Committer:
zoot661
Date:
Tue May 29 09:49:18 2012 +0000
Revision:
0:f993b6d8b1d8

        

Who changed what in which revision?

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