Async  0.18.0
AsyncIpAddress.h
Go to the documentation of this file.
00001 
00030 #ifndef ASYNC_IP_ADDRESS_INCLUDED
00031 #define ASYNC_IP_ADDRESS_INCLUDED
00032 
00033 
00034 /****************************************************************************
00035  *
00036  * System Includes
00037  *
00038  ****************************************************************************/
00039 
00040 #include <netinet/in.h>
00041 
00042 #include <string>
00043 #include <iostream>
00044 
00045 
00046 /****************************************************************************
00047  *
00048  * Project Includes
00049  *
00050  ****************************************************************************/
00051 
00052 
00053 
00054 /****************************************************************************
00055  *
00056  * Local Includes
00057  *
00058  ****************************************************************************/
00059 
00060 
00061 
00062 /****************************************************************************
00063  *
00064  * Forward declarations
00065  *
00066  ****************************************************************************/
00067 
00068 
00069 
00070 /****************************************************************************
00071  *
00072  * Namespace
00073  *
00074  ****************************************************************************/
00075 
00076 namespace Async
00077 {
00078 
00079 /****************************************************************************
00080  *
00081  * Defines & typedefs
00082  *
00083  ****************************************************************************/
00084 
00085 
00086 
00087 /****************************************************************************
00088  *
00089  * Exported Global Variables
00090  *
00091  ****************************************************************************/
00092 
00093 
00094 
00095 /****************************************************************************
00096  *
00097  * Class definitions
00098  *
00099  ****************************************************************************/
00100 
00104 class IpAddress
00105 {
00106   public:
00110     typedef struct in_addr Ip4Addr;
00111     
00115     IpAddress(void);
00116     
00121     IpAddress(const std::string& addr);
00122      
00127     IpAddress(const Ip4Addr& addr);
00128     
00133     IpAddress(const IpAddress& addr) { *this = addr; }
00134     
00138     ~IpAddress(void) {}
00139     
00144     Ip4Addr ip4Addr(void) const { return m_addr; }
00145     
00151     bool isUnicast(void) const;
00152     
00160     bool isWithinSubet(const std::string& subnet) const;
00161 
00167     bool isEmpty(void) const { return (m_addr.s_addr == INADDR_NONE); }
00168 
00172     void clear(void) { m_addr.s_addr = INADDR_NONE; }
00173     
00178     std::string toString(void) const;
00179     
00185     IpAddress& operator=(const IpAddress& rhs)
00186     {
00187       m_addr = rhs.m_addr;
00188       return *this;
00189     }
00190     
00197     bool operator==(const IpAddress& rhs) const
00198     {
00199       return m_addr.s_addr == rhs.m_addr.s_addr;
00200     }
00201     
00208     bool operator!=(const IpAddress& rhs) const
00209     {
00210       return !(*this == rhs);
00211     }
00212     
00219     bool operator<(const IpAddress& rhs) const
00220     {
00221       return m_addr.s_addr < rhs.m_addr.s_addr;
00222     }
00223     
00229     friend std::ostream& operator<<(std::ostream& os,
00230         const Async::IpAddress& ip);
00231     
00232   protected:
00233     
00234   private:
00235     Ip4Addr m_addr;
00236   
00237 };  /* class IpAddress */
00238 
00239 
00240 std::ostream& operator<<(std::ostream& os, const IpAddress& ip);
00241 
00242 
00243 } /* namespace */
00244 
00245 
00246 #endif /* ASYNC_IP_ADDRESS_INCLUDED */
00247 
00248 
00249 
00250 /*
00251  * This file has not been truncated
00252  */
00253