OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/sys_byteorder.h" |
16 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
17 #include "base/test/test_file_util.h" | 18 #include "base/test/test_file_util.h" |
18 #include "base/time.h" | 19 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
21 #include "net/base/sys_addrinfo.h" | 22 #include "net/base/sys_addrinfo.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 namespace net { | 25 namespace net { |
25 | 26 |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 414 |
414 struct addrinfo* ai = &static_ai; | 415 struct addrinfo* ai = &static_ai; |
415 ai->ai_socktype = SOCK_STREAM; | 416 ai->ai_socktype = SOCK_STREAM; |
416 memset(ai, 0, sizeof(static_ai)); | 417 memset(ai, 0, sizeof(static_ai)); |
417 | 418 |
418 ai->ai_family = AF_INET; | 419 ai->ai_family = AF_INET; |
419 ai->ai_addrlen = sizeof(static_addr4); | 420 ai->ai_addrlen = sizeof(static_addr4); |
420 | 421 |
421 struct sockaddr_in* addr4 = &static_addr4; | 422 struct sockaddr_in* addr4 = &static_addr4; |
422 memset(addr4, 0, sizeof(static_addr4)); | 423 memset(addr4, 0, sizeof(static_addr4)); |
423 addr4->sin_port = htons(port); | 424 addr4->sin_port = base::HostToNet16(port); |
424 addr4->sin_family = ai->ai_family; | 425 addr4->sin_family = ai->ai_family; |
425 memcpy(&addr4->sin_addr, bytes, 4); | 426 memcpy(&addr4->sin_addr, bytes, 4); |
426 | 427 |
427 ai->ai_addr = (sockaddr*)addr4; | 428 ai->ai_addr = (sockaddr*)addr4; |
428 return ai; | 429 return ai; |
429 } | 430 } |
430 | 431 |
431 // Returns a addrinfo for the given 128-bit address (IPv6.) | 432 // Returns a addrinfo for the given 128-bit address (IPv6.) |
432 // The result lives in static storage, so don't delete it. | 433 // The result lives in static storage, so don't delete it. |
433 // |bytes| should be an array of length 16. | 434 // |bytes| should be an array of length 16. |
434 const struct addrinfo* GetIPv6Address(const uint8* bytes, int port) { | 435 const struct addrinfo* GetIPv6Address(const uint8* bytes, int port) { |
435 static struct addrinfo static_ai; | 436 static struct addrinfo static_ai; |
436 static struct sockaddr_in6 static_addr6; | 437 static struct sockaddr_in6 static_addr6; |
437 | 438 |
438 struct addrinfo* ai = &static_ai; | 439 struct addrinfo* ai = &static_ai; |
439 ai->ai_socktype = SOCK_STREAM; | 440 ai->ai_socktype = SOCK_STREAM; |
440 memset(ai, 0, sizeof(static_ai)); | 441 memset(ai, 0, sizeof(static_ai)); |
441 | 442 |
442 ai->ai_family = AF_INET6; | 443 ai->ai_family = AF_INET6; |
443 ai->ai_addrlen = sizeof(static_addr6); | 444 ai->ai_addrlen = sizeof(static_addr6); |
444 | 445 |
445 struct sockaddr_in6* addr6 = &static_addr6; | 446 struct sockaddr_in6* addr6 = &static_addr6; |
446 memset(addr6, 0, sizeof(static_addr6)); | 447 memset(addr6, 0, sizeof(static_addr6)); |
447 addr6->sin6_port = htons(port); | 448 addr6->sin6_port = base::HostToNet16(port); |
448 addr6->sin6_family = ai->ai_family; | 449 addr6->sin6_family = ai->ai_family; |
449 memcpy(&addr6->sin6_addr, bytes, 16); | 450 memcpy(&addr6->sin6_addr, bytes, 16); |
450 | 451 |
451 ai->ai_addr = (sockaddr*)addr6; | 452 ai->ai_addr = (sockaddr*)addr6; |
452 return ai; | 453 return ai; |
453 } | 454 } |
454 | 455 |
455 // A helper for IDN*{Fast,Slow}. | 456 // A helper for IDN*{Fast,Slow}. |
456 // Append "::<language list>" to |expected| and |actual| to make it | 457 // Append "::<language list>" to |expected| and |actual| to make it |
457 // easy to tell which sub-case fails without debugging. | 458 // easy to tell which sub-case fails without debugging. |
(...skipping 2757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3215 if (it->address[i] != 0) { | 3216 if (it->address[i] != 0) { |
3216 all_zeroes = false; | 3217 all_zeroes = false; |
3217 break; | 3218 break; |
3218 } | 3219 } |
3219 } | 3220 } |
3220 EXPECT_FALSE(all_zeroes); | 3221 EXPECT_FALSE(all_zeroes); |
3221 } | 3222 } |
3222 } | 3223 } |
3223 | 3224 |
3224 } // namespace net | 3225 } // namespace net |
OLD | NEW |