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 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
11 #include <map> | 11 #include <map> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 | 15 |
16 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
17 #include <windows.h> | 17 #include <windows.h> |
18 #include <iphlpapi.h> | 18 #include <iphlpapi.h> |
19 #include <winsock2.h> | 19 #include <winsock2.h> |
| 20 #include <ws2bth.h> |
20 #pragma comment(lib, "iphlpapi.lib") | 21 #pragma comment(lib, "iphlpapi.lib") |
21 #elif defined(OS_POSIX) | 22 #elif defined(OS_POSIX) |
22 #include <fcntl.h> | 23 #include <fcntl.h> |
23 #include <netdb.h> | 24 #include <netdb.h> |
24 #include <netinet/in.h> | 25 #include <netinet/in.h> |
25 #if !defined(OS_NACL) | 26 #if !defined(OS_NACL) |
26 #include <net/if.h> | 27 #include <net/if.h> |
27 #if !defined(OS_ANDROID) | 28 #if !defined(OS_ANDROID) |
28 #include <ifaddrs.h> | 29 #include <ifaddrs.h> |
29 #endif // !defined(OS_NACL) | 30 #endif // !defined(OS_NACL) |
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 return false; | 1189 return false; |
1189 const struct sockaddr_in6* addr = | 1190 const struct sockaddr_in6* addr = |
1190 reinterpret_cast<const struct sockaddr_in6*>(sock_addr); | 1191 reinterpret_cast<const struct sockaddr_in6*>(sock_addr); |
1191 *address = reinterpret_cast<const unsigned char*>(&addr->sin6_addr); | 1192 *address = reinterpret_cast<const unsigned char*>(&addr->sin6_addr); |
1192 *address_len = kIPv6AddressSize; | 1193 *address_len = kIPv6AddressSize; |
1193 if (port) | 1194 if (port) |
1194 *port = base::NetToHost16(addr->sin6_port); | 1195 *port = base::NetToHost16(addr->sin6_port); |
1195 return true; | 1196 return true; |
1196 } | 1197 } |
1197 | 1198 |
| 1199 #if defined(OS_WIN) |
| 1200 // Bluetooth address size. Windows bluetooth is supported via winsock. |
| 1201 const size_t kBtAddressSize = 6; |
| 1202 if (sock_addr->sa_family == AF_BTH) { |
| 1203 if (sock_addr_len < static_cast<socklen_t>(sizeof(SOCKADDR_BTH))) |
| 1204 return false; |
| 1205 const SOCKADDR_BTH* addr = |
| 1206 reinterpret_cast<const SOCKADDR_BTH*>(sock_addr); |
| 1207 *address = reinterpret_cast<const uint8*>(&addr->btAddr); |
| 1208 *address_len = kBtAddressSize; |
| 1209 if (port) |
| 1210 *port = addr->port; |
| 1211 return true; |
| 1212 } |
| 1213 #endif |
| 1214 |
1198 return false; // Unrecognized |sa_family|. | 1215 return false; // Unrecognized |sa_family|. |
1199 } | 1216 } |
1200 | 1217 |
1201 std::string IPAddressToString(const uint8* address, | 1218 std::string IPAddressToString(const uint8* address, |
1202 size_t address_len) { | 1219 size_t address_len) { |
1203 std::string str; | 1220 std::string str; |
1204 url_canon::StdStringCanonOutput output(&str); | 1221 url_canon::StdStringCanonOutput output(&str); |
1205 | 1222 |
1206 if (address_len == kIPv4AddressSize) { | 1223 if (address_len == kIPv4AddressSize) { |
1207 url_canon::AppendIPv4Address(address, &output); | 1224 url_canon::AppendIPv4Address(address, &output); |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 } | 1850 } |
1834 return a1.size() * CHAR_BIT; | 1851 return a1.size() * CHAR_BIT; |
1835 } | 1852 } |
1836 | 1853 |
1837 unsigned MaskPrefixLength(const IPAddressNumber& mask) { | 1854 unsigned MaskPrefixLength(const IPAddressNumber& mask) { |
1838 IPAddressNumber all_ones(mask.size(), 0xFF); | 1855 IPAddressNumber all_ones(mask.size(), 0xFF); |
1839 return CommonPrefixLength(mask, all_ones); | 1856 return CommonPrefixLength(mask, all_ones); |
1840 } | 1857 } |
1841 | 1858 |
1842 } // namespace net | 1859 } // namespace net |
OLD | NEW |