OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "nacl_io/host_resolver.h" | 5 #include "nacl_io/host_resolver.h" |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 sockaddr_in6* in6 = reinterpret_cast<sockaddr_in6*>(current->ai_addr); | 189 sockaddr_in6* in6 = reinterpret_cast<sockaddr_in6*>(current->ai_addr); |
190 memcpy(*hostent_addr, &in6->sin6_addr.s6_addr, hostent_.h_length); | 190 memcpy(*hostent_addr, &in6->sin6_addr.s6_addr, hostent_.h_length); |
191 break; | 191 break; |
192 } | 192 } |
193 } | 193 } |
194 current = current->ai_next; | 194 current = current->ai_next; |
195 hostent_addr++; | 195 hostent_addr++; |
196 } | 196 } |
197 | 197 |
198 freeaddrinfo(ai); | 198 freeaddrinfo(ai); |
| 199 |
| 200 #if !defined(h_addr) |
| 201 // Copy element zero of h_addr_list to h_addr when h_addr is not defined |
| 202 // as in some libc's h_addr may be a separate member instead of a macro. |
| 203 hostent_.h_addr = hostent_.h_addr_list[0]; |
| 204 #endif |
| 205 |
199 return &hostent_; | 206 return &hostent_; |
200 } | 207 } |
201 | 208 |
202 void HostResolver::freeaddrinfo(struct addrinfo *res) { | 209 void HostResolver::freeaddrinfo(struct addrinfo *res) { |
203 while (res) { | 210 while (res) { |
204 struct addrinfo* cur = res; | 211 struct addrinfo* cur = res; |
205 res = res->ai_next; | 212 res = res->ai_next; |
206 free(cur->ai_addr); | 213 free(cur->ai_addr); |
207 free(cur->ai_canonname); | 214 free(cur->ai_canonname); |
208 free(cur); | 215 free(cur); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 } | 416 } |
410 if (NULL != hostent_.h_addr_list) { | 417 if (NULL != hostent_.h_addr_list) { |
411 for (int i = 0; NULL != hostent_.h_addr_list[i]; i++) { | 418 for (int i = 0; NULL != hostent_.h_addr_list[i]; i++) { |
412 free(hostent_.h_addr_list[i]); | 419 free(hostent_.h_addr_list[i]); |
413 } | 420 } |
414 free(hostent_.h_addr_list); | 421 free(hostent_.h_addr_list); |
415 } | 422 } |
416 hostent_.h_name = NULL; | 423 hostent_.h_name = NULL; |
417 hostent_.h_aliases = NULL; | 424 hostent_.h_aliases = NULL; |
418 hostent_.h_addr_list = NULL; | 425 hostent_.h_addr_list = NULL; |
| 426 #if !defined(h_addr) |
| 427 // Initialize h_addr separately in the case where it is not a macro. |
| 428 hostent_.h_addr = NULL; |
| 429 #endif |
419 } | 430 } |
420 | 431 |
421 } // namespace nacl_io | 432 } // namespace nacl_io |
422 | 433 |
423 #endif // PROVIDES_SOCKET_API | 434 #endif // PROVIDES_SOCKET_API |
OLD | NEW |