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 <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> |
8 | 9 |
9 #include <algorithm> | 10 #include <algorithm> |
10 #include <iterator> | 11 #include <iterator> |
11 #include <set> | 12 #include <set> |
12 | 13 |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 | 15 |
15 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
16 #include <windows.h> | 17 #include <windows.h> |
17 #include <iphlpapi.h> | 18 #include <iphlpapi.h> |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 if (!array) | 495 if (!array) |
495 return false; | 496 return false; |
496 size_t width = host_addr.size() + 1; | 497 size_t width = host_addr.size() + 1; |
497 for (size_t i = 0; i < array_size; ++i, array += width) { | 498 for (size_t i = 0; i < array_size; ++i, array += width) { |
498 if (IPNumberPrefixCheck(host_addr, array, array[width-1])) | 499 if (IPNumberPrefixCheck(host_addr, array, array[width-1])) |
499 return true; | 500 return true; |
500 } | 501 } |
501 return false; | 502 return false; |
502 } | 503 } |
503 | 504 |
| 505 SockaddrStorage::SockaddrStorage(const SockaddrStorage& other) |
| 506 : addr_len(other.addr_len), |
| 507 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) { |
| 508 memcpy(addr, other.addr, addr_len); |
| 509 } |
| 510 |
| 511 void SockaddrStorage::operator=(const SockaddrStorage& other) { |
| 512 addr_len = other.addr_len; |
| 513 // addr is already set to &this->addr_storage by default ctor. |
| 514 memcpy(addr, other.addr, addr_len); |
| 515 } |
| 516 |
504 // Extracts the address and port portions of a sockaddr. | 517 // Extracts the address and port portions of a sockaddr. |
505 bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr, | 518 bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr, |
506 socklen_t sock_addr_len, | 519 socklen_t sock_addr_len, |
507 const uint8** address, | 520 const uint8** address, |
508 size_t* address_len, | 521 size_t* address_len, |
509 uint16* port) { | 522 uint16* port) { |
510 if (sock_addr->sa_family == AF_INET) { | 523 if (sock_addr->sa_family == AF_INET) { |
511 if (sock_addr_len < static_cast<socklen_t>(sizeof(struct sockaddr_in))) | 524 if (sock_addr_len < static_cast<socklen_t>(sizeof(struct sockaddr_in))) |
512 return false; | 525 return false; |
513 const struct sockaddr_in* addr = | 526 const struct sockaddr_in* addr = |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 } | 1010 } |
998 return a1.size() * CHAR_BIT; | 1011 return a1.size() * CHAR_BIT; |
999 } | 1012 } |
1000 | 1013 |
1001 unsigned MaskPrefixLength(const IPAddressNumber& mask) { | 1014 unsigned MaskPrefixLength(const IPAddressNumber& mask) { |
1002 IPAddressNumber all_ones(mask.size(), 0xFF); | 1015 IPAddressNumber all_ones(mask.size(), 0xFF); |
1003 return CommonPrefixLength(mask, all_ones); | 1016 return CommonPrefixLength(mask, all_ones); |
1004 } | 1017 } |
1005 | 1018 |
1006 } // namespace net | 1019 } // namespace net |
OLD | NEW |