diff options
-rw-r--r-- | content/renderer/p2p/ipc_socket_factory.cc | 7 | ||||
-rw-r--r-- | jingle/glue/utils.cc | 30 | ||||
-rw-r--r-- | jingle/glue/utils.h | 8 |
3 files changed, 21 insertions, 24 deletions
diff --git a/content/renderer/p2p/ipc_socket_factory.cc b/content/renderer/p2p/ipc_socket_factory.cc index a5e5cda..6f9d46b 100644 --- a/content/renderer/p2p/ipc_socket_factory.cc +++ b/content/renderer/p2p/ipc_socket_factory.cc @@ -155,12 +155,14 @@ bool IpcPacketSocket::Init(P2PSocketType type, P2PSocketClient* client, state_ = IS_OPENING; net::IPEndPoint local_endpoint; - if (!jingle_glue::SocketAddressToIPEndPoint(local_address, &local_endpoint)) { + if (!jingle_glue::SocketAddressToIPEndPoint( + local_address, &local_endpoint)) { return false; } net::IPEndPoint remote_endpoint; - if (!jingle_glue::SocketAddressToIPEndPoint( + if (!remote_address.IsNil() && + !jingle_glue::SocketAddressToIPEndPoint( remote_address, &remote_endpoint)) { return false; } @@ -236,6 +238,7 @@ int IpcPacketSocket::SendTo(const void *data, size_t data_size, net::IPEndPoint address_chrome; if (!jingle_glue::SocketAddressToIPEndPoint(address, &address_chrome)) { NOTREACHED(); + error_ = EINVAL; return -1; } diff --git a/jingle/glue/utils.cc b/jingle/glue/utils.cc index 5e8d44b..d58fce0 100644 --- a/jingle/glue/utils.cc +++ b/jingle/glue/utils.cc @@ -17,26 +17,20 @@ namespace jingle_glue { -bool IPEndPointToSocketAddress(const net::IPEndPoint& address_chrome, - talk_base::SocketAddress* address_lj) { - if (address_chrome.GetFamily() != net::ADDRESS_FAMILY_IPV4) { - LOG(ERROR) << "Only IPv4 addresses are supported."; - return false; - } - uint32 ip_as_int = talk_base::NetworkToHost32( - *reinterpret_cast<const uint32*>(&address_chrome.address()[0])); - *address_lj = talk_base::SocketAddress(ip_as_int, address_chrome.port()); - return true; +bool IPEndPointToSocketAddress(const net::IPEndPoint& ip_endpoint, + talk_base::SocketAddress* address) { + sockaddr_storage addr; + socklen_t len = sizeof(addr); + return ip_endpoint.ToSockAddr(reinterpret_cast<sockaddr*>(&addr), &len) && + talk_base::SocketAddressFromSockAddrStorage(addr, address); } -bool SocketAddressToIPEndPoint(const talk_base::SocketAddress& address_lj, - net::IPEndPoint* address_chrome) { - uint32 ip = talk_base::HostToNetwork32(address_lj.ip()); - net::IPAddressNumber address; - address.resize(net::kIPv4AddressSize); - memcpy(&address[0], &ip, net::kIPv4AddressSize); - *address_chrome = net::IPEndPoint(address, address_lj.port()); - return true; +bool SocketAddressToIPEndPoint(const talk_base::SocketAddress& address, + net::IPEndPoint* ip_endpoint) { + sockaddr_storage addr; + int size = address.ToSockAddrStorage(&addr); + return (size > 0) && + ip_endpoint->FromSockAddr(reinterpret_cast<sockaddr*>(&addr), size); } std::string SerializeP2PCandidate(const cricket::Candidate& candidate) { diff --git a/jingle/glue/utils.h b/jingle/glue/utils.h index 803416a..a655f71 100644 --- a/jingle/glue/utils.h +++ b/jingle/glue/utils.h @@ -24,10 +24,10 @@ namespace jingle_glue { // Chromium and libjingle represent socket addresses differently. The // following two functions are used to convert addresses from one // representation to another. -bool IPEndPointToSocketAddress(const net::IPEndPoint& address_chrome, - talk_base::SocketAddress* address_lj); -bool SocketAddressToIPEndPoint(const talk_base::SocketAddress& address_lj, - net::IPEndPoint* address_chrome); +bool IPEndPointToSocketAddress(const net::IPEndPoint& ip_endpoint, + talk_base::SocketAddress* address); +bool SocketAddressToIPEndPoint(const talk_base::SocketAddress& address, + net::IPEndPoint* ip_endpoint); // Helper functions to serialize and deserialize P2P candidates. std::string SerializeP2PCandidate(const cricket::Candidate& candidate); |