summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/printing/cloud_print/privet_traffic_detector.cc7
-rw-r--r--content/browser/renderer_host/p2p/socket_host_udp_unittest.cc4
-rw-r--r--content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc22
-rw-r--r--content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.h5
-rw-r--r--extensions/browser/api/socket/udp_socket.cc13
-rw-r--r--net/base/ip_address.cc8
-rw-r--r--net/base/ip_address.h6
-rw-r--r--net/dns/mdns_client.cc2
-rw-r--r--net/dns/mock_mdns_socket_factory.h6
-rw-r--r--net/udp/datagram_server_socket.h5
-rw-r--r--net/udp/udp_server_socket.cc4
-rw-r--r--net/udp/udp_server_socket.h6
-rw-r--r--net/udp/udp_socket_perftest.cc7
-rw-r--r--net/udp/udp_socket_posix.cc39
-rw-r--r--net/udp/udp_socket_posix.h8
-rw-r--r--net/udp/udp_socket_unittest.cc22
-rw-r--r--net/udp/udp_socket_win.cc39
-rw-r--r--net/udp/udp_socket_win.h8
-rw-r--r--ppapi/shared_impl/private/net_address_private_impl.cc4
-rw-r--r--ppapi/shared_impl/private/net_address_private_impl.h5
20 files changed, 121 insertions, 99 deletions
diff --git a/chrome/browser/printing/cloud_print/privet_traffic_detector.cc b/chrome/browser/printing/cloud_print/privet_traffic_detector.cc
index c088722..26debe0 100644
--- a/chrome/browser/printing/cloud_print/privet_traffic_detector.cc
+++ b/chrome/browser/printing/cloud_print/privet_traffic_detector.cc
@@ -133,14 +133,15 @@ int PrivetTrafficDetector::Bind() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
socket_.reset(new net::UDPServerSocket(NULL, net::NetLog::Source()));
net::IPEndPoint multicast_addr = net::GetMDnsIPEndPoint(address_family_);
- net::IPAddressNumber address_any(multicast_addr.address().size());
- net::IPEndPoint bind_endpoint(address_any, multicast_addr.port());
+ net::IPEndPoint bind_endpoint(
+ net::IPAddress::AllZeros(multicast_addr.address().size()),
+ multicast_addr.port());
socket_->AllowAddressReuse();
int rv = socket_->Listen(bind_endpoint);
if (rv < net::OK)
return rv;
socket_->SetMulticastLoopbackMode(false);
- return socket_->JoinGroup(multicast_addr.address().bytes());
+ return socket_->JoinGroup(multicast_addr.address());
}
bool PrivetTrafficDetector::IsSourceAcceptable() const {
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 7bf0944..aecd85a 100644
--- a/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc
+++ b/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc
@@ -121,12 +121,12 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket {
void AllowBroadcast() override { NOTIMPLEMENTED(); }
- int JoinGroup(const net::IPAddressNumber& group_address) const override {
+ int JoinGroup(const net::IPAddress& group_address) const override {
NOTIMPLEMENTED();
return net::ERR_NOT_IMPLEMENTED;
}
- int LeaveGroup(const net::IPAddressNumber& group_address) const override {
+ int LeaveGroup(const net::IPAddress& group_address) const override {
NOTIMPLEMENTED();
return net::ERR_NOT_IMPLEMENTED;
}
diff --git a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc
index b73029e..b5f6e14 100644
--- a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc
+++ b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc
@@ -53,12 +53,11 @@ size_t g_num_instances = 0;
namespace content {
PepperUDPSocketMessageFilter::PendingSend::PendingSend(
- const net::IPAddressNumber& address,
+ const net::IPAddress& address,
int port,
const scoped_refptr<net::IOBufferWithSize>& buffer,
const ppapi::host::ReplyMessageContext& context)
- : address(address), port(port), buffer(buffer), context(context) {
-}
+ : address(address), port(port), buffer(buffer), context(context) {}
PepperUDPSocketMessageFilter::PendingSend::PendingSend(
const PendingSend& other) = default;
@@ -364,13 +363,13 @@ int32_t PepperUDPSocketMessageFilter::OnMsgJoinGroup(
if (!socket_)
return PP_ERROR_FAILED;
- net::IPAddressNumber group;
+ std::vector<uint8_t> group;
uint16_t port;
if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &group, &port))
return PP_ERROR_ADDRESS_INVALID;
- return NetErrorToPepperError(socket_->JoinGroup(group));
+ return NetErrorToPepperError(socket_->JoinGroup(net::IPAddress(group)));
}
int32_t PepperUDPSocketMessageFilter::OnMsgLeaveGroup(
@@ -385,13 +384,13 @@ int32_t PepperUDPSocketMessageFilter::OnMsgLeaveGroup(
if (!socket_)
return PP_ERROR_FAILED;
- net::IPAddressNumber group;
+ std::vector<uint8_t> group;
uint16_t port;
if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &group, &port))
return PP_ERROR_ADDRESS_INVALID;
- return NetErrorToPepperError(socket_->LeaveGroup(group));
+ return NetErrorToPepperError(socket_->LeaveGroup(net::IPAddress(group)));
}
void PepperUDPSocketMessageFilter::DoBind(
@@ -408,13 +407,13 @@ void PepperUDPSocketMessageFilter::DoBind(
net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(),
NULL, net::NetLog::Source()));
- net::IPAddressNumber address;
+ std::vector<uint8_t> address;
uint16_t port;
if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address, &port)) {
SendBindError(context, PP_ERROR_ADDRESS_INVALID);
return;
}
- net::IPEndPoint end_point(address, port);
+ net::IPEndPoint end_point(net::IPAddress(address), port);
{
int net_result = socket->Open(end_point.GetFamily());
if (net_result != net::OK) {
@@ -589,7 +588,7 @@ void PepperUDPSocketMessageFilter::DoSendTo(
return;
}
- net::IPAddressNumber address;
+ std::vector<uint8_t> address;
uint16_t port;
if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &address, &port)) {
SendSendToError(context, PP_ERROR_ADDRESS_INVALID);
@@ -607,7 +606,8 @@ void PepperUDPSocketMessageFilter::DoSendTo(
return;
}
- pending_sends_.push(PendingSend(address, port, buffer, context));
+ pending_sends_.push(
+ PendingSend(net::IPAddress(address), port, buffer, context));
// If there are other sends pending, we can't start yet.
if (num_pending_sends)
return;
diff --git a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.h b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.h
index 7f9612c..6420581 100644
--- a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.h
+++ b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.h
@@ -19,6 +19,7 @@
#include "content/common/content_export.h"
#include "content/public/common/process_type.h"
#include "net/base/completion_callback.h"
+#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/udp/udp_socket.h"
#include "ppapi/c/pp_instance.h"
@@ -75,14 +76,14 @@ class CONTENT_EXPORT PepperUDPSocketMessageFilter
};
struct PendingSend {
- PendingSend(const net::IPAddressNumber& address,
+ PendingSend(const net::IPAddress& address,
int port,
const scoped_refptr<net::IOBufferWithSize>& buffer,
const ppapi::host::ReplyMessageContext& context);
PendingSend(const PendingSend& other);
~PendingSend();
- net::IPAddressNumber address;
+ net::IPAddress address;
int port;
scoped_refptr<net::IOBufferWithSize> buffer;
ppapi::host::ReplyMessageContext context;
diff --git a/extensions/browser/api/socket/udp_socket.cc b/extensions/browser/api/socket/udp_socket.cc
index 3aa5729..6e58ac3 100644
--- a/extensions/browser/api/socket/udp_socket.cc
+++ b/extensions/browser/api/socket/udp_socket.cc
@@ -8,6 +8,7 @@
#include "base/lazy_instance.h"
#include "extensions/browser/api/api_resource.h"
+#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/udp/datagram_socket.h"
@@ -243,11 +244,11 @@ void UDPSocket::OnSendToComplete(int result) {
bool UDPSocket::IsBound() { return socket_.is_connected(); }
int UDPSocket::JoinGroup(const std::string& address) {
- net::IPAddressNumber ip;
- if (!net::ParseIPLiteralToNumber(address, &ip))
+ net::IPAddress ip;
+ if (!ip.AssignFromIPLiteral(address))
return net::ERR_ADDRESS_INVALID;
- std::string normalized_address = net::IPAddressToString(ip);
+ std::string normalized_address = ip.ToString();
std::vector<std::string>::iterator find_result = std::find(
multicast_groups_.begin(), multicast_groups_.end(), normalized_address);
if (find_result != multicast_groups_.end())
@@ -260,11 +261,11 @@ int UDPSocket::JoinGroup(const std::string& address) {
}
int UDPSocket::LeaveGroup(const std::string& address) {
- net::IPAddressNumber ip;
- if (!net::ParseIPLiteralToNumber(address, &ip))
+ net::IPAddress ip;
+ if (!ip.AssignFromIPLiteral(address))
return net::ERR_ADDRESS_INVALID;
- std::string normalized_address = net::IPAddressToString(ip);
+ std::string normalized_address = ip.ToString();
std::vector<std::string>::iterator find_result = std::find(
multicast_groups_.begin(), multicast_groups_.end(), normalized_address);
if (find_result == multicast_groups_.end())
diff --git a/net/base/ip_address.cc b/net/base/ip_address.cc
index 945e287..075d4d0 100644
--- a/net/base/ip_address.cc
+++ b/net/base/ip_address.cc
@@ -10,9 +10,6 @@
namespace net {
-const size_t IPAddress::kIPv4AddressSize = 4;
-const size_t IPAddress::kIPv6AddressSize = 16;
-
IPAddress::IPAddress() {}
IPAddress::IPAddress(const IPAddressNumber& address) : ip_address_(address) {}
@@ -87,6 +84,11 @@ IPAddress IPAddress::IPv6Localhost() {
return IPAddress(kLocalhostIPv6);
}
+// static
+IPAddress IPAddress::AllZeros(size_t num_zero_bytes) {
+ return IPAddress(std::vector<uint8_t>(num_zero_bytes));
+}
+
bool IPAddress::operator==(const IPAddress& that) const {
return ip_address_ == that.ip_address_;
}
diff --git a/net/base/ip_address.h b/net/base/ip_address.h
index 93f594d..ed76a76 100644
--- a/net/base/ip_address.h
+++ b/net/base/ip_address.h
@@ -20,8 +20,7 @@ namespace net {
class NET_EXPORT IPAddress {
public:
- static const size_t kIPv4AddressSize;
- static const size_t kIPv6AddressSize;
+ enum : size_t { kIPv4AddressSize = 4, kIPv6AddressSize = 16 };
// Creates a zero-sized, invalid address.
IPAddress();
@@ -93,6 +92,9 @@ class NET_EXPORT IPAddress {
// Returns an IPAddress instance representing the ::1 address.
static IPAddress IPv6Localhost();
+ // Returns an IPAddress made up of |num_zero_bytes| zeros.
+ static IPAddress AllZeros(size_t num_zero_bytes);
+
bool operator==(const IPAddress& that) const;
bool operator!=(const IPAddress& that) const;
bool operator<(const IPAddress& that) const;
diff --git a/net/dns/mdns_client.cc b/net/dns/mdns_client.cc
index 64e0d75..f72d9c2 100644
--- a/net/dns/mdns_client.cc
+++ b/net/dns/mdns_client.cc
@@ -38,7 +38,7 @@ int Bind(const IPEndPoint& multicast_addr,
if (rv < OK)
return rv;
- return socket->JoinGroup(multicast_addr.address().bytes());
+ return socket->JoinGroup(multicast_addr.address());
}
} // namespace
diff --git a/net/dns/mock_mdns_socket_factory.h b/net/dns/mock_mdns_socket_factory.h
index a5b1422..179fb39 100644
--- a/net/dns/mock_mdns_socket_factory.h
+++ b/net/dns/mock_mdns_socket_factory.h
@@ -16,6 +16,8 @@
namespace net {
+class IPAddress;
+
class MockMDnsDatagramServerSocket : public DatagramServerSocket {
public:
explicit MockMDnsDatagramServerSocket(AddressFamily address_family);
@@ -51,8 +53,8 @@ class MockMDnsDatagramServerSocket : public DatagramServerSocket {
MOCK_METHOD0(AllowAddressReuse, void());
MOCK_METHOD0(AllowBroadcast, void());
- MOCK_CONST_METHOD1(JoinGroup, int(const IPAddressNumber& group_address));
- MOCK_CONST_METHOD1(LeaveGroup, int(const IPAddressNumber& address));
+ MOCK_CONST_METHOD1(JoinGroup, int(const IPAddress& group_address));
+ MOCK_CONST_METHOD1(LeaveGroup, int(const IPAddress& address));
MOCK_METHOD1(SetMulticastInterface, int(uint32_t interface_index));
MOCK_METHOD1(SetMulticastTimeToLive, int(int ttl));
diff --git a/net/udp/datagram_server_socket.h b/net/udp/datagram_server_socket.h
index bad1fee..7e5adee1 100644
--- a/net/udp/datagram_server_socket.h
+++ b/net/udp/datagram_server_socket.h
@@ -13,6 +13,7 @@
namespace net {
+class IPAddress;
class IPEndPoint;
class IOBuffer;
@@ -71,14 +72,14 @@ class NET_EXPORT DatagramServerSocket : public DatagramSocket {
// Join the multicast group with address |group_address|.
// Returns a network error code.
- virtual int JoinGroup(const IPAddressNumber& group_address) const = 0;
+ virtual int JoinGroup(const IPAddress& group_address) const = 0;
// Leave the multicast group with address |group_address|.
// If the socket hasn't joined the group, it will be ignored.
// It's optional to leave the multicast group before destroying
// the socket. It will be done by the OS.
// Returns a network error code.
- virtual int LeaveGroup(const IPAddressNumber& group_address) const = 0;
+ virtual int LeaveGroup(const IPAddress& group_address) const = 0;
// Set interface to use for multicast. If |interface_index| set to 0, default
// interface is used.
diff --git a/net/udp/udp_server_socket.cc b/net/udp/udp_server_socket.cc
index 8cda8d4..4cba115 100644
--- a/net/udp/udp_server_socket.cc
+++ b/net/udp/udp_server_socket.cc
@@ -92,11 +92,11 @@ void UDPServerSocket::AllowBroadcast() {
allow_broadcast_ = true;
}
-int UDPServerSocket::JoinGroup(const IPAddressNumber& group_address) const {
+int UDPServerSocket::JoinGroup(const IPAddress& group_address) const {
return socket_.JoinGroup(group_address);
}
-int UDPServerSocket::LeaveGroup(const IPAddressNumber& group_address) const {
+int UDPServerSocket::LeaveGroup(const IPAddress& group_address) const {
return socket_.LeaveGroup(group_address);
}
diff --git a/net/udp/udp_server_socket.h b/net/udp/udp_server_socket.h
index 668ebcc..a0b4852 100644
--- a/net/udp/udp_server_socket.h
+++ b/net/udp/udp_server_socket.h
@@ -9,12 +9,12 @@
#include "base/macros.h"
#include "net/base/completion_callback.h"
-#include "net/base/ip_address_number.h"
#include "net/udp/datagram_server_socket.h"
#include "net/udp/udp_socket.h"
namespace net {
+class IPAddress;
class IPEndPoint;
class BoundNetLog;
@@ -42,8 +42,8 @@ class NET_EXPORT UDPServerSocket : public DatagramServerSocket {
const BoundNetLog& NetLog() const override;
void AllowAddressReuse() override;
void AllowBroadcast() override;
- int JoinGroup(const IPAddressNumber& group_address) const override;
- int LeaveGroup(const IPAddressNumber& group_address) const override;
+ int JoinGroup(const IPAddress& group_address) const override;
+ int LeaveGroup(const IPAddress& group_address) const override;
int SetMulticastInterface(uint32_t interface_index) override;
int SetMulticastTimeToLive(int time_to_live) override;
int SetMulticastLoopbackMode(bool loopback) override;
diff --git a/net/udp/udp_socket_perftest.cc b/net/udp/udp_socket_perftest.cc
index 26c14cf..67804a7 100644
--- a/net/udp/udp_socket_perftest.cc
+++ b/net/udp/udp_socket_perftest.cc
@@ -53,11 +53,10 @@ class UDPSocketPerfTest : public PlatformTest {
void CreateUDPAddress(const std::string& ip_str,
uint16_t port,
IPEndPoint* address) {
- IPAddressNumber ip_number;
- bool rv = ParseIPLiteralToNumber(ip_str, &ip_number);
- if (!rv)
+ IPAddress ip_address;
+ if (!ip_address.AssignFromIPLiteral(ip_str))
return;
- *address = IPEndPoint(ip_number, port);
+ *address = IPEndPoint(ip_address, port);
}
void UDPSocketPerfTest::WritePacketsToSocket(UDPClientSocket* socket,
diff --git a/net/udp/udp_socket_posix.cc b/net/udp/udp_socket_posix.cc
index ea1a560..331bb77 100644
--- a/net/udp/udp_socket_posix.cc
+++ b/net/udp/udp_socket_posix.cc
@@ -21,6 +21,7 @@
#include "base/posix/eintr_wrapper.h"
#include "base/rand_util.h"
#include "net/base/io_buffer.h"
+#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/network_activity_monitor.h"
@@ -281,12 +282,12 @@ int UDPSocketPosix::InternalConnect(const IPEndPoint& address) {
int rv = 0;
if (bind_type_ == DatagramSocket::RANDOM_BIND) {
- // Construct IPAddressNumber of appropriate size (IPv4 or IPv6) of 0s,
+ // Construct IPAddress of appropriate size (IPv4 or IPv6) of 0s,
// representing INADDR_ANY or in6addr_any.
- size_t addr_size = address.GetSockAddrFamily() == AF_INET ?
- kIPv4AddressSize : kIPv6AddressSize;
- IPAddressNumber addr_any(addr_size);
- rv = RandomBind(addr_any);
+ size_t addr_size = address.GetSockAddrFamily() == AF_INET
+ ? IPAddress::kIPv4AddressSize
+ : IPAddress::kIPv6AddressSize;
+ rv = RandomBind(IPAddress::AllZeros(addr_size));
}
// else connect() does the DatagramSocket::DEFAULT_BIND
@@ -652,7 +653,7 @@ int UDPSocketPosix::DoBind(const IPEndPoint& address) {
return MapSystemError(last_error);
}
-int UDPSocketPosix::RandomBind(const IPAddressNumber& address) {
+int UDPSocketPosix::RandomBind(const IPAddress& address) {
DCHECK(bind_type_ == DatagramSocket::RANDOM_BIND && !rand_int_cb_.is_null());
for (int i = 0; i < kBindRetries; ++i) {
@@ -664,13 +665,13 @@ int UDPSocketPosix::RandomBind(const IPAddressNumber& address) {
return DoBind(IPEndPoint(address, 0));
}
-int UDPSocketPosix::JoinGroup(const IPAddressNumber& group_address) const {
+int UDPSocketPosix::JoinGroup(const IPAddress& group_address) const {
DCHECK(CalledOnValidThread());
if (!is_connected())
return ERR_SOCKET_NOT_CONNECTED;
switch (group_address.size()) {
- case kIPv4AddressSize: {
+ case IPAddress::kIPv4AddressSize: {
if (addr_family_ != AF_INET)
return ERR_ADDRESS_INVALID;
@@ -681,23 +682,25 @@ int UDPSocketPosix::JoinGroup(const IPAddressNumber& group_address) const {
#else
ip_mreq mreq;
int error = GetIPv4AddressFromIndex(socket_, multicast_interface_,
- &mreq.imr_interface.s_addr);
+ &mreq.imr_interface.s_addr);
if (error != OK)
return error;
#endif
- memcpy(&mreq.imr_multiaddr, &group_address[0], kIPv4AddressSize);
+ memcpy(&mreq.imr_multiaddr, group_address.bytes().data(),
+ IPAddress::kIPv4AddressSize);
int rv = setsockopt(socket_, IPPROTO_IP, IP_ADD_MEMBERSHIP,
&mreq, sizeof(mreq));
if (rv < 0)
return MapSystemError(errno);
return OK;
}
- case kIPv6AddressSize: {
+ case IPAddress::kIPv6AddressSize: {
if (addr_family_ != AF_INET6)
return ERR_ADDRESS_INVALID;
ipv6_mreq mreq;
mreq.ipv6mr_interface = multicast_interface_;
- memcpy(&mreq.ipv6mr_multiaddr, &group_address[0], kIPv6AddressSize);
+ memcpy(&mreq.ipv6mr_multiaddr, group_address.bytes().data(),
+ IPAddress::kIPv6AddressSize);
int rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_JOIN_GROUP,
&mreq, sizeof(mreq));
if (rv < 0)
@@ -710,31 +713,33 @@ int UDPSocketPosix::JoinGroup(const IPAddressNumber& group_address) const {
}
}
-int UDPSocketPosix::LeaveGroup(const IPAddressNumber& group_address) const {
+int UDPSocketPosix::LeaveGroup(const IPAddress& group_address) const {
DCHECK(CalledOnValidThread());
if (!is_connected())
return ERR_SOCKET_NOT_CONNECTED;
switch (group_address.size()) {
- case kIPv4AddressSize: {
+ case IPAddress::kIPv4AddressSize: {
if (addr_family_ != AF_INET)
return ERR_ADDRESS_INVALID;
ip_mreq mreq;
mreq.imr_interface.s_addr = INADDR_ANY;
- memcpy(&mreq.imr_multiaddr, &group_address[0], kIPv4AddressSize);
+ memcpy(&mreq.imr_multiaddr, group_address.bytes().data(),
+ IPAddress::kIPv4AddressSize);
int rv = setsockopt(socket_, IPPROTO_IP, IP_DROP_MEMBERSHIP,
&mreq, sizeof(mreq));
if (rv < 0)
return MapSystemError(errno);
return OK;
}
- case kIPv6AddressSize: {
+ case IPAddress::kIPv6AddressSize: {
if (addr_family_ != AF_INET6)
return ERR_ADDRESS_INVALID;
ipv6_mreq mreq;
mreq.ipv6mr_interface = 0; // 0 indicates default multicast interface.
- memcpy(&mreq.ipv6mr_multiaddr, &group_address[0], kIPv6AddressSize);
+ memcpy(&mreq.ipv6mr_multiaddr, group_address.bytes().data(),
+ IPAddress::kIPv6AddressSize);
int rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
&mreq, sizeof(mreq));
if (rv < 0)
diff --git a/net/udp/udp_socket_posix.h b/net/udp/udp_socket_posix.h
index 969f98d..60b095c 100644
--- a/net/udp/udp_socket_posix.h
+++ b/net/udp/udp_socket_posix.h
@@ -26,6 +26,8 @@
namespace net {
+class IPAddress;
+
class NET_EXPORT UDPSocketPosix : public base::NonThreadSafe {
public:
UDPSocketPosix(DatagramSocket::BindType bind_type,
@@ -136,7 +138,7 @@ class NET_EXPORT UDPSocketPosix : public base::NonThreadSafe {
// |group_address| is the group address to join, could be either
// an IPv4 or IPv6 address.
// Returns a net error code.
- int JoinGroup(const IPAddressNumber& group_address) const;
+ int JoinGroup(const IPAddress& group_address) const;
// Leaves the multicast group.
// |group_address| is the group address to leave, could be either
@@ -145,7 +147,7 @@ class NET_EXPORT UDPSocketPosix : public base::NonThreadSafe {
// It's optional to leave the multicast group before destroying
// the socket. It will be done by the OS.
// Returns a net error code.
- int LeaveGroup(const IPAddressNumber& group_address) const;
+ int LeaveGroup(const IPAddress& group_address) const;
// Sets interface to use for multicast. If |interface_index| set to 0,
// default interface is used.
@@ -251,7 +253,7 @@ class NET_EXPORT UDPSocketPosix : public base::NonThreadSafe {
int SetMulticastOptions();
int DoBind(const IPEndPoint& address);
// Binds to a random port on |address|.
- int RandomBind(const IPAddressNumber& address);
+ int RandomBind(const IPAddress& address);
int socket_;
diff --git a/net/udp/udp_socket_unittest.cc b/net/udp/udp_socket_unittest.cc
index 2782ba9..28f29cc 100644
--- a/net/udp/udp_socket_unittest.cc
+++ b/net/udp/udp_socket_unittest.cc
@@ -16,6 +16,7 @@
#include "base/stl_util.h"
#include "base/thread_task_runner_handle.h"
#include "net/base/io_buffer.h"
+#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
@@ -128,11 +129,10 @@ class UDPSocketTest : public PlatformTest {
void CreateUDPAddress(const std::string& ip_str,
uint16_t port,
IPEndPoint* address) {
- IPAddressNumber ip_number;
- bool rv = ParseIPLiteralToNumber(ip_str, &ip_number);
- if (!rv)
+ IPAddress ip_address;
+ if (!ip_address.AssignFromIPLiteral(ip_str))
return;
- *address = IPEndPoint(ip_number, port);
+ *address = IPEndPoint(ip_address, port);
}
// Run unit test for a connection test.
@@ -512,11 +512,11 @@ TEST_F(UDPSocketTest, ClientGetLocalPeerAddresses) {
SCOPED_TRACE(std::string("Connecting from ") + tests[i].local_address +
std::string(" to ") + tests[i].remote_address);
- IPAddressNumber ip_number;
- ParseIPLiteralToNumber(tests[i].remote_address, &ip_number);
- IPEndPoint remote_address(ip_number, 80);
- ParseIPLiteralToNumber(tests[i].local_address, &ip_number);
- IPEndPoint local_address(ip_number, 80);
+ IPAddress ip_address;
+ EXPECT_TRUE(ip_address.AssignFromIPLiteral(tests[i].remote_address));
+ IPEndPoint remote_address(ip_address, 80);
+ EXPECT_TRUE(ip_address.AssignFromIPLiteral(tests[i].local_address));
+ IPEndPoint local_address(ip_address, 80);
UDPClientSocket client(DatagramSocket::DEFAULT_BIND,
RandIntCallback(),
@@ -610,8 +610,8 @@ TEST_F(UDPSocketTest, MAYBE_JoinMulticastGroup) {
IPEndPoint bind_address;
CreateUDPAddress("0.0.0.0", kPort, &bind_address);
- IPAddressNumber group_ip;
- EXPECT_TRUE(ParseIPLiteralToNumber(kGroup, &group_ip));
+ IPAddress group_ip;
+ EXPECT_TRUE(group_ip.AssignFromIPLiteral(kGroup));
UDPSocket socket(DatagramSocket::DEFAULT_BIND,
RandIntCallback(),
diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc
index 27e2750..c162822 100644
--- a/net/udp/udp_socket_win.cc
+++ b/net/udp/udp_socket_win.cc
@@ -15,6 +15,7 @@
#include "base/metrics/sparse_histogram.h"
#include "base/rand_util.h"
#include "net/base/io_buffer.h"
+#include "net/base/ip_address.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/base/network_activity_monitor.h"
@@ -439,12 +440,12 @@ int UDPSocketWin::InternalConnect(const IPEndPoint& address) {
int rv = 0;
if (bind_type_ == DatagramSocket::RANDOM_BIND) {
- // Construct IPAddressNumber of appropriate size (IPv4 or IPv6) of 0s,
+ // Construct IPAddress of appropriate size (IPv4 or IPv6) of 0s,
// representing INADDR_ANY or in6addr_any.
- size_t addr_size = (address.GetSockAddrFamily() == AF_INET) ?
- kIPv4AddressSize : kIPv6AddressSize;
- IPAddressNumber addr_any(addr_size);
- rv = RandomBind(addr_any);
+ size_t addr_size = (address.GetSockAddrFamily() == AF_INET)
+ ? IPAddress::kIPv4AddressSize
+ : IPAddress::kIPv6AddressSize;
+ rv = RandomBind(IPAddress::AllZeros(addr_size));
}
// else connect() does the DatagramSocket::DEFAULT_BIND
@@ -952,7 +953,7 @@ int UDPSocketWin::DoBind(const IPEndPoint& address) {
return MapSystemError(last_error);
}
-int UDPSocketWin::RandomBind(const IPAddressNumber& address) {
+int UDPSocketWin::RandomBind(const IPAddress& address) {
DCHECK(bind_type_ == DatagramSocket::RANDOM_BIND && !rand_int_cb_.is_null());
for (int i = 0; i < kBindRetries; ++i) {
@@ -964,19 +965,19 @@ int UDPSocketWin::RandomBind(const IPAddressNumber& address) {
return DoBind(IPEndPoint(address, 0));
}
-int UDPSocketWin::JoinGroup(
- const IPAddressNumber& group_address) const {
+int UDPSocketWin::JoinGroup(const IPAddress& group_address) const {
DCHECK(CalledOnValidThread());
if (!is_connected())
return ERR_SOCKET_NOT_CONNECTED;
switch (group_address.size()) {
- case kIPv4AddressSize: {
+ case IPAddress::kIPv4AddressSize: {
if (addr_family_ != AF_INET)
return ERR_ADDRESS_INVALID;
ip_mreq mreq;
mreq.imr_interface.s_addr = htonl(multicast_interface_);
- memcpy(&mreq.imr_multiaddr, &group_address[0], kIPv4AddressSize);
+ memcpy(&mreq.imr_multiaddr, group_address.bytes().data(),
+ IPAddress::kIPv4AddressSize);
int rv = setsockopt(socket_, IPPROTO_IP, IP_ADD_MEMBERSHIP,
reinterpret_cast<const char*>(&mreq),
sizeof(mreq));
@@ -984,12 +985,13 @@ int UDPSocketWin::JoinGroup(
return MapSystemError(WSAGetLastError());
return OK;
}
- case kIPv6AddressSize: {
+ case IPAddress::kIPv6AddressSize: {
if (addr_family_ != AF_INET6)
return ERR_ADDRESS_INVALID;
ipv6_mreq mreq;
mreq.ipv6mr_interface = multicast_interface_;
- memcpy(&mreq.ipv6mr_multiaddr, &group_address[0], kIPv6AddressSize);
+ memcpy(&mreq.ipv6mr_multiaddr, group_address.bytes().data(),
+ IPAddress::kIPv6AddressSize);
int rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP,
reinterpret_cast<const char*>(&mreq),
sizeof(mreq));
@@ -1003,31 +1005,32 @@ int UDPSocketWin::JoinGroup(
}
}
-int UDPSocketWin::LeaveGroup(
- const IPAddressNumber& group_address) const {
+int UDPSocketWin::LeaveGroup(const IPAddress& group_address) const {
DCHECK(CalledOnValidThread());
if (!is_connected())
return ERR_SOCKET_NOT_CONNECTED;
switch (group_address.size()) {
- case kIPv4AddressSize: {
+ case IPAddress::kIPv4AddressSize: {
if (addr_family_ != AF_INET)
return ERR_ADDRESS_INVALID;
ip_mreq mreq;
mreq.imr_interface.s_addr = htonl(multicast_interface_);
- memcpy(&mreq.imr_multiaddr, &group_address[0], kIPv4AddressSize);
+ memcpy(&mreq.imr_multiaddr, group_address.bytes().data(),
+ IPAddress::kIPv4AddressSize);
int rv = setsockopt(socket_, IPPROTO_IP, IP_DROP_MEMBERSHIP,
reinterpret_cast<const char*>(&mreq), sizeof(mreq));
if (rv)
return MapSystemError(WSAGetLastError());
return OK;
}
- case kIPv6AddressSize: {
+ case IPAddress::kIPv6AddressSize: {
if (addr_family_ != AF_INET6)
return ERR_ADDRESS_INVALID;
ipv6_mreq mreq;
mreq.ipv6mr_interface = multicast_interface_;
- memcpy(&mreq.ipv6mr_multiaddr, &group_address[0], kIPv6AddressSize);
+ memcpy(&mreq.ipv6mr_multiaddr, group_address.bytes().data(),
+ IPAddress::kIPv6AddressSize);
int rv = setsockopt(socket_, IPPROTO_IPV6, IP_DROP_MEMBERSHIP,
reinterpret_cast<const char*>(&mreq), sizeof(mreq));
if (rv)
diff --git a/net/udp/udp_socket_win.h b/net/udp/udp_socket_win.h
index f36c19b..62c3e11 100644
--- a/net/udp/udp_socket_win.h
+++ b/net/udp/udp_socket_win.h
@@ -29,6 +29,8 @@
namespace net {
+class IPAddress;
+
class NET_EXPORT UDPSocketWin
: NON_EXPORTED_BASE(public base::NonThreadSafe),
NON_EXPORTED_BASE(public base::win::ObjectWatcher::Delegate) {
@@ -140,7 +142,7 @@ class NET_EXPORT UDPSocketWin
// |group_address| is the group address to join, could be either
// an IPv4 or IPv6 address.
// Returns a net error code.
- int JoinGroup(const IPAddressNumber& group_address) const;
+ int JoinGroup(const IPAddress& group_address) const;
// Leaves the multicast group.
// |group_address| is the group address to leave, could be either
@@ -149,7 +151,7 @@ class NET_EXPORT UDPSocketWin
// It's optional to leave the multicast group before destroying
// the socket. It will be done by the OS.
// Return a net error code.
- int LeaveGroup(const IPAddressNumber& group_address) const;
+ int LeaveGroup(const IPAddress& group_address) const;
// Sets interface to use for multicast. If |interface_index| set to 0,
// default interface is used.
@@ -245,7 +247,7 @@ class NET_EXPORT UDPSocketWin
int SetMulticastOptions();
int DoBind(const IPEndPoint& address);
// Binds to a random port on |address|.
- int RandomBind(const IPAddressNumber& address);
+ int RandomBind(const IPAddress& address);
SOCKET socket_;
int addr_family_;
diff --git a/ppapi/shared_impl/private/net_address_private_impl.cc b/ppapi/shared_impl/private/net_address_private_impl.cc
index 07d61d7..c945808 100644
--- a/ppapi/shared_impl/private/net_address_private_impl.cc
+++ b/ppapi/shared_impl/private/net_address_private_impl.cc
@@ -450,7 +450,7 @@ bool NetAddressPrivateImpl::SockaddrToNetAddress(
// static
bool NetAddressPrivateImpl::IPEndPointToNetAddress(
- const std::vector<unsigned char>& address,
+ const std::vector<uint8_t>& address,
uint16_t port,
PP_NetAddress_Private* addr) {
if (!addr)
@@ -483,7 +483,7 @@ bool NetAddressPrivateImpl::IPEndPointToNetAddress(
// static
bool NetAddressPrivateImpl::NetAddressToIPEndPoint(
const PP_NetAddress_Private& addr,
- std::vector<unsigned char>* address,
+ std::vector<uint8_t>* address,
uint16_t* port) {
if (!address || !port)
return false;
diff --git a/ppapi/shared_impl/private/net_address_private_impl.h b/ppapi/shared_impl/private/net_address_private_impl.h
index a7867dd..dd4b56a 100644
--- a/ppapi/shared_impl/private/net_address_private_impl.h
+++ b/ppapi/shared_impl/private/net_address_private_impl.h
@@ -5,6 +5,7 @@
#ifndef PPAPI_SHARED_IMPL_PRIVATE_NET_ADDRESS_PRIVATE_IMPL_H_
#define PPAPI_SHARED_IMPL_PRIVATE_NET_ADDRESS_PRIVATE_IMPL_H_
+#include <stdint.h>
#include <string>
#include <vector>
@@ -26,12 +27,12 @@ class PPAPI_SHARED_EXPORT NetAddressPrivateImpl {
uint32_t sa_length,
PP_NetAddress_Private* net_addr);
- static bool IPEndPointToNetAddress(const std::vector<unsigned char>& address,
+ static bool IPEndPointToNetAddress(const std::vector<uint8_t>& address,
uint16_t port,
PP_NetAddress_Private* net_addr);
static bool NetAddressToIPEndPoint(const PP_NetAddress_Private& net_addr,
- std::vector<unsigned char>* address,
+ std::vector<uint8_t>* address,
uint16_t* port);
static std::string DescribeNetAddress(const PP_NetAddress_Private& addr,