Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/host_resolver.cc

Issue 275533002: Handle h_addr in a more libc independent way. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | native_client_sdk/src/tests/nacl_io_test/host_resolver_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Copy element zero of h_addr_list to h_addr as in some libc's h_addr may be
201 // a macro, but in others it may be a separate member.
202 hostent_.haddr = hostent_.h_addr_list[0];
Sam Clegg 2014/05/07 23:20:15 With the compiler not warn about self-assignment h
203
199 return &hostent_; 204 return &hostent_;
200 } 205 }
201 206
202 void HostResolver::freeaddrinfo(struct addrinfo *res) { 207 void HostResolver::freeaddrinfo(struct addrinfo *res) {
203 while (res) { 208 while (res) {
204 struct addrinfo* cur = res; 209 struct addrinfo* cur = res;
205 res = res->ai_next; 210 res = res->ai_next;
206 free(cur->ai_addr); 211 free(cur->ai_addr);
207 free(cur->ai_canonname); 212 free(cur->ai_canonname);
208 free(cur); 213 free(cur);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 414 }
410 if (NULL != hostent_.h_addr_list) { 415 if (NULL != hostent_.h_addr_list) {
411 for (int i = 0; NULL != hostent_.h_addr_list[i]; i++) { 416 for (int i = 0; NULL != hostent_.h_addr_list[i]; i++) {
412 free(hostent_.h_addr_list[i]); 417 free(hostent_.h_addr_list[i]);
413 } 418 }
414 free(hostent_.h_addr_list); 419 free(hostent_.h_addr_list);
415 } 420 }
416 hostent_.h_name = NULL; 421 hostent_.h_name = NULL;
417 hostent_.h_aliases = NULL; 422 hostent_.h_aliases = NULL;
418 hostent_.h_addr_list = NULL; 423 hostent_.h_addr_list = NULL;
424 hostent_.h_addr = NULL;
419 } 425 }
420 426
421 } // namespace nacl_io 427 } // namespace nacl_io
422 428
423 #endif // PROVIDES_SOCKET_API 429 #endif // PROVIDES_SOCKET_API
OLDNEW
« no previous file with comments | « no previous file | native_client_sdk/src/tests/nacl_io_test/host_resolver_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698