Add base::HostToNetXX() & NetToHostXX(), and use them to replace htonX() & ntohX() in Chrome.
This primarily addresses issues with code using the OS-provided htonX() & ntohX() functions from within the Chrome sandbox. Under Windows these functions are provided by ws2_32.dll, which is no longer available within Chrome's sandbox. The new base::HostToNetXX() and NetToHostXX() functions are safe for use by sandboxed code on Windows, and provide a single place where future fixes for other platforms can be made. BUG=117252 Review URL: http://codereview.chromium.org/9716020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129476 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
base
chrome
content/browser/renderer_host/p2p
crypto
jingle/notifier/base
native_client_sdk/src/build_tools/debug_server/debug_stub
net
base
host_resolver_proc.ccip_endpoint.cclisten_socket.cclisten_socket_unittest.ccnet_util.ccnet_util_unittest.cc
dns
dns_config_service_posix_unittest.ccdns_query.ccdns_response.ccdns_test_util.ccdns_transaction_unittest.cc
server
socket
ppapi/shared_impl/private
sync/util
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -37,6 +37,28 @@
|
||||
namespace base {
|
||||
|
||||
// Returns a value with all bytes in |x| swapped, i.e. reverses the endianness.
|
||||
inline uint16 ByteSwap(uint16 x) {
|
||||
#if defined(COMPILER_MSVC)
|
||||
return _byteswap_ushort(x);
|
||||
#elif defined(OS_MACOSX)
|
||||
return OSSwapInt16(x);
|
||||
#elif defined(OS_OPENBSD)
|
||||
return swap16(x);
|
||||
#else
|
||||
return bswap_16(x);
|
||||
#endif
|
||||
}
|
||||
inline uint32 ByteSwap(uint32 x) {
|
||||
#if defined(COMPILER_MSVC)
|
||||
return _byteswap_ulong(x);
|
||||
#elif defined(OS_MACOSX)
|
||||
return OSSwapInt32(x);
|
||||
#elif defined(OS_OPENBSD)
|
||||
return swap32(x);
|
||||
#else
|
||||
return bswap_32(x);
|
||||
#endif
|
||||
}
|
||||
inline uint64 ByteSwap(uint64 x) {
|
||||
#if defined(COMPILER_MSVC)
|
||||
return _byteswap_uint64(x);
|
||||
@ -51,7 +73,21 @@ inline uint64 ByteSwap(uint64 x) {
|
||||
|
||||
// Converts the bytes in |x| from network to host order (endianness), and
|
||||
// returns the result.
|
||||
inline uint64 ntohll(uint64 x) {
|
||||
inline uint16 NetToHost16(uint16 x) {
|
||||
#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
||||
return ByteSwap(x);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
}
|
||||
inline uint32 NetToHost32(uint32 x) {
|
||||
#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
||||
return ByteSwap(x);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
}
|
||||
inline uint64 NetToHost64(uint64 x) {
|
||||
#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
||||
return ByteSwap(x);
|
||||
#else
|
||||
@ -61,7 +97,21 @@ inline uint64 ntohll(uint64 x) {
|
||||
|
||||
// Converts the bytes in |x| from host to network order (endianness), and
|
||||
// returns the result.
|
||||
inline uint64 htonll(uint64 x) {
|
||||
inline uint16 HostToNet16(uint16 x) {
|
||||
#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
||||
return ByteSwap(x);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
}
|
||||
inline uint32 HostToNet32(uint32 x) {
|
||||
#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
||||
return ByteSwap(x);
|
||||
#else
|
||||
return x;
|
||||
#endif
|
||||
}
|
||||
inline uint64 HostToNet64(uint64 x) {
|
||||
#if defined(ARCH_CPU_LITTLE_ENDIAN)
|
||||
return ByteSwap(x);
|
||||
#else
|
||||
|
@ -841,8 +841,9 @@ void Serv::Run() {
|
||||
struct sockaddr_in addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(0); // let OS allocatate ephemeral port number.
|
||||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
// Let the OS allocate a port number.
|
||||
addr.sin_port = base::HostToNet16(0);
|
||||
addr.sin_addr.s_addr = base::HostToNet32(INADDR_LOOPBACK);
|
||||
if (bind(listening_sock_,
|
||||
reinterpret_cast<struct sockaddr*>(&addr),
|
||||
sizeof(addr))) {
|
||||
@ -883,8 +884,8 @@ void Serv::Run() {
|
||||
const int kPort = 10101;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(kPort);
|
||||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
addr.sin_port = base::HostToNet16(kPort);
|
||||
addr.sin_addr.s_addr = base::HostToNet32(INADDR_LOOPBACK);
|
||||
if (bind(extra_listening_sock_,
|
||||
reinterpret_cast<struct sockaddr*>(&addr),
|
||||
sizeof(addr))) {
|
||||
@ -934,7 +935,7 @@ void Serv::Run() {
|
||||
}
|
||||
BrowserThread::PostTask(
|
||||
BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&SendNotification, ntohs(addr.sin_port)));
|
||||
base::Bind(&SendNotification, base::NetToHost16(addr.sin_port)));
|
||||
|
||||
LOG(INFO) << "WebSocketProxy: Starting event dispatch loop.";
|
||||
event_base_dispatch(evbase_);
|
||||
@ -1574,7 +1575,7 @@ void Conn::OnPrimchanRead(struct bufferevent* bev, EventKey evkey) {
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sin_port = htons(cs->destport_);
|
||||
sa.sin_port = base::HostToNet16(cs->destport_);
|
||||
if (inet_pton(sa.sin_family = AF_INET,
|
||||
cs->destaddr_.c_str(),
|
||||
&sa.sin_addr) == 1) {
|
||||
@ -1595,7 +1596,7 @@ void Conn::OnPrimchanRead(struct bufferevent* bev, EventKey evkey) {
|
||||
}
|
||||
struct sockaddr_in6 sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sin6_port = htons(cs->destport_);
|
||||
sa.sin6_port = base::HostToNet16(cs->destport_);
|
||||
if (inet_pton(sa.sin6_family = AF_INET6,
|
||||
cs->destaddr_.c_str(),
|
||||
&sa.sin6_addr) == 1) {
|
||||
@ -1754,7 +1755,7 @@ void Conn::OnDestResolutionIPv4(int result, char type,
|
||||
struct sockaddr_in sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = htons(cs->destport_);
|
||||
sa.sin_port = base::HostToNet16(cs->destport_);
|
||||
DCHECK(sizeof(sa.sin_addr) == sizeof(struct in_addr));
|
||||
memcpy(&sa.sin_addr,
|
||||
static_cast<struct in_addr*>(addr_list) + i,
|
||||
@ -1785,7 +1786,7 @@ void Conn::OnDestResolutionIPv6(int result, char type,
|
||||
struct sockaddr_in6 sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sin6_family = AF_INET6;
|
||||
sa.sin6_port = htons(cs->destport_);
|
||||
sa.sin6_port = base::HostToNet16(cs->destport_);
|
||||
DCHECK(sizeof(sa.sin6_addr) == sizeof(struct in6_addr));
|
||||
memcpy(&sa.sin6_addr,
|
||||
static_cast<struct in6_addr*>(addr_list) + i,
|
||||
|
@ -452,7 +452,7 @@ bool SafeBrowsingProtocolParser::ReadChunkId(
|
||||
memcpy(chunk_id, *data, sizeof(*chunk_id));
|
||||
*data += sizeof(*chunk_id);
|
||||
*remaining -= sizeof(*chunk_id);
|
||||
*chunk_id = htonl(*chunk_id);
|
||||
*chunk_id = base::HostToNet32(*chunk_id);
|
||||
DCHECK_GE(*remaining, 0);
|
||||
return true;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ inline uint64 HashToUInt64(const std::string& hash) {
|
||||
uint64 value;
|
||||
DCHECK_GE(hash.size(), sizeof(value));
|
||||
memcpy(&value, hash.data(), sizeof(value));
|
||||
return base::htonll(value);
|
||||
return base::HostToNet64(value);
|
||||
}
|
||||
|
||||
// Creates an MD5 hash of the given value, and returns hash as a byte buffer
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -34,15 +34,15 @@ bool P2PSocketHost::GetStunPacketType(
|
||||
if (data_size < kStunHeaderSize)
|
||||
return false;
|
||||
|
||||
uint32 cookie = ntohl(*reinterpret_cast<const uint32*>(data + 4));
|
||||
uint32 cookie = base::NetToHost32(*reinterpret_cast<const uint32*>(data + 4));
|
||||
if (cookie != kStunMagicCookie)
|
||||
return false;
|
||||
|
||||
uint16 length = ntohs(*reinterpret_cast<const uint16*>(data + 2));
|
||||
uint16 length = base::NetToHost16(*reinterpret_cast<const uint16*>(data + 2));
|
||||
if (length != data_size - kStunHeaderSize)
|
||||
return false;
|
||||
|
||||
int message_type = ntohs(*reinterpret_cast<const uint16*>(data));
|
||||
int message_type = base::NetToHost16(*reinterpret_cast<const uint16*>(data));
|
||||
|
||||
// Verify that the type is known:
|
||||
switch (message_type) {
|
||||
|
@ -168,8 +168,8 @@ void P2PSocketHostTcp::DidCompleteRead(int result) {
|
||||
|
||||
read_buffer_->set_offset(read_buffer_->offset() + result);
|
||||
if (read_buffer_->offset() > kPacketHeaderSize) {
|
||||
int packet_size =
|
||||
ntohs(*reinterpret_cast<uint16*>(read_buffer_->StartOfBuffer()));
|
||||
int packet_size = base::NetToHost16(
|
||||
*reinterpret_cast<uint16*>(read_buffer_->StartOfBuffer()));
|
||||
if (packet_size + kPacketHeaderSize <= read_buffer_->offset()) {
|
||||
// We've got a full packet!
|
||||
char* start = read_buffer_->StartOfBuffer() + kPacketHeaderSize;
|
||||
@ -221,7 +221,8 @@ void P2PSocketHostTcp::Send(const net::IPEndPoint& to,
|
||||
|
||||
int size = kPacketHeaderSize + data.size();
|
||||
write_buffer_ = new net::DrainableIOBuffer(new net::IOBuffer(size), size);
|
||||
*reinterpret_cast<uint16*>(write_buffer_->data()) = htons(data.size());
|
||||
*reinterpret_cast<uint16*>(write_buffer_->data()) =
|
||||
base::HostToNet16(data.size());
|
||||
memcpy(write_buffer_->data() + kPacketHeaderSize, &data[0], data.size());
|
||||
|
||||
DoWrite();
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -42,7 +42,7 @@ class P2PSocketHostTcpTest : public testing::Test {
|
||||
|
||||
std::string IntToSize(int size) {
|
||||
std::string result;
|
||||
uint16 size16 = htons(size);
|
||||
uint16 size16 = base::HostToNet16(size);
|
||||
result.resize(sizeof(size16));
|
||||
memcpy(&result[0], &size16, sizeof(size16));
|
||||
return result;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -232,10 +232,11 @@ void CreateRandomPacket(std::vector<char>* packet) {
|
||||
|
||||
void CreateStunPacket(std::vector<char>* packet, uint16 type) {
|
||||
CreateRandomPacket(packet);
|
||||
*reinterpret_cast<uint16*>(&*packet->begin()) = htons(type);
|
||||
*reinterpret_cast<uint16*>(&*packet->begin()) = base::HostToNet16(type);
|
||||
*reinterpret_cast<uint16*>(&*packet->begin() + 2) =
|
||||
htons(packet->size() - kStunHeaderSize);
|
||||
*reinterpret_cast<uint32*>(&*packet->begin() + 4) = htonl(kStunMagicCookie);
|
||||
base::HostToNet16(packet->size() - kStunHeaderSize);
|
||||
*reinterpret_cast<uint32*>(&*packet->begin() + 4) =
|
||||
base::HostToNet32(kStunMagicCookie);
|
||||
}
|
||||
|
||||
void CreateStunRequest(std::vector<char>* packet) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -21,14 +21,14 @@ Encryptor::Counter::~Counter() {
|
||||
}
|
||||
|
||||
bool Encryptor::Counter::Increment() {
|
||||
uint64 low_num = base::ntohll(counter_.components64[1]);
|
||||
uint64 low_num = base::NetToHost64(counter_.components64[1]);
|
||||
uint64 new_low_num = low_num + 1;
|
||||
counter_.components64[1] = base::htonll(new_low_num);
|
||||
counter_.components64[1] = base::HostToNet64(new_low_num);
|
||||
|
||||
// If overflow occured then increment the most significant component.
|
||||
if (new_low_num < low_num) {
|
||||
counter_.components64[0] =
|
||||
base::htonll(base::ntohll(counter_.components64[0]) + 1);
|
||||
base::HostToNet64(base::NetToHost64(counter_.components64[0]) + 1);
|
||||
}
|
||||
|
||||
// TODO(hclam): Return false if counter value overflows.
|
||||
|
@ -13,16 +13,11 @@
|
||||
|
||||
#include "base/sys_byteorder.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Allow htonl/ntohl 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::htonl() etc when available.
|
||||
#define ntohl(x) _byteswap_ulong(x)
|
||||
#define htonl(x) _byteswap_ulong(x)
|
||||
#endif // OS_WIN
|
||||
|
||||
namespace {
|
||||
|
||||
using base::HostToNet32;
|
||||
using base::NetToHost32;
|
||||
|
||||
// Field element functions.
|
||||
//
|
||||
// The field that we're dealing with is ℤ/pℤ where p = 2**224 - 2**96 + 1.
|
||||
@ -564,27 +559,33 @@ void ScalarMult(Point* out, const Point& a,
|
||||
// Get224Bits reads 7 words from in and scatters their contents in
|
||||
// little-endian form into 8 words at out, 28 bits per output word.
|
||||
void Get224Bits(uint32* out, const uint32* in) {
|
||||
out[0] = ntohl(in[6]) & kBottom28Bits;
|
||||
out[1] = ((ntohl(in[5]) << 4) | (ntohl(in[6]) >> 28)) & kBottom28Bits;
|
||||
out[2] = ((ntohl(in[4]) << 8) | (ntohl(in[5]) >> 24)) & kBottom28Bits;
|
||||
out[3] = ((ntohl(in[3]) << 12) | (ntohl(in[4]) >> 20)) & kBottom28Bits;
|
||||
out[4] = ((ntohl(in[2]) << 16) | (ntohl(in[3]) >> 16)) & kBottom28Bits;
|
||||
out[5] = ((ntohl(in[1]) << 20) | (ntohl(in[2]) >> 12)) & kBottom28Bits;
|
||||
out[6] = ((ntohl(in[0]) << 24) | (ntohl(in[1]) >> 8)) & kBottom28Bits;
|
||||
out[7] = (ntohl(in[0]) >> 4) & kBottom28Bits;
|
||||
out[0] = NetToHost32(in[6]) & kBottom28Bits;
|
||||
out[1] = ((NetToHost32(in[5]) << 4) |
|
||||
(NetToHost32(in[6]) >> 28)) & kBottom28Bits;
|
||||
out[2] = ((NetToHost32(in[4]) << 8) |
|
||||
(NetToHost32(in[5]) >> 24)) & kBottom28Bits;
|
||||
out[3] = ((NetToHost32(in[3]) << 12) |
|
||||
(NetToHost32(in[4]) >> 20)) & kBottom28Bits;
|
||||
out[4] = ((NetToHost32(in[2]) << 16) |
|
||||
(NetToHost32(in[3]) >> 16)) & kBottom28Bits;
|
||||
out[5] = ((NetToHost32(in[1]) << 20) |
|
||||
(NetToHost32(in[2]) >> 12)) & kBottom28Bits;
|
||||
out[6] = ((NetToHost32(in[0]) << 24) |
|
||||
(NetToHost32(in[1]) >> 8)) & kBottom28Bits;
|
||||
out[7] = (NetToHost32(in[0]) >> 4) & kBottom28Bits;
|
||||
}
|
||||
|
||||
// Put224Bits performs the inverse operation to Get224Bits: taking 28 bits from
|
||||
// each of 8 input words and writing them in big-endian order to 7 words at
|
||||
// out.
|
||||
void Put224Bits(uint32* out, const uint32* in) {
|
||||
out[6] = htonl((in[0] >> 0) | (in[1] << 28));
|
||||
out[5] = htonl((in[1] >> 4) | (in[2] << 24));
|
||||
out[4] = htonl((in[2] >> 8) | (in[3] << 20));
|
||||
out[3] = htonl((in[3] >> 12) | (in[4] << 16));
|
||||
out[2] = htonl((in[4] >> 16) | (in[5] << 12));
|
||||
out[1] = htonl((in[5] >> 20) | (in[6] << 8));
|
||||
out[0] = htonl((in[6] >> 24) | (in[7] << 4));
|
||||
out[6] = HostToNet32((in[0] >> 0) | (in[1] << 28));
|
||||
out[5] = HostToNet32((in[1] >> 4) | (in[2] << 24));
|
||||
out[4] = HostToNet32((in[2] >> 8) | (in[3] << 20));
|
||||
out[3] = HostToNet32((in[3] >> 12) | (in[4] << 16));
|
||||
out[2] = HostToNet32((in[4] >> 16) | (in[5] << 12));
|
||||
out[1] = HostToNet32((in[5] >> 20) | (in[6] << 8));
|
||||
out[0] = HostToNet32((in[6] >> 24) | (in[7] << 4));
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
@ -4,12 +4,11 @@
|
||||
|
||||
#include "crypto/symmetric_key.h"
|
||||
|
||||
#include <winsock2.h> // For htonl.
|
||||
|
||||
#include <vector>
|
||||
|
||||
// TODO(wtc): replace scoped_array by std::vector.
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/sys_byteorder.h"
|
||||
|
||||
namespace crypto {
|
||||
|
||||
@ -264,7 +263,7 @@ bool ComputePBKDF2Block(HCRYPTHASH hash,
|
||||
return false;
|
||||
|
||||
// Iteration U_1: and append (big-endian) INT (i).
|
||||
uint32 big_endian_block_index = htonl(block_index);
|
||||
uint32 big_endian_block_index = base::HostToNet32(block_index);
|
||||
ok = CryptHashData(safe_hash,
|
||||
reinterpret_cast<BYTE*>(&big_endian_block_index),
|
||||
sizeof(big_endian_block_index), 0);
|
||||
|
@ -101,7 +101,7 @@ class AsyncSocketDataProvider : public net::SocketDataProvider {
|
||||
// Takes a 32-bit integer in host byte order and converts it to a
|
||||
// net::IPAddressNumber.
|
||||
net::IPAddressNumber Uint32ToIPAddressNumber(uint32 ip) {
|
||||
uint32 ip_nbo = htonl(ip);
|
||||
uint32 ip_nbo = base::HostToNet32(ip);
|
||||
const unsigned char* const ip_start =
|
||||
reinterpret_cast<const unsigned char*>(&ip_nbo);
|
||||
return net::IPAddressNumber(ip_start, ip_start + (sizeof ip_nbo));
|
||||
|
@ -291,4 +291,3 @@ void ITransport::Free(ITransport* itrans) {
|
||||
}
|
||||
|
||||
} // namespace port
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include "build/build_config.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/sys_byteorder.h"
|
||||
#include "net/base/address_list.h"
|
||||
#include "net/base/dns_reloader.h"
|
||||
#include "net/base/net_errors.h"
|
||||
@ -28,7 +29,8 @@ bool IsAllLocalhostOfOneFamily(const struct addrinfo* ai) {
|
||||
case AF_INET: {
|
||||
const struct sockaddr_in* addr_in =
|
||||
reinterpret_cast<struct sockaddr_in*>(ai->ai_addr);
|
||||
if ((ntohl(addr_in->sin_addr.s_addr) & 0xff000000) == 0x7f000000)
|
||||
if ((base::NetToHost32(addr_in->sin_addr.s_addr) & 0xff000000) ==
|
||||
0x7f000000)
|
||||
saw_v4_localhost = true;
|
||||
else
|
||||
return false;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/string_number_conversions.h"
|
||||
#include "base/sys_byteorder.h"
|
||||
#if defined(OS_WIN)
|
||||
#include <winsock2.h>
|
||||
#elif defined(OS_POSIX)
|
||||
@ -54,7 +55,7 @@ bool IPEndPoint::ToSockAddr(struct sockaddr* address,
|
||||
struct sockaddr_in* addr = reinterpret_cast<struct sockaddr_in*>(address);
|
||||
memset(addr, 0, sizeof(struct sockaddr_in));
|
||||
addr->sin_family = AF_INET;
|
||||
addr->sin_port = htons(port_);
|
||||
addr->sin_port = base::HostToNet16(port_);
|
||||
memcpy(&addr->sin_addr, &address_[0], kIPv4AddressSize);
|
||||
break;
|
||||
}
|
||||
@ -66,7 +67,7 @@ bool IPEndPoint::ToSockAddr(struct sockaddr* address,
|
||||
reinterpret_cast<struct sockaddr_in6*>(address);
|
||||
memset(addr6, 0, sizeof(struct sockaddr_in6));
|
||||
addr6->sin6_family = AF_INET6;
|
||||
addr6->sin6_port = htons(port_);
|
||||
addr6->sin6_port = base::HostToNet16(port_);
|
||||
memcpy(&addr6->sin6_addr, &address_[0], kIPv6AddressSize);
|
||||
break;
|
||||
}
|
||||
@ -87,7 +88,7 @@ bool IPEndPoint::FromSockAddr(const struct sockaddr* address,
|
||||
return false;
|
||||
const struct sockaddr_in* addr =
|
||||
reinterpret_cast<const struct sockaddr_in*>(address);
|
||||
port_ = ntohs(addr->sin_port);
|
||||
port_ = base::NetToHost16(addr->sin_port);
|
||||
const char* bytes = reinterpret_cast<const char*>(&addr->sin_addr);
|
||||
address_.assign(&bytes[0], &bytes[kIPv4AddressSize]);
|
||||
break;
|
||||
@ -97,7 +98,7 @@ bool IPEndPoint::FromSockAddr(const struct sockaddr* address,
|
||||
return false;
|
||||
const struct sockaddr_in6* addr =
|
||||
reinterpret_cast<const struct sockaddr_in6*>(address);
|
||||
port_ = ntohs(addr->sin6_port);
|
||||
port_ = base::NetToHost16(addr->sin6_port);
|
||||
const char* bytes = reinterpret_cast<const char*>(&addr->sin6_addr);
|
||||
address_.assign(&bytes[0], &bytes[kIPv6AddressSize]);
|
||||
break;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
#endif
|
||||
|
||||
#include "base/eintr_wrapper.h"
|
||||
#include "base/sys_byteorder.h"
|
||||
#include "base/threading/platform_thread.h"
|
||||
#include "net/base/net_util.h"
|
||||
#include "net/base/listen_socket.h"
|
||||
@ -116,7 +117,7 @@ SOCKET ListenSocket::Listen(std::string ip, int port) {
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = inet_addr(ip.c_str());
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_port = base::HostToNet16(port);
|
||||
if (bind(s, reinterpret_cast<sockaddr*>(&addr), sizeof(addr))) {
|
||||
#if defined(OS_WIN)
|
||||
closesocket(s);
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/eintr_wrapper.h"
|
||||
#include "base/sys_byteorder.h"
|
||||
#include "net/base/net_util.h"
|
||||
#include "testing/platform_test.h"
|
||||
|
||||
@ -50,7 +51,7 @@ void ListenSocketTester::SetUp() {
|
||||
struct sockaddr_in client;
|
||||
client.sin_family = AF_INET;
|
||||
client.sin_addr.s_addr = inet_addr(kLoopback);
|
||||
client.sin_port = htons(kTestPort);
|
||||
client.sin_port = base::HostToNet16(kTestPort);
|
||||
int ret = HANDLE_EINTR(
|
||||
connect(test_socket_, reinterpret_cast<sockaddr*>(&client),
|
||||
sizeof(client)));
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "base/string_number_conversions.h"
|
||||
#include "base/string_util.h"
|
||||
#include "base/stringprintf.h"
|
||||
#include "base/sys_byteorder.h"
|
||||
#include "base/sys_string_conversions.h"
|
||||
#include "base/test/test_file_util.h"
|
||||
#include "base/time.h"
|
||||
@ -420,7 +421,7 @@ const struct addrinfo* GetIPv4Address(const uint8* bytes, int port) {
|
||||
|
||||
struct sockaddr_in* addr4 = &static_addr4;
|
||||
memset(addr4, 0, sizeof(static_addr4));
|
||||
addr4->sin_port = htons(port);
|
||||
addr4->sin_port = base::HostToNet16(port);
|
||||
addr4->sin_family = ai->ai_family;
|
||||
memcpy(&addr4->sin_addr, bytes, 4);
|
||||
|
||||
@ -444,7 +445,7 @@ const struct addrinfo* GetIPv6Address(const uint8* bytes, int port) {
|
||||
|
||||
struct sockaddr_in6* addr6 = &static_addr6;
|
||||
memset(addr6, 0, sizeof(static_addr6));
|
||||
addr6->sin6_port = htons(port);
|
||||
addr6->sin6_port = base::HostToNet16(port);
|
||||
addr6->sin6_family = ai->ai_family;
|
||||
memcpy(&addr6->sin6_addr, bytes, 16);
|
||||
|
||||
|
@ -73,7 +73,7 @@ void InitializeResState(res_state res, unsigned generation) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
struct sockaddr_in sa;
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = htons(NS_DEFAULTPORT + i - generation);
|
||||
sa.sin_port = base::HostToNet16(NS_DEFAULTPORT + i - generation);
|
||||
inet_pton(AF_INET, ip4addr[i], &sa.sin_addr);
|
||||
res->nsaddr_list[i] = sa;
|
||||
}
|
||||
@ -90,7 +90,7 @@ void InitializeResState(res_state res, unsigned generation) {
|
||||
struct sockaddr_in6 *sa6;
|
||||
sa6 = (struct sockaddr_in6 *)malloc(sizeof(*sa6));
|
||||
sa6->sin6_family = AF_INET6;
|
||||
sa6->sin6_port = htons(NS_DEFAULTPORT - i);
|
||||
sa6->sin6_port = base::HostToNet16(NS_DEFAULTPORT - i);
|
||||
inet_pton(AF_INET6, ip6addr[i], &sa6->sin6_addr);
|
||||
res->_u._ext.nsaddrs[i] = sa6;
|
||||
}
|
||||
@ -127,5 +127,3 @@ TEST(DnsConfigServicePosixTest, ConvertResStateToDnsConfig) {
|
||||
|
||||
} // namespace
|
||||
} // namespace net
|
||||
|
||||
|
||||
|
@ -28,9 +28,9 @@ DnsQuery::DnsQuery(uint16 id, const base::StringPiece& qname, uint16 qtype)
|
||||
dns_protocol::Header* header =
|
||||
reinterpret_cast<dns_protocol::Header*>(io_buffer_->data());
|
||||
memset(header, 0, sizeof(dns_protocol::Header));
|
||||
header->id = htons(id);
|
||||
header->flags = htons(dns_protocol::kFlagRD);
|
||||
header->qdcount = htons(1);
|
||||
header->id = base::HostToNet16(id);
|
||||
header->flags = base::HostToNet16(dns_protocol::kFlagRD);
|
||||
header->qdcount = base::HostToNet16(1);
|
||||
|
||||
// Write question section after the header.
|
||||
BigEndianWriter writer(reinterpret_cast<char*>(header + 1), question_size);
|
||||
@ -49,7 +49,7 @@ DnsQuery* DnsQuery::CloneWithNewId(uint16 id) const {
|
||||
uint16 DnsQuery::id() const {
|
||||
const dns_protocol::Header* header =
|
||||
reinterpret_cast<const dns_protocol::Header*>(io_buffer_->data());
|
||||
return ntohs(header->id);
|
||||
return base::NetToHost16(header->id);
|
||||
}
|
||||
|
||||
base::StringPiece DnsQuery::qname() const {
|
||||
@ -77,7 +77,7 @@ DnsQuery::DnsQuery(const DnsQuery& orig, uint16 id) {
|
||||
io_buffer_.get()->size());
|
||||
dns_protocol::Header* header =
|
||||
reinterpret_cast<dns_protocol::Header*>(io_buffer_->data());
|
||||
header->id = htons(id);
|
||||
header->id = base::HostToNet16(id);
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
|
@ -149,11 +149,11 @@ bool DnsResponse::InitParse(int nbytes, const DnsQuery& query) {
|
||||
return false;
|
||||
|
||||
// Match the query id.
|
||||
if (ntohs(header()->id) != query.id())
|
||||
if (base::NetToHost16(header()->id) != query.id())
|
||||
return false;
|
||||
|
||||
// Match question count.
|
||||
if (ntohs(header()->qdcount) != 1)
|
||||
if (base::NetToHost16(header()->qdcount) != 1)
|
||||
return false;
|
||||
|
||||
// Match the question section.
|
||||
@ -177,17 +177,17 @@ bool DnsResponse::IsValid() const {
|
||||
|
||||
uint16 DnsResponse::flags() const {
|
||||
DCHECK(parser_.IsValid());
|
||||
return ntohs(header()->flags) & ~(dns_protocol::kRcodeMask);
|
||||
return base::NetToHost16(header()->flags) & ~(dns_protocol::kRcodeMask);
|
||||
}
|
||||
|
||||
uint8 DnsResponse::rcode() const {
|
||||
DCHECK(parser_.IsValid());
|
||||
return ntohs(header()->flags) & dns_protocol::kRcodeMask;
|
||||
return base::NetToHost16(header()->flags) & dns_protocol::kRcodeMask;
|
||||
}
|
||||
|
||||
unsigned DnsResponse::answer_count() const {
|
||||
DCHECK(parser_.IsValid());
|
||||
return ntohs(header()->ancount);
|
||||
return base::NetToHost16(header()->ancount);
|
||||
}
|
||||
|
||||
base::StringPiece DnsResponse::qname() const {
|
||||
|
@ -86,7 +86,8 @@ class MockTransaction : public DnsTransaction,
|
||||
size_t answer_size = 12 + rdata_size;
|
||||
|
||||
// Write answer with loopback IP address.
|
||||
reinterpret_cast<dns_protocol::Header*>(buffer)->ancount = htons(1);
|
||||
reinterpret_cast<dns_protocol::Header*>(buffer)->ancount =
|
||||
base::HostToNet16(1);
|
||||
BigEndianWriter writer(buffer + nbytes, answer_size);
|
||||
writer.WriteU16(kPointerToQueryName);
|
||||
writer.WriteU16(qtype_);
|
||||
@ -167,4 +168,3 @@ void MockDnsConfigService::Watch(const CallbackType& callback) {
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/scoped_vector.h"
|
||||
#include "base/rand_util.h"
|
||||
#include "base/sys_byteorder.h"
|
||||
#include "base/test/test_timeouts.h"
|
||||
#include "net/base/big_endian.h"
|
||||
#include "net/base/dns_util.h"
|
||||
@ -279,7 +280,7 @@ class DnsTransactionTest : public testing::Test {
|
||||
0);
|
||||
dns_protocol::Header* header =
|
||||
reinterpret_cast<dns_protocol::Header*>(response->io_buffer()->data());
|
||||
header->flags |= htons(dns_protocol::kFlagResponse | rcode);
|
||||
header->flags |= base::HostToNet16(dns_protocol::kFlagResponse | rcode);
|
||||
responses_.push_back(response);
|
||||
|
||||
writes_.push_back(MockWrite(ASYNC,
|
||||
@ -715,4 +716,3 @@ TEST_F(DnsTransactionTest, SuffixSearchStop) {
|
||||
} // namespace
|
||||
|
||||
} // namespace net
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -37,7 +37,7 @@ static uint32 WebSocketKeyFingerprint(const std::string& str) {
|
||||
int64 number = 0;
|
||||
if (!base::StringToInt64(result, &number))
|
||||
return 0;
|
||||
return htonl(static_cast<uint32>(number / spaces));
|
||||
return base::HostToNet32(static_cast<uint32>(number / spaces));
|
||||
}
|
||||
|
||||
class WebSocketHixie76 : public net::WebSocket {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include "base/debug/trace_event.h"
|
||||
#include "base/format_macros.h"
|
||||
#include "base/string_util.h"
|
||||
#include "base/sys_byteorder.h"
|
||||
#include "net/base/io_buffer.h"
|
||||
#include "net/base/net_log.h"
|
||||
#include "net/base/net_util.h"
|
||||
@ -364,7 +365,7 @@ int SOCKS5ClientSocket::BuildHandshakeWriteBuffer(std::string* handshake)
|
||||
host_request_info_.hostname().size()));
|
||||
handshake->append(host_request_info_.hostname());
|
||||
|
||||
uint16 nw_port = htons(host_request_info_.port());
|
||||
uint16 nw_port = base::HostToNet16(host_request_info_.port());
|
||||
handshake->append(reinterpret_cast<char*>(&nw_port), sizeof(nw_port));
|
||||
return OK;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
#include "base/sys_byteorder.h"
|
||||
#include "net/base/address_list.h"
|
||||
#include "net/base/net_log.h"
|
||||
#include "net/base/net_log_unittest.h"
|
||||
@ -56,7 +57,7 @@ class SOCKS5ClientSocketTest : public PlatformTest {
|
||||
};
|
||||
|
||||
SOCKS5ClientSocketTest::SOCKS5ClientSocketTest()
|
||||
: kNwPort(htons(80)),
|
||||
: kNwPort(base::HostToNet16(80)),
|
||||
net_log_(CapturingNetLog::kUnbounded),
|
||||
host_resolver_(new MockHostResolver) {
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2012 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.
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include "base/basictypes.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/sys_byteorder.h"
|
||||
#include "net/base/io_buffer.h"
|
||||
#include "net/base/net_log.h"
|
||||
#include "net/base/net_util.h"
|
||||
@ -297,7 +298,7 @@ const std::string SOCKSClientSocket::BuildHandshakeWriteBuffer() const {
|
||||
SOCKS4ServerRequest request;
|
||||
request.version = kSOCKSVersion4;
|
||||
request.command = kSOCKSStreamRequest;
|
||||
request.nw_port = htons(host_request_info_.port());
|
||||
request.nw_port = base::HostToNet16(host_request_info_.port());
|
||||
|
||||
const struct addrinfo* ai = addresses_.head();
|
||||
DCHECK(ai);
|
||||
|
@ -689,8 +689,8 @@ class WebSocketServerSocketImpl : public net::WebSocketServerSocket {
|
||||
}
|
||||
|
||||
char challenge[4 + 4 + sizeof(key3)];
|
||||
int32 part1 = htonl(key_number1 / spaces1);
|
||||
int32 part2 = htonl(key_number2 / spaces2);
|
||||
int32 part1 = base::HostToNet32(key_number1 / spaces1);
|
||||
int32 part2 = base::HostToNet32(key_number2 / spaces2);
|
||||
memcpy(challenge, &part1, 4);
|
||||
memcpy(challenge + 4, &part2, 4);
|
||||
memcpy(challenge + 4 + 4, key3, sizeof(key3));
|
||||
|
@ -72,11 +72,11 @@ uint16_t GetPort(const PP_NetAddress_Private* addr) {
|
||||
switch (GetFamilyInternal(addr)) {
|
||||
case AF_INET: {
|
||||
const sockaddr_in* a = reinterpret_cast<const sockaddr_in*>(addr->data);
|
||||
return ntohs(a->sin_port);
|
||||
return base::NetToHost16(a->sin_port);
|
||||
}
|
||||
case AF_INET6: {
|
||||
const sockaddr_in6* a = reinterpret_cast<const sockaddr_in6*>(addr->data);
|
||||
return ntohs(a->sin6_port);
|
||||
return base::NetToHost16(a->sin6_port);
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
@ -181,8 +181,8 @@ PP_Bool AreEqual(const PP_NetAddress_Private* addr1,
|
||||
#if defined(OS_WIN) || defined(OS_MACOSX)
|
||||
std::string ConvertIPv4AddressToString(const sockaddr_in* a,
|
||||
bool include_port) {
|
||||
unsigned ip = ntohl(a->sin_addr.s_addr);
|
||||
unsigned port = ntohs(a->sin_port);
|
||||
unsigned ip = base::NetToHost32(a->sin_addr.s_addr);
|
||||
unsigned port = base::NetToHost16(a->sin_port);
|
||||
std::string description = base::StringPrintf(
|
||||
"%u.%u.%u.%u",
|
||||
(ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
|
||||
@ -204,7 +204,7 @@ std::string ConvertIPv4AddressToString(const sockaddr_in* a,
|
||||
// 5952, but consistent with |getnameinfo()|.
|
||||
std::string ConvertIPv6AddressToString(const sockaddr_in6* a,
|
||||
bool include_port) {
|
||||
unsigned port = ntohs(a->sin6_port);
|
||||
unsigned port = base::NetToHost16(a->sin6_port);
|
||||
unsigned scope = a->sin6_scope_id;
|
||||
std::string description(include_port ? "[" : "");
|
||||
|
||||
@ -229,7 +229,7 @@ std::string ConvertIPv6AddressToString(const sockaddr_in6* a,
|
||||
int curr_start = 0;
|
||||
int curr_length = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (ntohs(a->sin6_addr.s6_addr16[i]) != 0) {
|
||||
if (base::NetToHost16(a->sin6_addr.s6_addr16[i]) != 0) {
|
||||
curr_length = 0;
|
||||
} else {
|
||||
if (!curr_length)
|
||||
@ -249,7 +249,7 @@ std::string ConvertIPv6AddressToString(const sockaddr_in6* a,
|
||||
need_sep = false;
|
||||
i += longest_length;
|
||||
} else {
|
||||
unsigned v = ntohs(a->sin6_addr.s6_addr16[i]);
|
||||
unsigned v = base::NetToHost16(a->sin6_addr.s6_addr16[i]);
|
||||
base::StringAppendF(&description, need_sep ? ":%x" : "%x", v);
|
||||
need_sep = true;
|
||||
i++;
|
||||
@ -315,12 +315,14 @@ PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr,
|
||||
switch (GetFamilyInternal(src_addr)) {
|
||||
case AF_INET: {
|
||||
memmove(dest_addr, src_addr, sizeof(*src_addr));
|
||||
reinterpret_cast<sockaddr_in*>(dest_addr->data)->sin_port = htons(port);
|
||||
reinterpret_cast<sockaddr_in*>(dest_addr->data)->sin_port =
|
||||
base::HostToNet16(port);
|
||||
return PP_TRUE;
|
||||
}
|
||||
case AF_INET6: {
|
||||
memmove(dest_addr, src_addr, sizeof(*src_addr));
|
||||
reinterpret_cast<sockaddr_in6*>(dest_addr->data)->sin6_port = htons(port);
|
||||
reinterpret_cast<sockaddr_in6*>(dest_addr->data)->sin6_port =
|
||||
base::HostToNet16(port);
|
||||
return PP_TRUE;
|
||||
}
|
||||
default:
|
||||
|
@ -31,7 +31,7 @@ class NigoriStream {
|
||||
// Append the big-endian representation of the length of |value| with 32 bits,
|
||||
// followed by |value| itself to the stream.
|
||||
NigoriStream& operator<<(const std::string& value) {
|
||||
uint32 size = htonl(value.size());
|
||||
uint32 size = base::HostToNet32(value.size());
|
||||
stream_.write((char *) &size, sizeof(uint32));
|
||||
stream_ << value;
|
||||
return *this;
|
||||
@ -41,9 +41,9 @@ class NigoriStream {
|
||||
// followed by the big-endian representation of the value of |type|, with 32
|
||||
// bits, to the stream.
|
||||
NigoriStream& operator<<(const Nigori::Type type) {
|
||||
uint32 size = htonl(sizeof(uint32));
|
||||
uint32 size = base::HostToNet32(sizeof(uint32));
|
||||
stream_.write((char *) &size, sizeof(uint32));
|
||||
uint32 value = htonl(type);
|
||||
uint32 value = base::HostToNet32(type);
|
||||
stream_.write((char *) &value, sizeof(uint32));
|
||||
return *this;
|
||||
}
|
||||
|
Reference in New Issue
Block a user