NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ipaddr.h Source File

ipaddr.h

00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 
00024 #ifndef IPADDR_H
00025 #define IPADDR_H
00026 
00027 #include "netCfg.h"
00028 #if NET_LWIP_STACK
00029 typedef struct ip_addr ip_addr_t;
00030 #endif
00031 
00032 #include "stdint.h"
00033 
00034 ///IP Address container
00035 /**
00036 This class is a container for an IPv4 address.
00037 */
00038 class IpAddr //Basically a C++ frontend to ip_addr_t
00039 {
00040 public:
00041   #if NET_LWIP_STACK
00042   IpAddr(ip_addr_t* pIp);
00043   #endif
00044   
00045   ///Initializes IP address with provided values
00046   IpAddr(uint8_t ip0, uint8_t ip1, uint8_t ip2, uint8_t ip3);
00047   
00048   ///Initializes IP address with null values 
00049   IpAddr();
00050 
00051   #if NET_LWIP_STACK
00052   ip_addr_t getStruct() const;
00053   #endif
00054   
00055   ///Returns IP address byte #
00056   uint8_t operator[](unsigned int i) const;
00057   
00058   ///Compares too addresses
00059   /**
00060   @return true if the two addresses are equal
00061   */
00062   bool isEq(const IpAddr& b) const;
00063   
00064   ///Compares too addresses
00065   /**
00066   @return true if the two addresses are equal
00067   */
00068   bool operator==(const IpAddr& b) const;
00069  
00070   ///Compares too addresses
00071   /**
00072   @return true if the two addresses are different
00073   */ 
00074   bool operator!=(const IpAddr& b) const;
00075   
00076   ///Checks whether the address is null
00077   /**
00078   @return true if the address is null
00079   */
00080   bool isNull() const;
00081   
00082   ///Checks whether the address is a broadcast address
00083   /**
00084   @return true if the address is a broadcast address
00085   */
00086   bool isBroadcast() const;
00087 
00088   ///Checks whether the address is a multicast address
00089   /**
00090   @return true if the address is a multicast address
00091   */
00092   bool isMulticast() const;
00093   
00094 private:
00095   uint8_t m_ip[4];
00096 };
00097 
00098 #endif