sources/network/ipaddress.cpp

changeset 10
3874575d924d
parent 9
e7a09ceb4505
child 19
2046a1651c0b
equal deleted inserted replaced
9:e7a09ceb4505 10:3874575d924d
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 struct addrinfo hints;
177 struct addrinfo* lookup; 177 struct addrinfo* lookup;
178 int errorcode;
179 memset (&hints, 0, sizeof hints); 178 memset (&hints, 0, sizeof hints);
180 hints.ai_family = AF_INET; 179 hints.ai_family = AF_INET;
181 180
182 if ((errorcode = getaddrinfo (node, nullptr, &hints, &lookup)) != 0) 181 if (getaddrinfo (node, nullptr, &hints, &lookup) != 0)
183 { 182 {
184 *ok = false; 183 *ok = false;
185 return IPAddress(); 184 return IPAddress();
186 } 185 }
187 186
189 assert (lookup != nullptr); 188 assert (lookup != nullptr);
190 sockaddr_in* addr = reinterpret_cast<struct sockaddr_in*> (lookup[0].ai_addr); 189 sockaddr_in* addr = reinterpret_cast<struct sockaddr_in*> (lookup[0].ai_addr);
191 result.host = ntohl (addr->sin_addr.s_addr); 190 result.host = ntohl (addr->sin_addr.s_addr);
192 result.port = ntohs (addr->sin_port); 191 result.port = ntohs (addr->sin_port);
193 freeaddrinfo (lookup); 192 freeaddrinfo (lookup);
194 *ok = true;
195 return result; 193 return result;
196 } 194 }

mercurial