Dependents: RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more
LPC2368/core/ipaddr.h@0:479ce5546098, 2011-12-31 (annotated)
- Committer:
- sherckuith
- Date:
- Sat Dec 31 11:25:27 2011 +0000
- Revision:
- 0:479ce5546098
Ethernet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sherckuith | 0:479ce5546098 | 1 | |
sherckuith | 0:479ce5546098 | 2 | /* |
sherckuith | 0:479ce5546098 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
sherckuith | 0:479ce5546098 | 4 | |
sherckuith | 0:479ce5546098 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
sherckuith | 0:479ce5546098 | 6 | of this software and associated documentation files (the "Software"), to deal |
sherckuith | 0:479ce5546098 | 7 | in the Software without restriction, including without limitation the rights |
sherckuith | 0:479ce5546098 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
sherckuith | 0:479ce5546098 | 9 | copies of the Software, and to permit persons to whom the Software is |
sherckuith | 0:479ce5546098 | 10 | furnished to do so, subject to the following conditions: |
sherckuith | 0:479ce5546098 | 11 | |
sherckuith | 0:479ce5546098 | 12 | The above copyright notice and this permission notice shall be included in |
sherckuith | 0:479ce5546098 | 13 | all copies or substantial portions of the Software. |
sherckuith | 0:479ce5546098 | 14 | |
sherckuith | 0:479ce5546098 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
sherckuith | 0:479ce5546098 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
sherckuith | 0:479ce5546098 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
sherckuith | 0:479ce5546098 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
sherckuith | 0:479ce5546098 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
sherckuith | 0:479ce5546098 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
sherckuith | 0:479ce5546098 | 21 | THE SOFTWARE. |
sherckuith | 0:479ce5546098 | 22 | */ |
sherckuith | 0:479ce5546098 | 23 | |
sherckuith | 0:479ce5546098 | 24 | #ifndef IPADDR_H |
sherckuith | 0:479ce5546098 | 25 | #define IPADDR_H |
sherckuith | 0:479ce5546098 | 26 | |
sherckuith | 0:479ce5546098 | 27 | #include "netCfg.h" |
sherckuith | 0:479ce5546098 | 28 | #if NET_LWIP_STACK |
sherckuith | 0:479ce5546098 | 29 | typedef struct ip_addr ip_addr_t; |
sherckuith | 0:479ce5546098 | 30 | #endif |
sherckuith | 0:479ce5546098 | 31 | |
sherckuith | 0:479ce5546098 | 32 | #include "stdint.h" |
sherckuith | 0:479ce5546098 | 33 | |
sherckuith | 0:479ce5546098 | 34 | ///IP Address container |
sherckuith | 0:479ce5546098 | 35 | /** |
sherckuith | 0:479ce5546098 | 36 | This class is a container for an IPv4 address. |
sherckuith | 0:479ce5546098 | 37 | */ |
sherckuith | 0:479ce5546098 | 38 | class IpAddr //Basically a C++ frontend to ip_addr_t |
sherckuith | 0:479ce5546098 | 39 | { |
sherckuith | 0:479ce5546098 | 40 | public: |
sherckuith | 0:479ce5546098 | 41 | #if NET_LWIP_STACK |
sherckuith | 0:479ce5546098 | 42 | IpAddr(ip_addr_t* pIp); |
sherckuith | 0:479ce5546098 | 43 | #endif |
sherckuith | 0:479ce5546098 | 44 | |
sherckuith | 0:479ce5546098 | 45 | ///Initializes IP address with provided values |
sherckuith | 0:479ce5546098 | 46 | IpAddr(uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3); |
sherckuith | 0:479ce5546098 | 47 | |
sherckuith | 0:479ce5546098 | 48 | ///Initializes IP address with null values |
sherckuith | 0:479ce5546098 | 49 | IpAddr(); |
sherckuith | 0:479ce5546098 | 50 | |
sherckuith | 0:479ce5546098 | 51 | #if NET_LWIP_STACK |
sherckuith | 0:479ce5546098 | 52 | ip_addr_t getStruct() const; |
sherckuith | 0:479ce5546098 | 53 | #endif |
sherckuith | 0:479ce5546098 | 54 | |
sherckuith | 0:479ce5546098 | 55 | ///Returns IP address byte # |
sherckuith | 0:479ce5546098 | 56 | uint8_t operator[](unsigned int i) const; |
sherckuith | 0:479ce5546098 | 57 | |
sherckuith | 0:479ce5546098 | 58 | ///Compares too addresses |
sherckuith | 0:479ce5546098 | 59 | /** |
sherckuith | 0:479ce5546098 | 60 | @return true if the two addresses are equal |
sherckuith | 0:479ce5546098 | 61 | */ |
sherckuith | 0:479ce5546098 | 62 | bool isEq(const IpAddr& b) const; |
sherckuith | 0:479ce5546098 | 63 | |
sherckuith | 0:479ce5546098 | 64 | ///Compares too addresses |
sherckuith | 0:479ce5546098 | 65 | /** |
sherckuith | 0:479ce5546098 | 66 | @return true if the two addresses are equal |
sherckuith | 0:479ce5546098 | 67 | */ |
sherckuith | 0:479ce5546098 | 68 | bool operator==(const IpAddr& b) const; |
sherckuith | 0:479ce5546098 | 69 | |
sherckuith | 0:479ce5546098 | 70 | ///Compares too addresses |
sherckuith | 0:479ce5546098 | 71 | /** |
sherckuith | 0:479ce5546098 | 72 | @return true if the two addresses are different |
sherckuith | 0:479ce5546098 | 73 | */ |
sherckuith | 0:479ce5546098 | 74 | bool operator!=(const IpAddr& b) const; |
sherckuith | 0:479ce5546098 | 75 | |
sherckuith | 0:479ce5546098 | 76 | ///Checks whether the address is null |
sherckuith | 0:479ce5546098 | 77 | /** |
sherckuith | 0:479ce5546098 | 78 | @return true if the address is null |
sherckuith | 0:479ce5546098 | 79 | */ |
sherckuith | 0:479ce5546098 | 80 | bool isNull() const; |
sherckuith | 0:479ce5546098 | 81 | |
sherckuith | 0:479ce5546098 | 82 | ///Checks whether the address is a broadcast address |
sherckuith | 0:479ce5546098 | 83 | /** |
sherckuith | 0:479ce5546098 | 84 | @return true if the address is a broadcast address |
sherckuith | 0:479ce5546098 | 85 | */ |
sherckuith | 0:479ce5546098 | 86 | bool isBroadcast() const; |
sherckuith | 0:479ce5546098 | 87 | |
sherckuith | 0:479ce5546098 | 88 | ///Checks whether the address is a multicast address |
sherckuith | 0:479ce5546098 | 89 | /** |
sherckuith | 0:479ce5546098 | 90 | @return true if the address is a multicast address |
sherckuith | 0:479ce5546098 | 91 | */ |
sherckuith | 0:479ce5546098 | 92 | bool isMulticast() const; |
sherckuith | 0:479ce5546098 | 93 | |
sherckuith | 0:479ce5546098 | 94 | private: |
sherckuith | 0:479ce5546098 | 95 | uint8_t m_ip[4]; |
sherckuith | 0:479ce5546098 | 96 | }; |
sherckuith | 0:479ce5546098 | 97 | |
sherckuith | 0:479ce5546098 | 98 | #endif |