![]() |
Ipv4Address Class Reference#include <Ipv4Address.h>
Inheritance diagram for Ipv4Address: ![]() ![]()
Detailed Description
Definition at line 37 of file Ipv4Address.h. Constructor & Destructor Documentation
Create empty Ipv4 address structure.
Definition at line 37 of file Ipv4Address.cpp. References m_addr. Referenced by GetCopy(). 00037 : m_valid(true) 00038 { 00039 memset(&m_addr, 0, sizeof(m_addr)); 00040 m_addr.sin_family = AF_INET; 00041 m_addr.sin_port = htons( port ); 00042 }
Create Ipv4 address structure.
Definition at line 45 of file Ipv4Address.cpp. References m_addr. 00045 : m_valid(true) 00046 { 00047 memset(&m_addr, 0, sizeof(m_addr)); 00048 m_addr.sin_family = AF_INET; 00049 m_addr.sin_port = htons( port ); 00050 memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr)); 00051 }
Create Ipv4 address structure.
Definition at line 54 of file Ipv4Address.cpp. References m_addr. 00054 : m_valid(true) 00055 { 00056 memset(&m_addr, 0, sizeof(m_addr)); 00057 m_addr.sin_family = AF_INET; 00058 m_addr.sin_port = htons( port ); 00059 m_addr.sin_addr = a; 00060 }
Create Ipv4 address structure.
Definition at line 63 of file Ipv4Address.cpp. References m_addr, m_valid, and Utility::u2ip(). 00063 : m_valid(false) 00064 { 00065 memset(&m_addr, 0, sizeof(m_addr)); 00066 m_addr.sin_family = AF_INET; 00067 m_addr.sin_port = htons( port ); 00068 { 00069 ipaddr_t a; 00070 if (Utility::u2ip(host, a)) 00071 { 00072 memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr)); 00073 m_valid = true; 00074 } 00075 } 00076 }
Member Function Documentation
Get a pointer to the address struct.
Implements SocketAddress. Definition at line 91 of file Ipv4Address.cpp. References m_addr. 00092 { 00093 return (struct sockaddr *)&m_addr; 00094 }
Get length of address struct.
Implements SocketAddress. Definition at line 97 of file Ipv4Address.cpp.
Compare two addresses.
Implements SocketAddress. Definition at line 181 of file Ipv4Address.cpp. References GetFamily(), SocketAddress::GetFamily(), and m_addr. 00182 { 00183 if (a.GetFamily() != GetFamily()) 00184 return false; 00185 if ((socklen_t)a != sizeof(m_addr)) 00186 return false; 00187 struct sockaddr *sa = a; 00188 struct sockaddr_in *p = (struct sockaddr_in *)sa; 00189 if (p -> sin_port != m_addr.sin_port) 00190 return false; 00191 if (memcmp(&p -> sin_addr, &m_addr.sin_addr, 4)) 00192 return false; 00193 return true; 00194 }
Set port number.
Implements SocketAddress. Definition at line 103 of file Ipv4Address.cpp. References m_addr. 00104 { 00105 m_addr.sin_port = htons( port ); 00106 }
Get port number.
Implements SocketAddress. Definition at line 109 of file Ipv4Address.cpp. References m_addr. Referenced by Convert(). 00110 { 00111 return ntohs( m_addr.sin_port ); 00112 }
Set socket address.
Implements SocketAddress. Definition at line 163 of file Ipv4Address.cpp. References m_addr. 00164 { 00165 memcpy(&m_addr, sa, sizeof(struct sockaddr_in)); 00166 }
Get address family.
Implements SocketAddress. Definition at line 169 of file Ipv4Address.cpp. References m_addr. Referenced by operator==(). 00170 { 00171 return m_addr.sin_family; 00172 }
Address structure is valid.
Implements SocketAddress. Definition at line 175 of file Ipv4Address.cpp. References m_valid. Referenced by UdpSocket::Bind(), ListenSocket< X >::Bind(), UdpSocket::Open(), and UdpSocket::SendToBuf(). 00176 { 00177 return m_valid; 00178 }
Get a copy of this SocketAddress object.
Implements SocketAddress. Definition at line 197 of file Ipv4Address.cpp. References Ipv4Address(), and m_addr. 00198 { 00199 return std::auto_ptr<SocketAddress>(new Ipv4Address(m_addr)); 00200 }
Convert address struct to text.
Implements SocketAddress. Definition at line 143 of file Ipv4Address.cpp. References GetPort(), Utility::l2string(), and m_addr. 00144 { 00145 if (include_port) 00146 return Convert(m_addr.sin_addr) + ":" + Utility::l2string(GetPort()); 00147 return Convert(m_addr.sin_addr); 00148 }
Reverse lookup of address.
Implements SocketAddress. Definition at line 203 of file Ipv4Address.cpp. References m_addr.
Resolve hostname.
Definition at line 115 of file Ipv4Address.cpp. References Utility::isipv4(), and Utility::u2ip(). 00116 { 00117 struct sockaddr_in sa; 00118 memset(&a, 0, sizeof(a)); 00119 if (Utility::isipv4(hostname)) 00120 { 00121 if (!Utility::u2ip(hostname, sa, AI_NUMERICHOST)) 00122 return false; 00123 a = sa.sin_addr; 00124 return true; 00125 } 00126 if (!Utility::u2ip(hostname, sa)) 00127 return false; 00128 a = sa.sin_addr; 00129 return true; 00130 }
Reverse resolve (IP to hostname).
Definition at line 133 of file Ipv4Address.cpp. References Utility::reverse(). 00134 { 00135 struct sockaddr_in sa; 00136 memset(&sa, 0, sizeof(sa)); 00137 sa.sin_family = AF_INET; 00138 sa.sin_addr = a; 00139 return Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name); 00140 }
Convert address struct to text.
Definition at line 151 of file Ipv4Address.cpp. References Utility::reverse(). 00152 { 00153 struct sockaddr_in sa; 00154 memset(&sa, 0, sizeof(sa)); 00155 sa.sin_family = AF_INET; 00156 sa.sin_addr = a; 00157 std::string name; 00158 Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name, NI_NUMERICHOST); 00159 return name; 00160 }
Member Data Documentation
Definition at line 87 of file Ipv4Address.h. Referenced by Convert(), GetCopy(), GetFamily(), GetPort(), Ipv4Address(), operator struct sockaddr *(), operator==(), Reverse(), SetAddress(), and SetPort().
The documentation for this class was generated from the following files: |