![]() |
Ipv4Address Class Reference#include <Ipv4Address.h>
Inheritance diagram for Ipv4Address:
![]()
Collaboration diagram for Ipv4Address:
![]()
Detailed DescriptionDefinition at line 47 of file Ipv4Address.h. Constructor & Destructor Documentation
Create empty Ipv4 address structure.
Definition at line 46 of file Ipv4Address.cpp. References m_addr. Referenced by GetCopy(). 00046 : m_valid(true) 00047 { 00048 memset(&m_addr, 0, sizeof(m_addr)); 00049 m_addr.sin_family = AF_INET; 00050 m_addr.sin_port = htons( port ); 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 memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr)); 00060 }
Create Ipv4 address structure.
Definition at line 63 of file Ipv4Address.cpp. References m_addr. 00063 : m_valid(true) 00064 { 00065 memset(&m_addr, 0, sizeof(m_addr)); 00066 m_addr.sin_family = AF_INET; 00067 m_addr.sin_port = htons( port ); 00068 m_addr.sin_addr = a; 00069 }
Create Ipv4 address structure.
Definition at line 72 of file Ipv4Address.cpp. References m_addr, m_valid, and Utility::u2ip(). 00072 : m_valid(false) 00073 { 00074 memset(&m_addr, 0, sizeof(m_addr)); 00075 m_addr.sin_family = AF_INET; 00076 m_addr.sin_port = htons( port ); 00077 { 00078 ipaddr_t a; 00079 if (Utility::u2ip(host, a)) 00080 { 00081 memcpy(&m_addr.sin_addr, &a, sizeof(struct in_addr)); 00082 m_valid = true; 00083 } 00084 } 00085 }
Member Function Documentation
Get a pointer to the address struct.
Implements SocketAddress. Definition at line 100 of file Ipv4Address.cpp. References m_addr. 00101 { 00102 return (struct sockaddr *)&m_addr; 00103 }
Get length of address struct.
Implements SocketAddress. Definition at line 106 of file Ipv4Address.cpp.
Compare two addresses.
Implements SocketAddress. Definition at line 190 of file Ipv4Address.cpp. References GetFamily(), SocketAddress::GetFamily(), and m_addr. 00191 { 00192 if (a.GetFamily() != GetFamily()) 00193 return false; 00194 if ((socklen_t)a != sizeof(m_addr)) 00195 return false; 00196 struct sockaddr *sa = a; 00197 struct sockaddr_in *p = (struct sockaddr_in *)sa; 00198 if (p -> sin_port != m_addr.sin_port) 00199 return false; 00200 if (memcmp(&p -> sin_addr, &m_addr.sin_addr, 4)) 00201 return false; 00202 return true; 00203 }
Set port number.
Implements SocketAddress. Definition at line 112 of file Ipv4Address.cpp. References m_addr. 00113 { 00114 m_addr.sin_port = htons( port ); 00115 }
Get port number.
Implements SocketAddress. Definition at line 118 of file Ipv4Address.cpp. References m_addr. Referenced by Convert(). 00119 { 00120 return ntohs( m_addr.sin_port ); 00121 }
Set socket address.
Implements SocketAddress. Definition at line 172 of file Ipv4Address.cpp. References m_addr. 00173 { 00174 memcpy(&m_addr, sa, sizeof(struct sockaddr_in)); 00175 }
Get address family.
Implements SocketAddress. Definition at line 178 of file Ipv4Address.cpp. References m_addr. Referenced by operator==(). 00179 { 00180 return m_addr.sin_family; 00181 }
Address structure is valid.
Implements SocketAddress. Definition at line 184 of file Ipv4Address.cpp. References m_valid. Referenced by UdpSocket::Bind(), ListenSocket< X >::Bind(), UdpSocket::Open(), and UdpSocket::SendToBuf(). 00185 { 00186 return m_valid; 00187 }
Get a copy of this SocketAddress object.
Implements SocketAddress. Definition at line 206 of file Ipv4Address.cpp. References Ipv4Address(), and m_addr. 00207 { 00208 return std::auto_ptr<SocketAddress>(new Ipv4Address(m_addr)); 00209 }
Convert address struct to text.
Implements SocketAddress. Definition at line 152 of file Ipv4Address.cpp. References GetPort(), Utility::l2string(), and m_addr. Referenced by Socket::GetSockAddress(). 00153 { 00154 if (include_port) 00155 return Convert(m_addr.sin_addr) + ":" + Utility::l2string(GetPort()); 00156 return Convert(m_addr.sin_addr); 00157 }
Reverse lookup of address.
Implements SocketAddress. Definition at line 212 of file Ipv4Address.cpp. References m_addr.
Resolve hostname.
Definition at line 124 of file Ipv4Address.cpp. References AI_NUMERICHOST, Utility::isipv4(), and Utility::u2ip(). 00125 { 00126 struct sockaddr_in sa; 00127 memset(&a, 0, sizeof(a)); 00128 if (Utility::isipv4(hostname)) 00129 { 00130 if (!Utility::u2ip(hostname, sa, AI_NUMERICHOST)) 00131 return false; 00132 a = sa.sin_addr; 00133 return true; 00134 } 00135 if (!Utility::u2ip(hostname, sa)) 00136 return false; 00137 a = sa.sin_addr; 00138 return true; 00139 }
Reverse resolve (IP to hostname).
Definition at line 142 of file Ipv4Address.cpp. References Utility::reverse(). 00143 { 00144 struct sockaddr_in sa; 00145 memset(&sa, 0, sizeof(sa)); 00146 sa.sin_family = AF_INET; 00147 sa.sin_addr = a; 00148 return Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name); 00149 }
Convert address struct to text.
Definition at line 160 of file Ipv4Address.cpp. References NI_NUMERICHOST, and Utility::reverse(). 00161 { 00162 struct sockaddr_in sa; 00163 memset(&sa, 0, sizeof(sa)); 00164 sa.sin_family = AF_INET; 00165 sa.sin_addr = a; 00166 std::string name; 00167 Utility::reverse((struct sockaddr *)&sa, sizeof(sa), name, NI_NUMERICHOST); 00168 return name; 00169 }
Member Data Documentation
Definition at line 97 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: |