Ipv4Address Class Reference#include <Ipv4Address.h>
Inheritance diagram for Ipv4Address:
![]()
Collaboration diagram for Ipv4Address:
![]()
Detailed DescriptionDefinition at line 45 of file Ipv4Address.h. Constructor & Destructor Documentation
Create empty Ipv4 address structure.
Definition at line 44 of file Ipv4Address.cpp. References m_addr. Referenced by GetCopy(). 00044 : m_valid(true) 00045 { 00046 memset(&m_addr, 0, sizeof(m_addr)); 00047 m_addr.sin_family = AF_INET; 00048 m_addr.sin_port = htons( port ); 00049 }
Create Ipv4 address structure.
Definition at line 52 of file Ipv4Address.cpp. References m_addr. 00052 : m_valid(true) 00053 { 00054 memset(&m_addr, 0, sizeof(m_addr)); 00055 m_addr.sin_family = AF_INET; 00056 m_addr.sin_port = htons( port ); 00057 memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr)); 00058 }
Create Ipv4 address structure.
Definition at line 61 of file Ipv4Address.cpp. References m_addr. 00061 : m_valid(true) 00062 { 00063 memset(&m_addr, 0, sizeof(m_addr)); 00064 m_addr.sin_family = AF_INET; 00065 m_addr.sin_port = htons( port ); 00066 m_addr.sin_addr = a; 00067 }
Create Ipv4 address structure.
Definition at line 70 of file Ipv4Address.cpp. References m_addr, m_valid, and Utility::u2ip(). 00070 : m_valid(false) 00071 { 00072 memset(&m_addr, 0, sizeof(m_addr)); 00073 m_addr.sin_family = AF_INET; 00074 m_addr.sin_port = htons( port ); 00075 { 00076 ipaddr_t a; 00077 if (Utility::u2ip(host, a)) 00078 { 00079 memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr)); 00080 m_valid = true; 00081 } 00082 } 00083 }
Member Function Documentation
Get a pointer to the address struct.
Implements SocketAddress. Definition at line 98 of file Ipv4Address.cpp. References m_addr. 00099 { 00100 return (struct sockaddr *)&m_addr; 00101 }
Get length of address struct.
Implements SocketAddress. Definition at line 104 of file Ipv4Address.cpp.
Compare two addresses.
Implements SocketAddress. Definition at line 188 of file Ipv4Address.cpp. References GetFamily(), SocketAddress::GetFamily(), and m_addr. 00189 { 00190 if (a.GetFamily() != GetFamily()) 00191 return false; 00192 if ((socklen_t)a != sizeof(m_addr)) 00193 return false; 00194 struct sockaddr *sa = a; 00195 struct sockaddr_in *p = (struct sockaddr_in *)sa; 00196 if (p -> sin_port != m_addr.sin_port) 00197 return false; 00198 if (memcmp(&p -> sin_addr, &m_addr.sin_addr, 4)) 00199 return false; 00200 return true; 00201 }
Set port number.
Implements SocketAddress. Definition at line 110 of file Ipv4Address.cpp. References m_addr. 00111 { 00112 m_addr.sin_port = htons( port ); 00113 }
Get port number.
Implements SocketAddress. Definition at line 116 of file Ipv4Address.cpp. References m_addr. Referenced by Convert(). 00117 { 00118 return ntohs( m_addr.sin_port ); 00119 }
Set socket address.
Implements SocketAddress. Definition at line 170 of file Ipv4Address.cpp. References m_addr. 00171 { 00172 memcpy(&m_addr, sa, sizeof(struct sockaddr_in)); 00173 }
Get address family.
Implements SocketAddress. Definition at line 176 of file Ipv4Address.cpp. References m_addr. Referenced by operator==(). 00177 { 00178 return m_addr.sin_family; 00179 }
Address structure is valid.
Implements SocketAddress. Definition at line 182 of file Ipv4Address.cpp. References m_valid. Referenced by UdpSocket::Bind(), ListenSocket< X >::Bind(), UdpSocket::Open(), and UdpSocket::SendToBuf(). 00183 { 00184 return m_valid; 00185 }
Get a copy of this SocketAddress object.
Implements SocketAddress. Definition at line 204 of file Ipv4Address.cpp. References Ipv4Address(), and m_addr. 00205 { 00206 return std::auto_ptr<SocketAddress>(new Ipv4Address(m_addr)); 00207 }
Convert address struct to text.
Implements SocketAddress. Definition at line 150 of file Ipv4Address.cpp. References GetPort(), Utility::l2string(), and m_addr. Referenced by Socket::GetSockAddress(). 00151 { 00152 if (include_port) 00153 return Convert(m_addr.sin_addr) + ":" + Utility::l2string(GetPort()); 00154 return Convert(m_addr.sin_addr); 00155 }
Reverse lookup of address.
Implements SocketAddress. Definition at line 210 of file Ipv4Address.cpp. References m_addr.
Resolve hostname.
Definition at line 122 of file Ipv4Address.cpp. References AI_NUMERICHOST, Utility::isipv4(), and Utility::u2ip(). 00123 { 00124 struct sockaddr_in sa; 00125 memset(&a, 0, sizeof(a)); 00126 if (Utility::isipv4(hostname)) 00127 { 00128 if (!Utility::u2ip(hostname, sa, AI_NUMERICHOST)) 00129 return false; 00130 a = sa.sin_addr; 00131 return true; 00132 } 00133 if (!Utility::u2ip(hostname, sa)) 00134 return false; 00135 a = sa.sin_addr; 00136 return true; 00137 }
Reverse resolve (IP to hostname).
Definition at line 140 of file Ipv4Address.cpp. References Utility::reverse(). 00141 { 00142 struct sockaddr_in sa; 00143 memset(&sa, 0, sizeof(sa)); 00144 sa.sin_family = AF_INET; 00145 sa.sin_addr = a; 00146 return Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name); 00147 }
Convert address struct to text.
Definition at line 158 of file Ipv4Address.cpp. References NI_NUMERICHOST, and Utility::reverse(). 00159 { 00160 struct sockaddr_in sa; 00161 memset(&sa, 0, sizeof(sa)); 00162 sa.sin_family = AF_INET; 00163 sa.sin_addr = a; 00164 std::string name; 00165 Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name, NI_NUMERICHOST); 00166 return name; 00167 }
Member Data Documentation
Definition at line 95 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: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1.4.4