diff options
author | tfarina <tfarina@chromium.org> | 2016-01-12 18:26:59 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-13 02:28:48 +0000 |
commit | 3d87d7cd303c0a226f4b84993d704bc6c9cc6ade (patch) | |
tree | 186517ce361ba895a27f2852c5ec77b12db797ae /net | |
parent | 067b65d4448b7a28ebf7b3a7d96168a97fa4c21a (diff) | |
download | chromium_src-3d87d7cd303c0a226f4b84993d704bc6c9cc6ade.zip chromium_src-3d87d7cd303c0a226f4b84993d704bc6c9cc6ade.tar.gz chromium_src-3d87d7cd303c0a226f4b84993d704bc6c9cc6ade.tar.bz2 |
net: have SockaddrStorage type in its own header file
This patch moves SockaddrStorage type into its own header file,
as it seems more appropriate than in the generic net_util.h. This
should help breakout net_util.h even further. We are almost there.
BUG=488531
TEST=net_unittests
R=eroman@chromium.org
TBR=vitalybuka@chromium.org
Review URL: https://codereview.chromium.org/1584503002
Cr-Commit-Position: refs/heads/master@{#369081}
Diffstat (limited to 'net')
-rw-r--r-- | net/base/address_list_unittest.cc | 2 | ||||
-rw-r--r-- | net/base/ip_endpoint_unittest.cc | 2 | ||||
-rw-r--r-- | net/base/net_util.cc | 12 | ||||
-rw-r--r-- | net/base/net_util.h | 22 | ||||
-rw-r--r-- | net/base/network_interfaces_win.cc | 6 | ||||
-rw-r--r-- | net/base/network_interfaces_win.h | 1 | ||||
-rw-r--r-- | net/base/sockaddr_storage.cc | 27 | ||||
-rw-r--r-- | net/base/sockaddr_storage.h | 35 | ||||
-rw-r--r-- | net/net.gypi | 2 | ||||
-rw-r--r-- | net/socket/socket_posix.cc | 2 | ||||
-rw-r--r-- | net/socket/ssl_client_socket_nss.cc | 2 | ||||
-rw-r--r-- | net/socket/tcp_socket_posix.cc | 2 | ||||
-rw-r--r-- | net/socket/tcp_socket_unittest.cc | 2 | ||||
-rw-r--r-- | net/socket/tcp_socket_win.cc | 2 | ||||
-rw-r--r-- | net/socket/unix_domain_client_socket_posix.cc | 2 | ||||
-rw-r--r-- | net/socket/unix_domain_client_socket_posix_unittest.cc | 2 | ||||
-rw-r--r-- | net/socket/unix_domain_server_socket_posix.cc | 2 | ||||
-rw-r--r-- | net/tools/quic/quic_client.cc | 2 | ||||
-rw-r--r-- | net/tools/quic/quic_server.cc | 2 | ||||
-rw-r--r-- | net/udp/udp_socket_posix.cc | 2 | ||||
-rw-r--r-- | net/udp/udp_socket_win.cc | 2 |
21 files changed, 81 insertions, 52 deletions
diff --git a/net/base/address_list_unittest.cc b/net/base/address_list_unittest.cc index cdf7fa8..44955a9 100644 --- a/net/base/address_list_unittest.cc +++ b/net/base/address_list_unittest.cc @@ -6,7 +6,7 @@ #include "base/strings/string_util.h" #include "base/sys_byteorder.h" -#include "net/base/net_util.h" +#include "net/base/sockaddr_storage.h" #include "net/base/sys_addrinfo.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/net/base/ip_endpoint_unittest.cc b/net/base/ip_endpoint_unittest.cc index 4da0bbe..a2b647c 100644 --- a/net/base/ip_endpoint_unittest.cc +++ b/net/base/ip_endpoint_unittest.cc @@ -15,7 +15,7 @@ #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/sys_byteorder.h" -#include "net/base/net_util.h" +#include "net/base/sockaddr_storage.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" diff --git a/net/base/net_util.cc b/net/base/net_util.cc index afd4824..d2681f27 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -258,18 +258,6 @@ bool IsHostnameNonUnique(const std::string& hostname) { registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); } -SockaddrStorage::SockaddrStorage(const SockaddrStorage& other) - : addr_len(other.addr_len), - addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) { - memcpy(addr, other.addr, addr_len); -} - -void SockaddrStorage::operator=(const SockaddrStorage& other) { - addr_len = other.addr_len; - // addr is already set to &this->addr_storage by default ctor. - memcpy(addr, other.addr, addr_len); -} - std::string GetHostName() { #if defined(OS_NACL) NOTIMPLEMENTED(); diff --git a/net/base/net_util.h b/net/base/net_util.h index 0064f73..6a498f6 100644 --- a/net/base/net_util.h +++ b/net/base/net_util.h @@ -5,16 +5,6 @@ #ifndef NET_BASE_NET_UTIL_H_ #define NET_BASE_NET_UTIL_H_ -#include "build/build_config.h" - -#if defined(OS_POSIX) -#include <sys/socket.h> -#include <sys/types.h> -#elif defined(OS_WIN) -#include <winsock2.h> -#include <ws2tcpip.h> -#endif - #include <stddef.h> #include <stdint.h> @@ -71,18 +61,6 @@ NET_EXPORT std::string GetHostAndOptionalPort(const GURL& url); // that falls in an IANA-reserved range. NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); -// Convenience struct for when you need a |struct sockaddr|. -struct SockaddrStorage { - SockaddrStorage() : addr_len(sizeof(addr_storage)), - addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {} - SockaddrStorage(const SockaddrStorage& other); - void operator=(const SockaddrStorage& other); - - struct sockaddr_storage addr_storage; - socklen_t addr_len; - struct sockaddr* const addr; -}; - // Returns the hostname of the current system. Returns empty string on failure. NET_EXPORT std::string GetHostName(); diff --git a/net/base/network_interfaces_win.cc b/net/base/network_interfaces_win.cc index e8480d2..e451211 100644 --- a/net/base/network_interfaces_win.cc +++ b/net/base/network_interfaces_win.cc @@ -2,10 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "net/base/net_util.h" +#include "net/base/network_interfaces_win.h" -#include <iphlpapi.h> -#include <wlanapi.h> #pragma comment(lib, "iphlpapi.lib") #include <algorithm> @@ -23,7 +21,7 @@ #include "net/base/escape.h" #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/network_interfaces_win.h" +#include "net/base/net_util.h" #include "url/gurl.h" namespace net { diff --git a/net/base/network_interfaces_win.h b/net/base/network_interfaces_win.h index 353dda4..9d69418 100644 --- a/net/base/network_interfaces_win.h +++ b/net/base/network_interfaces_win.h @@ -8,6 +8,7 @@ // This file is only used to expose some of the internals // of network_interfaces_win.cc to tests. +#include <winsock2.h> #include <iphlpapi.h> #include <wlanapi.h> diff --git a/net/base/sockaddr_storage.cc b/net/base/sockaddr_storage.cc new file mode 100644 index 0000000..2822e07 --- /dev/null +++ b/net/base/sockaddr_storage.cc @@ -0,0 +1,27 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/base/sockaddr_storage.h" + +#include <string.h> + +namespace net { + +SockaddrStorage::SockaddrStorage() + : addr_len(sizeof(addr_storage)), + addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {} + +SockaddrStorage::SockaddrStorage(const SockaddrStorage& other) + : addr_len(other.addr_len), + addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) { + memcpy(addr, other.addr, addr_len); +} + +void SockaddrStorage::operator=(const SockaddrStorage& other) { + addr_len = other.addr_len; + // addr is already set to &this->addr_storage by default ctor. + memcpy(addr, other.addr, addr_len); +} + +} // namespace net diff --git a/net/base/sockaddr_storage.h b/net/base/sockaddr_storage.h new file mode 100644 index 0000000..cc31231 --- /dev/null +++ b/net/base/sockaddr_storage.h @@ -0,0 +1,35 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_BASE_SOCKADDR_STORAGE_H_ +#define NET_BASE_SOCKADDR_STORAGE_H_ + +#include "build/build_config.h" + +#if defined(OS_POSIX) +#include <sys/socket.h> +#include <sys/types.h> +#elif defined(OS_WIN) +#include <winsock2.h> +#include <ws2tcpip.h> +#endif + +#include "net/base/net_export.h" + +namespace net { + +// Convenience struct for when you need a |struct sockaddr|. +struct NET_EXPORT SockaddrStorage { + SockaddrStorage(); + SockaddrStorage(const SockaddrStorage& other); + void operator=(const SockaddrStorage& other); + + struct sockaddr_storage addr_storage; + socklen_t addr_len; + struct sockaddr* const addr; +}; + +} // namespace net + +#endif // NET_BASE_SOCKADDR_STORAGE_H_ diff --git a/net/net.gypi b/net/net.gypi index 0480934..3ccafca 100644 --- a/net/net.gypi +++ b/net/net.gypi @@ -60,6 +60,8 @@ 'base/rand_callback.h', 'base/registry_controlled_domains/registry_controlled_domain.cc', 'base/registry_controlled_domains/registry_controlled_domain.h', + 'base/sockaddr_storage.cc', + 'base/sockaddr_storage.h', 'base/socket_performance_watcher.cc', 'base/socket_performance_watcher.h', 'base/socket_performance_watcher_factory.h', diff --git a/net/socket/socket_posix.cc b/net/socket/socket_posix.cc index a18e22d..9689289 100644 --- a/net/socket/socket_posix.cc +++ b/net/socket/socket_posix.cc @@ -16,7 +16,7 @@ #include "net/base/io_buffer.h" #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/net_util.h" +#include "net/base/sockaddr_storage.h" namespace net { diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc index e1a8335..fcd8739 100644 --- a/net/socket/ssl_client_socket_nss.cc +++ b/net/socket/ssl_client_socket_nss.cc @@ -88,7 +88,7 @@ #include "net/base/address_list.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" -#include "net/base/net_util.h" +#include "net/base/sockaddr_storage.h" #include "net/cert/asn1_util.h" #include "net/cert/cert_status_flags.h" #include "net/cert/cert_verifier.h" diff --git a/net/socket/tcp_socket_posix.cc b/net/socket/tcp_socket_posix.cc index 9996e86..0546e60 100644 --- a/net/socket/tcp_socket_posix.cc +++ b/net/socket/tcp_socket_posix.cc @@ -21,9 +21,9 @@ #include "net/base/io_buffer.h" #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/net_util.h" #include "net/base/network_activity_monitor.h" #include "net/base/network_change_notifier.h" +#include "net/base/sockaddr_storage.h" #include "net/socket/socket_net_log_params.h" #include "net/socket/socket_posix.h" diff --git a/net/socket/tcp_socket_unittest.cc b/net/socket/tcp_socket_unittest.cc index d9d13c5..ade3ee7f 100644 --- a/net/socket/tcp_socket_unittest.cc +++ b/net/socket/tcp_socket_unittest.cc @@ -15,7 +15,7 @@ #include "net/base/io_buffer.h" #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/net_util.h" +#include "net/base/sockaddr_storage.h" #include "net/base/test_completion_callback.h" #include "net/socket/tcp_client_socket.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/net/socket/tcp_socket_win.cc b/net/socket/tcp_socket_win.cc index fdf1dfa..a9998e2 100644 --- a/net/socket/tcp_socket_win.cc +++ b/net/socket/tcp_socket_win.cc @@ -19,9 +19,9 @@ #include "net/base/io_buffer.h" #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/net_util.h" #include "net/base/network_activity_monitor.h" #include "net/base/network_change_notifier.h" +#include "net/base/sockaddr_storage.h" #include "net/base/winsock_init.h" #include "net/base/winsock_util.h" #include "net/socket/socket_descriptor.h" diff --git a/net/socket/unix_domain_client_socket_posix.cc b/net/socket/unix_domain_client_socket_posix.cc index fc2b303..564bef8 100644 --- a/net/socket/unix_domain_client_socket_posix.cc +++ b/net/socket/unix_domain_client_socket_posix.cc @@ -12,7 +12,7 @@ #include "base/posix/eintr_wrapper.h" #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/net_util.h" +#include "net/base/sockaddr_storage.h" #include "net/socket/socket_posix.h" namespace net { diff --git a/net/socket/unix_domain_client_socket_posix_unittest.cc b/net/socket/unix_domain_client_socket_posix_unittest.cc index 814595e..3583075 100644 --- a/net/socket/unix_domain_client_socket_posix_unittest.cc +++ b/net/socket/unix_domain_client_socket_posix_unittest.cc @@ -14,7 +14,7 @@ #include "base/posix/eintr_wrapper.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" -#include "net/base/net_util.h" +#include "net/base/sockaddr_storage.h" #include "net/base/test_completion_callback.h" #include "net/socket/socket_posix.h" #include "net/socket/unix_domain_server_socket_posix.h" diff --git a/net/socket/unix_domain_server_socket_posix.cc b/net/socket/unix_domain_server_socket_posix.cc index 49945c3..161893a 100644 --- a/net/socket/unix_domain_server_socket_posix.cc +++ b/net/socket/unix_domain_server_socket_posix.cc @@ -12,7 +12,7 @@ #include "base/logging.h" #include "net/base/net_errors.h" -#include "net/base/net_util.h" +#include "net/base/sockaddr_storage.h" #include "net/socket/socket_posix.h" #include "net/socket/unix_domain_client_socket_posix.h" diff --git a/net/tools/quic/quic_client.cc b/net/tools/quic/quic_client.cc index b1ed67e..00d38ea 100644 --- a/net/tools/quic/quic_client.cc +++ b/net/tools/quic/quic_client.cc @@ -13,7 +13,7 @@ #include "base/logging.h" #include "base/run_loop.h" -#include "net/base/net_util.h" +#include "net/base/sockaddr_storage.h" #include "net/quic/crypto/quic_random.h" #include "net/quic/quic_connection.h" #include "net/quic/quic_data_reader.h" diff --git a/net/tools/quic/quic_server.cc b/net/tools/quic/quic_server.cc index fc1395b..2ed4e5b 100644 --- a/net/tools/quic/quic_server.cc +++ b/net/tools/quic/quic_server.cc @@ -12,7 +12,7 @@ #include <sys/socket.h> #include "net/base/ip_endpoint.h" -#include "net/base/net_util.h" +#include "net/base/sockaddr_storage.h" #include "net/quic/crypto/crypto_handshake.h" #include "net/quic/crypto/quic_random.h" #include "net/quic/quic_clock.h" diff --git a/net/udp/udp_socket_posix.cc b/net/udp/udp_socket_posix.cc index 545d2ee..ea1a560 100644 --- a/net/udp/udp_socket_posix.cc +++ b/net/udp/udp_socket_posix.cc @@ -23,8 +23,8 @@ #include "net/base/io_buffer.h" #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/net_util.h" #include "net/base/network_activity_monitor.h" +#include "net/base/sockaddr_storage.h" #include "net/log/net_log.h" #include "net/socket/socket_descriptor.h" #include "net/udp/udp_net_log_parameters.h" diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc index 60b254f..27e2750 100644 --- a/net/udp/udp_socket_win.cc +++ b/net/udp/udp_socket_win.cc @@ -17,8 +17,8 @@ #include "net/base/io_buffer.h" #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/net_util.h" #include "net/base/network_activity_monitor.h" +#include "net/base/sockaddr_storage.h" #include "net/base/winsock_init.h" #include "net/base/winsock_util.h" #include "net/log/net_log.h" |