sources/network/ipaddress.cpp

changeset 19
2046a1651c0b
parent 10
3874575d924d
child 24
e651d02802c0
equal deleted inserted replaced
18:56a1ac7d931b 19:2046a1651c0b
171 // ----------------------------------------------------------------------------- 171 // -----------------------------------------------------------------------------
172 // 172 //
173 STATIC METHOD 173 STATIC METHOD
174 IPAddress::resolve (String node, bool* ok) -> IPAddress 174 IPAddress::resolve (String node, bool* ok) -> IPAddress
175 { 175 {
176 struct addrinfo hints; 176 addrinfo hints;
177 struct addrinfo* lookup; 177 addrinfo* lookup;
178 memset (&hints, 0, sizeof hints); 178 memset (&hints, 0, sizeof hints);
179 hints.ai_family = AF_INET; 179 hints.ai_family = AF_INET;
180 180
181 if (getaddrinfo (node, nullptr, &hints, &lookup) != 0) 181 if (getaddrinfo (node, nullptr, &hints, &lookup) != 0)
182 { 182 {
184 return IPAddress(); 184 return IPAddress();
185 } 185 }
186 186
187 IPAddress result; 187 IPAddress result;
188 assert (lookup != nullptr); 188 assert (lookup != nullptr);
189 sockaddr_in* addr = reinterpret_cast<struct sockaddr_in*> (lookup[0].ai_addr); 189 sockaddr_in* addr = reinterpret_cast<sockaddr_in*> (lookup[0].ai_addr);
190 result.host = ntohl (addr->sin_addr.s_addr); 190 result.host = ntohl (addr->sin_addr.s_addr);
191 result.port = ntohs (addr->sin_port); 191 result.port = ntohs (addr->sin_port);
192 freeaddrinfo (lookup); 192 freeaddrinfo (lookup);
193 return result; 193 return result;
194 } 194 }

mercurial