GainSpan Wi-Fi library see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
Dependents: GSwifi_httpd GSwifi_websocket GSwifi_tcpclient GSwifi_tcpserver ... more
Fork of GSwifi by
GainSpan Wi-Fi library
The GS1011 is an ultra low power 802.11b wireless module from GainSpan.
see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
ゲインスパン Wi-Fi モジュール ライブラリ
ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011 シリーズ用のライブラリです。
解説: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
ipaddr.cpp@7:b75b7fc144ff, 2012-08-21 (annotated)
- Committer:
- gsfan
- Date:
- Tue Aug 21 07:38:34 2012 +0000
- Revision:
- 7:b75b7fc144ff
- Parent:
- 0:2f6062c6d018
bugfix udp send
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsfan | 0:2f6062c6d018 | 1 | |
gsfan | 0:2f6062c6d018 | 2 | /* |
gsfan | 0:2f6062c6d018 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
gsfan | 0:2f6062c6d018 | 4 | |
gsfan | 0:2f6062c6d018 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
gsfan | 0:2f6062c6d018 | 6 | of this software and associated documentation files (the "Software"), to deal |
gsfan | 0:2f6062c6d018 | 7 | in the Software without restriction, including without limitation the rights |
gsfan | 0:2f6062c6d018 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
gsfan | 0:2f6062c6d018 | 9 | copies of the Software, and to permit persons to whom the Software is |
gsfan | 0:2f6062c6d018 | 10 | furnished to do so, subject to the following conditions: |
gsfan | 0:2f6062c6d018 | 11 | |
gsfan | 0:2f6062c6d018 | 12 | The above copyright notice and this permission notice shall be included in |
gsfan | 0:2f6062c6d018 | 13 | all copies or substantial portions of the Software. |
gsfan | 0:2f6062c6d018 | 14 | |
gsfan | 0:2f6062c6d018 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
gsfan | 0:2f6062c6d018 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
gsfan | 0:2f6062c6d018 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
gsfan | 0:2f6062c6d018 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
gsfan | 0:2f6062c6d018 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
gsfan | 0:2f6062c6d018 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
gsfan | 0:2f6062c6d018 | 21 | THE SOFTWARE. |
gsfan | 0:2f6062c6d018 | 22 | */ |
gsfan | 0:2f6062c6d018 | 23 | |
gsfan | 0:2f6062c6d018 | 24 | #include "ipaddr.h" |
gsfan | 0:2f6062c6d018 | 25 | |
gsfan | 0:2f6062c6d018 | 26 | //#include "netCfg.h" |
gsfan | 0:2f6062c6d018 | 27 | #if NET_LWIP_STACK |
gsfan | 0:2f6062c6d018 | 28 | #include "lwip/ip_addr.h" |
gsfan | 0:2f6062c6d018 | 29 | #endif |
gsfan | 0:2f6062c6d018 | 30 | |
gsfan | 0:2f6062c6d018 | 31 | |
gsfan | 0:2f6062c6d018 | 32 | #if NET_LWIP_STACK |
gsfan | 0:2f6062c6d018 | 33 | IpAddr::IpAddr(ip_addr_t* pIp) |
gsfan | 0:2f6062c6d018 | 34 | { |
gsfan | 0:2f6062c6d018 | 35 | *((uint32_t*)m_ip) = pIp->addr; |
gsfan | 0:2f6062c6d018 | 36 | } |
gsfan | 0:2f6062c6d018 | 37 | #endif |
gsfan | 0:2f6062c6d018 | 38 | |
gsfan | 0:2f6062c6d018 | 39 | ///Initializes IP address with provided values |
gsfan | 0:2f6062c6d018 | 40 | IpAddr::IpAddr(uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3) |
gsfan | 0:2f6062c6d018 | 41 | { |
gsfan | 0:2f6062c6d018 | 42 | //We are in LE |
gsfan | 0:2f6062c6d018 | 43 | m_ip[0] = ip0; |
gsfan | 0:2f6062c6d018 | 44 | m_ip[1] = ip1; |
gsfan | 0:2f6062c6d018 | 45 | m_ip[2] = ip2; |
gsfan | 0:2f6062c6d018 | 46 | m_ip[3] = ip3; |
gsfan | 0:2f6062c6d018 | 47 | } |
gsfan | 0:2f6062c6d018 | 48 | |
gsfan | 0:2f6062c6d018 | 49 | ///Initializes IP address with null values |
gsfan | 0:2f6062c6d018 | 50 | IpAddr::IpAddr() |
gsfan | 0:2f6062c6d018 | 51 | { |
gsfan | 0:2f6062c6d018 | 52 | m_ip[0] = 0; |
gsfan | 0:2f6062c6d018 | 53 | m_ip[1] = 0; |
gsfan | 0:2f6062c6d018 | 54 | m_ip[2] = 0; |
gsfan | 0:2f6062c6d018 | 55 | m_ip[3] = 0; |
gsfan | 0:2f6062c6d018 | 56 | } |
gsfan | 0:2f6062c6d018 | 57 | |
gsfan | 0:2f6062c6d018 | 58 | |
gsfan | 0:2f6062c6d018 | 59 | #if NET_LWIP_STACK |
gsfan | 0:2f6062c6d018 | 60 | ip_addr_t IpAddr::getStruct() const |
gsfan | 0:2f6062c6d018 | 61 | { |
gsfan | 0:2f6062c6d018 | 62 | ip_addr_t ip_struct; |
gsfan | 0:2f6062c6d018 | 63 | ip_struct.addr = *((uint32_t*)m_ip); |
gsfan | 0:2f6062c6d018 | 64 | return ip_struct; |
gsfan | 0:2f6062c6d018 | 65 | } |
gsfan | 0:2f6062c6d018 | 66 | #endif |
gsfan | 0:2f6062c6d018 | 67 | |
gsfan | 0:2f6062c6d018 | 68 | uint8_t IpAddr::operator[](unsigned int i) const |
gsfan | 0:2f6062c6d018 | 69 | { |
gsfan | 0:2f6062c6d018 | 70 | uint8_t null = 0; |
gsfan | 0:2f6062c6d018 | 71 | if( i > 3 ) |
gsfan | 0:2f6062c6d018 | 72 | return null; |
gsfan | 0:2f6062c6d018 | 73 | return m_ip[i]; |
gsfan | 0:2f6062c6d018 | 74 | } |
gsfan | 0:2f6062c6d018 | 75 | |
gsfan | 0:2f6062c6d018 | 76 | bool IpAddr::isEq(const IpAddr& b) const |
gsfan | 0:2f6062c6d018 | 77 | { |
gsfan | 0:2f6062c6d018 | 78 | return (*((uint32_t*)m_ip) == *((uint32_t*)(b.m_ip))); |
gsfan | 0:2f6062c6d018 | 79 | } |
gsfan | 0:2f6062c6d018 | 80 | |
gsfan | 0:2f6062c6d018 | 81 | bool IpAddr::operator==(const IpAddr& b) const |
gsfan | 0:2f6062c6d018 | 82 | { |
gsfan | 0:2f6062c6d018 | 83 | return isEq(b); |
gsfan | 0:2f6062c6d018 | 84 | } |
gsfan | 0:2f6062c6d018 | 85 | |
gsfan | 0:2f6062c6d018 | 86 | bool IpAddr::operator!=(const IpAddr& b) const |
gsfan | 0:2f6062c6d018 | 87 | { |
gsfan | 0:2f6062c6d018 | 88 | return !(operator==(b)); |
gsfan | 0:2f6062c6d018 | 89 | } |
gsfan | 0:2f6062c6d018 | 90 | |
gsfan | 0:2f6062c6d018 | 91 | bool IpAddr::isNull() const |
gsfan | 0:2f6062c6d018 | 92 | { |
gsfan | 0:2f6062c6d018 | 93 | return (*((uint32_t*)m_ip) == 0); |
gsfan | 0:2f6062c6d018 | 94 | } |
gsfan | 0:2f6062c6d018 | 95 | |
gsfan | 0:2f6062c6d018 | 96 | bool IpAddr::isBroadcast() const |
gsfan | 0:2f6062c6d018 | 97 | { |
gsfan | 0:2f6062c6d018 | 98 | return (*((uint32_t*)m_ip) == 0xFFFFFFFF); |
gsfan | 0:2f6062c6d018 | 99 | } |
gsfan | 0:2f6062c6d018 | 100 | |
gsfan | 0:2f6062c6d018 | 101 | bool IpAddr::isMulticast() const |
gsfan | 0:2f6062c6d018 | 102 | { |
gsfan | 0:2f6062c6d018 | 103 | return ((m_ip[0] & 0xF0) == 0xE0); |
gsfan | 0:2f6062c6d018 | 104 | } |