| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <unicode/regex.h> | 9 #include <unicode/regex.h> |
| 10 #include <unicode/ucnv.h> | 10 #include <unicode/ucnv.h> |
| (...skipping 2012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2023 return false; | 2023 return false; |
| 2024 } | 2024 } |
| 2025 | 2025 |
| 2026 return true; | 2026 return true; |
| 2027 } | 2027 } |
| 2028 | 2028 |
| 2029 // Returns the port field of the sockaddr in |info|. | 2029 // Returns the port field of the sockaddr in |info|. |
| 2030 uint16* GetPortFieldFromAddrinfo(const struct addrinfo* info) { | 2030 uint16* GetPortFieldFromAddrinfo(const struct addrinfo* info) { |
| 2031 DCHECK(info); | 2031 DCHECK(info); |
| 2032 if (info->ai_family == AF_INET) { | 2032 if (info->ai_family == AF_INET) { |
| 2033 DCHECK_EQ(sizeof(sockaddr_in), info->ai_addrlen); | 2033 DCHECK_EQ(sizeof(sockaddr_in), static_cast<size_t>(info->ai_addrlen)); |
| 2034 struct sockaddr_in* sockaddr = | 2034 struct sockaddr_in* sockaddr = |
| 2035 reinterpret_cast<struct sockaddr_in*>(info->ai_addr); | 2035 reinterpret_cast<struct sockaddr_in*>(info->ai_addr); |
| 2036 return &sockaddr->sin_port; | 2036 return &sockaddr->sin_port; |
| 2037 } else if (info->ai_family == AF_INET6) { | 2037 } else if (info->ai_family == AF_INET6) { |
| 2038 DCHECK_EQ(sizeof(sockaddr_in6), info->ai_addrlen); | 2038 DCHECK_EQ(sizeof(sockaddr_in6), static_cast<size_t>(info->ai_addrlen)); |
| 2039 struct sockaddr_in6* sockaddr = | 2039 struct sockaddr_in6* sockaddr = |
| 2040 reinterpret_cast<struct sockaddr_in6*>(info->ai_addr); | 2040 reinterpret_cast<struct sockaddr_in6*>(info->ai_addr); |
| 2041 return &sockaddr->sin6_port; | 2041 return &sockaddr->sin6_port; |
| 2042 } else { | 2042 } else { |
| 2043 NOTREACHED(); | 2043 NOTREACHED(); |
| 2044 return NULL; | 2044 return NULL; |
| 2045 } | 2045 } |
| 2046 } | 2046 } |
| 2047 | 2047 |
| 2048 int GetPortFromAddrinfo(const struct addrinfo* info) { | 2048 int GetPortFromAddrinfo(const struct addrinfo* info) { |
| 2049 uint16* port_field = GetPortFieldFromAddrinfo(info); | 2049 uint16* port_field = GetPortFieldFromAddrinfo(info); |
| 2050 if (!port_field) | 2050 if (!port_field) |
| 2051 return -1; | 2051 return -1; |
| 2052 return ntohs(*port_field); | 2052 return ntohs(*port_field); |
| 2053 } | 2053 } |
| 2054 | 2054 |
| 2055 } // namespace net | 2055 } // namespace net |
| OLD | NEW |