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

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

Issue 348803003: Refactor tcp socket and unix domain socket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments and fixed unittests for chrome os. Created 6 years, 5 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
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 #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
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) {
mmenke 2014/06/30 18:26:51 Ahh...right. Mind adding a comment along those li
byungchul 2014/06/30 19:38:34 Done.
512 addr_len = other.addr_len;
513 memcpy(addr, other.addr, addr_len);
514 }
515
504 // Extracts the address and port portions of a sockaddr. 516 // Extracts the address and port portions of a sockaddr.
505 bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr, 517 bool GetIPAddressFromSockAddr(const struct sockaddr* sock_addr,
506 socklen_t sock_addr_len, 518 socklen_t sock_addr_len,
507 const uint8** address, 519 const uint8** address,
508 size_t* address_len, 520 size_t* address_len,
509 uint16* port) { 521 uint16* port) {
510 if (sock_addr->sa_family == AF_INET) { 522 if (sock_addr->sa_family == AF_INET) {
511 if (sock_addr_len < static_cast<socklen_t>(sizeof(struct sockaddr_in))) 523 if (sock_addr_len < static_cast<socklen_t>(sizeof(struct sockaddr_in)))
512 return false; 524 return false;
513 const struct sockaddr_in* addr = 525 const struct sockaddr_in* addr =
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 } 1009 }
998 return a1.size() * CHAR_BIT; 1010 return a1.size() * CHAR_BIT;
999 } 1011 }
1000 1012
1001 unsigned MaskPrefixLength(const IPAddressNumber& mask) { 1013 unsigned MaskPrefixLength(const IPAddressNumber& mask) {
1002 IPAddressNumber all_ones(mask.size(), 0xFF); 1014 IPAddressNumber all_ones(mask.size(), 0xFF);
1003 return CommonPrefixLength(mask, all_ones); 1015 return CommonPrefixLength(mask, all_ones);
1004 } 1016 }
1005 1017
1006 } // namespace net 1018 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util.h ('k') | net/net.gyp » ('j') | net/socket/socket_libevent.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698