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