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 #define __STDC_LIMIT_MACROS | |
6 | |
5 #include "nacl_io/host_resolver.h" | 7 #include "nacl_io/host_resolver.h" |
6 | 8 |
7 #include <assert.h> | 9 #include <assert.h> |
10 #include <stdint.h> | |
8 #include <stdlib.h> | 11 #include <stdlib.h> |
9 #include <string.h> | 12 #include <string.h> |
10 | 13 |
11 #include "nacl_io/kernel_proxy.h" | 14 #include "nacl_io/kernel_proxy.h" |
12 #include "nacl_io/ossocket.h" | 15 #include "nacl_io/ossocket.h" |
13 #include "nacl_io/pepper_interface.h" | 16 #include "nacl_io/pepper_interface.h" |
14 | 17 |
15 #ifdef PROVIDES_SOCKET_API | 18 #ifdef PROVIDES_SOCKET_API |
16 | 19 |
17 namespace { | 20 namespace { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 | 227 |
225 if (node == NULL && service == NULL) | 228 if (node == NULL && service == NULL) |
226 return EAI_NONAME; | 229 return EAI_NONAME; |
227 | 230 |
228 // Check the service name (port). Currently we only handle numeric | 231 // Check the service name (port). Currently we only handle numeric |
229 // services. | 232 // services. |
230 long port = 0; | 233 long port = 0; |
231 if (service != NULL) { | 234 if (service != NULL) { |
232 char* cp; | 235 char* cp; |
233 port = strtol(service, &cp, 10); | 236 port = strtol(service, &cp, 10); |
234 if (port > 0 && port <= 65535 && *cp == '\0') { | 237 if (port >= 0 && port <= UINT16_MAX && *cp == '\0') { |
235 port = htons(port); | 238 port = htons(port); |
236 } else { | 239 } else { |
237 return EAI_SERVICE; | 240 return EAI_SERVICE; |
238 } | 241 } |
239 } | 242 } |
240 | 243 |
241 struct addrinfo default_hints; | 244 struct addrinfo default_hints; |
242 memset(&default_hints, 0, sizeof(default_hints)); | 245 memset(&default_hints, 0, sizeof(default_hints)); |
243 const struct addrinfo* hints = hints_in ? hints_in : &default_hints; | 246 const struct addrinfo* hints = hints_in ? hints_in : &default_hints; |
244 | 247 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 // string so this condition is never true. | 345 // string so this condition is never true. |
343 // TODO(sbc): investigate this issue with PPAPI team. | 346 // TODO(sbc): investigate this issue with PPAPI team. |
344 if (len > 0) { | 347 if (len > 0) { |
345 // Copy and NULL-terminate the UTF8 string var. | 348 // Copy and NULL-terminate the UTF8 string var. |
346 canon_name = static_cast<char*>(malloc(len + 1)); | 349 canon_name = static_cast<char*>(malloc(len + 1)); |
347 strncpy(canon_name, tmp, len); | 350 strncpy(canon_name, tmp, len); |
348 canon_name[len] = '\0'; | 351 canon_name[len] = '\0'; |
349 } | 352 } |
350 } | 353 } |
351 if (!canon_name) | 354 if (!canon_name) |
352 canon_name = strdup(node); | 355 canon_name = strdup(node); |
bradn
2014/06/19 19:38:38
While you're in here. When I was trying to figure
Sam Clegg
2014/06/19 19:59:56
If AI_CANONNAME is off then I think canon_name is
| |
353 var_interface->Release(name_var); | 356 var_interface->Release(name_var); |
354 } | 357 } |
355 | 358 |
356 int num_addresses = resolver_iface->GetNetAddressCount(resolver); | 359 int num_addresses = resolver_iface->GetNetAddressCount(resolver); |
357 if (0 == num_addresses) | 360 if (0 == num_addresses) |
358 return EAI_NODATA; | 361 return EAI_NODATA; |
359 | 362 |
360 // Convert address to sockaddr struct. | 363 // Convert address to sockaddr struct. |
361 for (int i = 0; i < num_addresses; i++) { | 364 for (int i = 0; i < num_addresses; i++) { |
362 ScopedResource addr(ppapi_, resolver_iface->GetNetAddress(resolver, i)); | 365 ScopedResource addr(ppapi_, resolver_iface->GetNetAddress(resolver, i)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 hostent_.h_addr_list = NULL; | 427 hostent_.h_addr_list = NULL; |
425 #if !defined(h_addr) | 428 #if !defined(h_addr) |
426 // Initialize h_addr separately in the case where it is not a macro. | 429 // Initialize h_addr separately in the case where it is not a macro. |
427 hostent_.h_addr = NULL; | 430 hostent_.h_addr = NULL; |
428 #endif | 431 #endif |
429 } | 432 } |
430 | 433 |
431 } // namespace nacl_io | 434 } // namespace nacl_io |
432 | 435 |
433 #endif // PROVIDES_SOCKET_API | 436 #endif // PROVIDES_SOCKET_API |
OLD | NEW |