hattori&ide

Dependencies:   mbed

Committer:
hattori_atsushi
Date:
Sun Dec 18 08:16:01 2022 +0000
Revision:
0:f77369cabd75
hattori

Who changed what in which revision?

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