diff options
27 files changed, 104 insertions, 121 deletions
diff --git a/base/base.gypi b/base/base.gypi index 7a99941..0165db4 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -293,6 +293,7 @@ 'system_monitor/system_monitor_mac.mm', 'system_monitor/system_monitor_posix.cc', 'system_monitor/system_monitor_win.cc', + 'sys_byteorder.h', 'sys_info.h', 'sys_info_chromeos.cc', 'sys_info_freebsd.cc', diff --git a/base/sys_byteorder.h b/base/sys_byteorder.h new file mode 100644 index 0000000..9fcdbba --- /dev/null +++ b/base/sys_byteorder.h @@ -0,0 +1,75 @@ +// Copyright (c) 2011 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. + +// This is a convenience header to pull in the platform-specific +// headers that define functions for byte-order conversion, +// particularly: ntohs(), htons(), ntohl(), htonl(). Prefer including +// this file instead of directly writing the #if / #else, since it +// avoids duplicating the platform-specific selections. +// This header also provides ntohll() and htonll() for byte-order conversion +// for 64-bit integers. + +#ifndef BASE_SYS_BYTEORDER_H_ +#define BASE_SYS_BYTEORDER_H_ + +#include "base/basictypes.h" +#include "build/build_config.h" + +#if defined(OS_WIN) +#include <winsock2.h> +#else +#include <arpa/inet.h> +#endif + +// Include headers to provide byteswap for all platforms. +#if defined(COMPILER_MSVC) +#include <stdlib.h> +#elif defined(OS_MACOSX) +#include <libkern/OSByteOrder.h> +#elif defined(OS_OPENBSD) +#include <sys/endian.h> +#else +#include <byteswap.h> +#endif + + +namespace base { + +// Returns a value with all bytes in |x| swapped, i.e. reverses the endianness. +inline uint64 ByteSwap(uint64 x) { +#if defined(COMPILER_MSVC) + return _byteswap_uint64(x); +#elif defined(OS_MACOSX) + return OSSwapInt64(x); +#elif defined(OS_OPENBSD) + return swap64(x); +#else + return bswap_64(x); +#endif +} + +// Converts the bytes in |x| from network to host order (endianness), and +// returns the result. +inline uint64 ntohll(uint64 x) { +#if defined(ARCH_CPU_LITTLE_ENDIAN) + return ByteSwap(x); +#else + return x; +#endif +} + +// Converts the bytes in |x| from host to network order (endianness), and +// returns the result. +inline uint64 htonll(uint64 x) { +#if defined(ARCH_CPU_LITTLE_ENDIAN) + return ByteSwap(x); +#else + return x; +#endif +} + +} // namespace base + + +#endif // BASE_SYS_BYTEORDER_H_ diff --git a/chrome/browser/chromeos/web_socket_proxy.cc b/chrome/browser/chromeos/web_socket_proxy.cc index 1a8f3207..bf1aa28 100644 --- a/chrome/browser/chromeos/web_socket_proxy.cc +++ b/chrome/browser/chromeos/web_socket_proxy.cc @@ -14,7 +14,6 @@ #include <map> #include <vector> -#include <arpa/inet.h> #include <errno.h> #include <fcntl.h> #include <netinet/in.h> @@ -37,6 +36,7 @@ #include "base/stl_util.h" #include "base/string_number_conversions.h" #include "base/string_util.h" +#include "base/sys_byteorder.h" #include "chrome/browser/chromeos/web_socket_proxy_helper.h" #include "chrome/browser/internal_auth.h" #include "chrome/common/chrome_notification_types.h" diff --git a/chrome/browser/safe_browsing/protocol_parser.cc b/chrome/browser/safe_browsing/protocol_parser.cc index 00756dd..168aee9 100644 --- a/chrome/browser/safe_browsing/protocol_parser.cc +++ b/chrome/browser/safe_browsing/protocol_parser.cc @@ -10,16 +10,11 @@ #include "base/logging.h" #include "base/stringprintf.h" #include "base/string_split.h" +#include "base/sys_byteorder.h" #include "build/build_config.h" #include "chrome/browser/safe_browsing/protocol_parser.h" #include "chrome/browser/safe_browsing/safe_browsing_util.h" -#if defined(OS_WIN) -#include <Winsock2.h> -#elif defined(OS_POSIX) -#include <arpa/inet.h> -#endif - namespace { // Helper function for quick scans of a line oriented protocol. Note that we use // std::string::assign(const charT* s, size_type n) diff --git a/chrome/browser/sync/util/nigori.cc b/chrome/browser/sync/util/nigori.cc index f8cffca..799a3f4 100644 --- a/chrome/browser/sync/util/nigori.cc +++ b/chrome/browser/sync/util/nigori.cc @@ -4,12 +4,6 @@ #include "chrome/browser/sync/util/nigori.h" -#if defined(OS_WIN) -#include <winsock2.h> // for htonl -#else -#include <arpa/inet.h> -#endif - #include <sstream> #include <vector> @@ -17,6 +11,7 @@ #include "base/logging.h" #include "base/rand_util.h" #include "base/string_util.h" +#include "base/sys_byteorder.h" #include "crypto/encryptor.h" #include "crypto/hmac.h" diff --git a/content/browser/renderer_host/p2p/socket_host.cc b/content/browser/renderer_host/p2p/socket_host.cc index ae77df5..0f07127 100644 --- a/content/browser/renderer_host/p2p/socket_host.cc +++ b/content/browser/renderer_host/p2p/socket_host.cc @@ -4,7 +4,7 @@ #include "content/browser/renderer_host/p2p/socket_host.h" -#include "net/base/sys_byteorder.h" +#include "base/sys_byteorder.h" #include "content/browser/renderer_host/p2p/socket_host_tcp.h" #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" #include "content/browser/renderer_host/p2p/socket_host_udp.h" diff --git a/content/browser/renderer_host/p2p/socket_host_tcp.cc b/content/browser/renderer_host/p2p/socket_host_tcp.cc index db94edc..755cd0d 100644 --- a/content/browser/renderer_host/p2p/socket_host_tcp.cc +++ b/content/browser/renderer_host/p2p/socket_host_tcp.cc @@ -4,11 +4,11 @@ #include "content/browser/renderer_host/p2p/socket_host_tcp.h" +#include "base/sys_byteorder.h" #include "content/common/p2p_messages.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/base/net_util.h" -#include "net/base/sys_byteorder.h" #include "net/socket/tcp_client_socket.h" namespace { diff --git a/content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc b/content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc index 2b88f4a..254b47b 100644 --- a/content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc +++ b/content/browser/renderer_host/p2p/socket_host_tcp_unittest.cc @@ -6,8 +6,8 @@ #include <deque> +#include "base/sys_byteorder.h" #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" -#include "net/base/sys_byteorder.h" #include "net/socket/stream_socket.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/content/browser/renderer_host/p2p/socket_host_test_utils.h b/content/browser/renderer_host/p2p/socket_host_test_utils.h index 0ea8c1c..6c3113b 100644 --- a/content/browser/renderer_host/p2p/socket_host_test_utils.h +++ b/content/browser/renderer_host/p2p/socket_host_test_utils.h @@ -7,6 +7,7 @@ #include <vector> +#include "base/sys_byteorder.h" #include "content/common/p2p_messages.h" #include "ipc/ipc_message.h" #include "ipc/ipc_message_utils.h" @@ -14,7 +15,6 @@ #include "net/base/completion_callback.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" -#include "net/base/sys_byteorder.h" #include "net/socket/stream_socket.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc b/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc index 02cc3b2..b294c78 100644 --- a/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc +++ b/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc @@ -7,11 +7,11 @@ #include <deque> #include <vector> +#include "base/sys_byteorder.h" #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" #include "net/base/io_buffer.h" #include "net/base/ip_endpoint.h" #include "net/base/net_errors.h" -#include "net/base/sys_byteorder.h" #include "net/udp/datagram_server_socket.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/content/renderer/p2p/ipc_network_manager.cc b/content/renderer/p2p/ipc_network_manager.cc index 019801b..b999506 100644 --- a/content/renderer/p2p/ipc_network_manager.cc +++ b/content/renderer/p2p/ipc_network_manager.cc @@ -5,8 +5,8 @@ #include "content/renderer/p2p/ipc_network_manager.h" #include "base/bind.h" +#include "base/sys_byteorder.h" #include "net/base/net_util.h" -#include "net/base/sys_byteorder.h" namespace content { diff --git a/crypto/encryptor.cc b/crypto/encryptor.cc index 763dc2c..31a7cc8 100644 --- a/crypto/encryptor.cc +++ b/crypto/encryptor.cc @@ -5,35 +5,7 @@ #include "crypto/encryptor.h" #include "base/logging.h" -#include "build/build_config.h" - -// Include headers to provide bswap for all platforms. -#if defined(COMPILER_MSVC) -#include <stdlib.h> -#define bswap_16(x) _byteswap_ushort(x) -#define bswap_32(x) _byteswap_ulong(x) -#define bswap_64(x) _byteswap_uint64(x) -#elif defined(OS_MACOSX) -#include <libkern/OSByteOrder.h> -#define bswap_16(x) OSSwapInt16(x) -#define bswap_32(x) OSSwapInt32(x) -#define bswap_64(x) OSSwapInt64(x) -#elif defined(OS_OPENBSD) -#include <sys/endian.h> -#define bswap_16(x) swap16(x) -#define bswap_32(x) swap32(x) -#define bswap_64(x) swap64(x) -#else -#include <byteswap.h> -#endif - -#if defined(ARCH_CPU_LITTLE_ENDIAN) -#define ntoh_64(x) bswap_64(x) -#define hton_64(x) bswap_64(x) -#else -#define ntoh_64(x) (x) -#define hton_64(x) (x) -#endif +#include "base/sys_byteorder.h" namespace crypto { @@ -49,14 +21,14 @@ Encryptor::Counter::~Counter() { } bool Encryptor::Counter::Increment() { - uint64 low_num = ntoh_64(counter_.components64[1]); + uint64 low_num = base::ntohll(counter_.components64[1]); uint64 new_low_num = low_num + 1; - counter_.components64[1] = hton_64(new_low_num); + counter_.components64[1] = base::htonll(new_low_num); // If overflow occured then increment the most significant component. if (new_low_num < low_num) { counter_.components64[0] = - hton_64(ntoh_64(counter_.components64[0]) + 1); + base::htonll(base::ntohll(counter_.components64[0]) + 1); } // TODO(hclam): Return false if counter value overflows. diff --git a/crypto/p224.cc b/crypto/p224.cc index 0c87a5f..31a19bc 100644 --- a/crypto/p224.cc +++ b/crypto/p224.cc @@ -11,14 +11,7 @@ #include <string.h> -#include "build/build_config.h" - -// For htonl and ntohl. -#if defined(OS_WIN) -#include <winsock2.h> -#else -#include <arpa/inet.h> -#endif +#include "base/sys_byteorder.h" namespace { diff --git a/jingle/notifier/base/chrome_async_socket_unittest.cc b/jingle/notifier/base/chrome_async_socket_unittest.cc index e9ce73c..a86b5c8 100644 --- a/jingle/notifier/base/chrome_async_socket_unittest.cc +++ b/jingle/notifier/base/chrome_async_socket_unittest.cc @@ -4,12 +4,6 @@ #include "jingle/notifier/base/chrome_async_socket.h" -#if defined(OS_WIN) -#include <winsock2.h> -#elif defined(OS_POSIX) -#include <arpa/inet.h> -#endif - #include <deque> #include <string> @@ -17,6 +11,7 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" +#include "base/sys_byteorder.h" #include "jingle/notifier/base/resolving_client_socket_factory.h" #include "net/base/cert_verifier.h" #include "net/base/net_errors.h" diff --git a/jingle/notifier/communicator/xmpp_connection_generator.cc b/jingle/notifier/communicator/xmpp_connection_generator.cc index b19d16b..3a05d9c 100644 --- a/jingle/notifier/communicator/xmpp_connection_generator.cc +++ b/jingle/notifier/communicator/xmpp_connection_generator.cc @@ -12,18 +12,13 @@ #include "jingle/notifier/communicator/xmpp_connection_generator.h" -#if defined(OS_WIN) -#include <winsock2.h> -#elif defined(OS_POSIX) -#include <arpa/inet.h> -#endif - #include <vector> #include "base/bind.h" #include "base/callback.h" #include "base/compiler_specific.h" #include "base/logging.h" +#include "base/sys_byteorder.h" #include "jingle/notifier/base/server_information.h" #include "jingle/notifier/communicator/connection_options.h" #include "jingle/notifier/communicator/connection_settings.h" diff --git a/net/base/sys_byteorder.h b/net/base/sys_byteorder.h deleted file mode 100644 index bde3151..0000000 --- a/net/base/sys_byteorder.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2011 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. - -// This is a convenience header to pull in the platform-specific -// headers that define functions for byte-order conversion, -// particularly: ntohs(), htons(), ntohl(), htonl(). Prefer including -// this file instead of directly writing the #if / #else, since it -// avoids duplicating the platform-specific selections. - -#ifndef NET_BASE_SYS_BYTEORDER_H_ -#define NET_BASE_SYS_BYTEORDER_H_ - -#include "build/build_config.h" - -#if defined(OS_WIN) -#include <winsock2.h> -#else -#include <arpa/inet.h> -#endif - -#endif // NET_BASE_SYS_BYTEORDER_H_ diff --git a/net/dns/dns_config_service_posix_unittest.cc b/net/dns/dns_config_service_posix_unittest.cc index a3f90aa..ab9e56d 100644 --- a/net/dns/dns_config_service_posix_unittest.cc +++ b/net/dns/dns_config_service_posix_unittest.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <arpa/inet.h> #include <resolv.h> +#include "base/sys_byteorder.h" #include "net/dns/dns_config_service_posix.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/net/dns/dns_query.cc b/net/dns/dns_query.cc index 3cfb5cd..408b302 100644 --- a/net/dns/dns_query.cc +++ b/net/dns/dns_query.cc @@ -6,10 +6,10 @@ #include <limits> +#include "base/sys_byteorder.h" #include "net/base/big_endian.h" #include "net/base/dns_util.h" #include "net/base/io_buffer.h" -#include "net/base/sys_byteorder.h" #include "net/dns/dns_protocol.h" namespace net { diff --git a/net/dns/dns_response.cc b/net/dns/dns_response.cc index 9e6db79..dabfc6a 100644 --- a/net/dns/dns_response.cc +++ b/net/dns/dns_response.cc @@ -4,10 +4,10 @@ #include "net/dns/dns_response.h" +#include "base/sys_byteorder.h" #include "net/base/big_endian.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" -#include "net/base/sys_byteorder.h" #include "net/dns/dns_protocol.h" #include "net/dns/dns_query.h" diff --git a/net/net.gyp b/net/net.gyp index d6c510c..54aee3e 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -228,7 +228,6 @@ 'base/static_cookie_policy.cc', 'base/static_cookie_policy.h', 'base/sys_addrinfo.h', - 'base/sys_byteorder.h', 'base/test_data_stream.cc', 'base/test_data_stream.h', 'base/test_root_certs.cc', diff --git a/net/server/http_server.cc b/net/server/http_server.cc index 6f2a46b..f56ff96 100644 --- a/net/server/http_server.cc +++ b/net/server/http_server.cc @@ -8,17 +8,12 @@ #include "base/logging.h" #include "base/string_util.h" #include "base/stringprintf.h" +#include "base/sys_byteorder.h" #include "build/build_config.h" #include "net/server/http_connection.h" #include "net/server/http_server_request_info.h" #include "net/server/web_socket.h" -#if defined(OS_WIN) -#include <winsock2.h> -#else -#include <arpa/inet.h> -#endif - namespace net { HttpServer::HttpServer(const std::string& host, diff --git a/net/server/web_socket.cc b/net/server/web_socket.cc index 7360c25..0abbcf7 100644 --- a/net/server/web_socket.cc +++ b/net/server/web_socket.cc @@ -4,6 +4,8 @@ #include "net/server/web_socket.h" +#include <limits> + #include "base/base64.h" #include "base/rand_util.h" #include "base/logging.h" @@ -11,17 +13,10 @@ #include "base/sha1.h" #include "base/string_number_conversions.h" #include "base/stringprintf.h" +#include "base/sys_byteorder.h" #include "net/server/http_connection.h" #include "net/server/http_server_request_info.h" -#if defined(OS_WIN) -#include <winsock2.h> -#else -#include <arpa/inet.h> -#endif - -#include <limits> - namespace net { namespace { diff --git a/net/socket/web_socket_server_socket.cc b/net/socket/web_socket_server_socket.cc index b86ac32..add4a55 100644 --- a/net/socket/web_socket_server_socket.cc +++ b/net/socket/web_socket_server_socket.cc @@ -10,12 +10,6 @@ #include <map> #include <vector> -#if defined(OS_WIN) -#include <winsock2.h> // for htonl -#else -#include <arpa/inet.h> -#endif - #include "base/basictypes.h" #include "base/bind.h" #include "base/bind_helpers.h" @@ -26,6 +20,7 @@ #include "base/memory/weak_ptr.h" #include "base/message_loop.h" #include "base/string_util.h" +#include "base/sys_byteorder.h" #include "googleurl/src/gurl.h" #include "net/base/completion_callback.h" #include "net/base/io_buffer.h" diff --git a/net/spdy/spdy_frame_builder.h b/net/spdy/spdy_frame_builder.h index e828a88..403e819 100644 --- a/net/spdy/spdy_frame_builder.h +++ b/net/spdy/spdy_frame_builder.h @@ -9,8 +9,8 @@ #include <string> #include "base/basictypes.h" +#include "base/sys_byteorder.h" #include "net/base/net_export.h" -#include "net/base/sys_byteorder.h" #include "net/spdy/spdy_protocol.h" namespace spdy { diff --git a/net/spdy/spdy_framer.h b/net/spdy/spdy_framer.h index 1d4b000e..3e16502 100644 --- a/net/spdy/spdy_framer.h +++ b/net/spdy/spdy_framer.h @@ -15,8 +15,8 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" +#include "base/sys_byteorder.h" #include "net/base/net_export.h" -#include "net/base/sys_byteorder.h" #include "net/spdy/spdy_protocol.h" typedef struct z_stream_s z_stream; // Forward declaration for zlib. diff --git a/net/spdy/spdy_protocol.h b/net/spdy/spdy_protocol.h index 21c1d97..fa489b8 100644 --- a/net/spdy/spdy_protocol.h +++ b/net/spdy/spdy_protocol.h @@ -12,7 +12,7 @@ #include "base/basictypes.h" #include "base/logging.h" -#include "net/base/sys_byteorder.h" +#include "base/sys_byteorder.h" #include "net/spdy/spdy_bitmasks.h" // Data Frame Format diff --git a/ppapi/shared_impl/private/net_address_private_impl.cc b/ppapi/shared_impl/private/net_address_private_impl.cc index 3b9a4ae..0c43a2f 100644 --- a/ppapi/shared_impl/private/net_address_private_impl.cc +++ b/ppapi/shared_impl/private/net_address_private_impl.cc @@ -11,12 +11,12 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/stringprintf.h" +#include "base/sys_byteorder.h" #include "build/build_config.h" #include "net/base/address_list.h" #include "net/base/ip_endpoint.h" #include "net/base/net_util.h" #include "net/base/sys_addrinfo.h" -#include "net/base/sys_byteorder.h" #include "ppapi/c/pp_var.h" #include "ppapi/c/private/ppb_net_address_private.h" #include "ppapi/shared_impl/var.h" |