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

Unified Diff: net/base/net_util.cc

Issue 9716020: Add base::HostToNetXX() & NetToHostXX(), and use them to replace htonX() & ntohX() in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/listen_socket_unittest.cc ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util.cc
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 21fb07f0a4b9a53f7da3d2b161cf744f1ea8be0f..29b83a8a4ca8a667dc780adb69544f15d838ac22 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -76,14 +76,6 @@
using base::Time;
-#if defined(OS_WIN)
-// Allow htons/ntohs to be called without requiring ws2_32.dll to be loaded,
-// which isn't available in Chrome's sandbox. See crbug.com/116591.
-// TODO(wez): Replace these calls with base::htons() etc when available.
-#define ntohs(x) _byteswap_ushort(x)
-#define htons(x) _byteswap_ushort(x)
-#endif // OS_WIN
-
namespace net {
namespace {
@@ -2344,7 +2336,7 @@ uint16 GetPortFromAddrinfo(const struct addrinfo* info) {
const uint16* port_field = GetPortFieldFromAddrinfo(info);
if (!port_field)
return -1;
- return ntohs(*port_field);
+ return base::NetToHost16(*port_field);
}
const uint16* GetPortFieldFromSockaddr(const struct sockaddr* address,
@@ -2369,7 +2361,7 @@ int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) {
const uint16* port_field = GetPortFieldFromSockaddr(address, address_len);
if (!port_field)
return -1;
- return ntohs(*port_field);
+ return base::NetToHost16(*port_field);
}
// Assign |port| to each address in the linked list starting from |head|.
@@ -2378,7 +2370,7 @@ void SetPortForAllAddrinfos(struct addrinfo* head, uint16 port) {
for (struct addrinfo* ai = head; ai; ai = ai->ai_next) {
uint16* port_field = GetPortFieldFromAddrinfo(ai);
if (port_field)
- *port_field = htons(port);
+ *port_field = base::HostToNet16(port);
}
}
« no previous file with comments | « net/base/listen_socket_unittest.cc ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698