Committer:
donatien
Date:
Fri Aug 06 10:42:05 2010 +0000
Revision:
3:e02ec42cf9c8

        

Who changed what in which revision?

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