Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Side by Side Diff: net/base/net_util.cc

Issue 236203018: win: Implement Bluetooth server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for #4 comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 if (port) 1182 if (port)
1182 *port = base::NetToHost16(addr->sin_port); 1183 *port = base::NetToHost16(addr->sin_port);
1183 return true; 1184 return true;
1184 } 1185 }
1185 1186
1186 if (sock_addr->sa_family == AF_INET6) { 1187 if (sock_addr->sa_family == AF_INET6) {
1187 if (sock_addr_len < static_cast<socklen_t>(sizeof(struct sockaddr_in6))) 1188 if (sock_addr_len < static_cast<socklen_t>(sizeof(struct sockaddr_in6)))
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 uint8*>(&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 if (sock_addr->sa_family == AF_BTH) {
1201 if (sock_addr_len < static_cast<socklen_t>(sizeof(SOCKADDR_BTH)))
1202 return false;
1203 const SOCKADDR_BTH* addr =
1204 reinterpret_cast<const SOCKADDR_BTH*>(sock_addr);
1205 *address = reinterpret_cast<const uint8*>(&addr->btAddr);
1206 *address_len = kBthAddressSize;
1207 if (port)
1208 *port = addr->port;
1209 return true;
1210 }
1211 #endif
1212
1198 return false; // Unrecognized |sa_family|. 1213 return false; // Unrecognized |sa_family|.
1199 } 1214 }
1200 1215
1201 std::string IPAddressToString(const uint8* address, 1216 std::string IPAddressToString(const uint8* address,
1202 size_t address_len) { 1217 size_t address_len) {
1203 std::string str; 1218 std::string str;
1204 url_canon::StdStringCanonOutput output(&str); 1219 url_canon::StdStringCanonOutput output(&str);
1205 1220
1206 if (address_len == kIPv4AddressSize) { 1221 if (address_len == kIPv4AddressSize) {
1207 url_canon::AppendIPv4Address(address, &output); 1222 url_canon::AppendIPv4Address(address, &output);
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 } 1848 }
1834 return a1.size() * CHAR_BIT; 1849 return a1.size() * CHAR_BIT;
1835 } 1850 }
1836 1851
1837 unsigned MaskPrefixLength(const IPAddressNumber& mask) { 1852 unsigned MaskPrefixLength(const IPAddressNumber& mask) {
1838 IPAddressNumber all_ones(mask.size(), 0xFF); 1853 IPAddressNumber all_ones(mask.size(), 0xFF);
1839 return CommonPrefixLength(mask, all_ones); 1854 return CommonPrefixLength(mask, all_ones);
1840 } 1855 }
1841 1856
1842 } // namespace net 1857 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698