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

Side by Side Diff: jingle/glue/utils.cc

Issue 1405963021: Add support for default local address in IpcNetworkManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IPAddressNumberToIPAddress. Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "jingle/glue/utils.h" 5 #include "jingle/glue/utils.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "net/base/ip_endpoint.h" 12 #include "net/base/ip_endpoint.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 #include "third_party/webrtc/base/byteorder.h" 14 #include "third_party/webrtc/base/byteorder.h"
15 #include "third_party/webrtc/base/ipaddress.h"
15 #include "third_party/webrtc/base/socketaddress.h" 16 #include "third_party/webrtc/base/socketaddress.h"
16 #include "third_party/webrtc/p2p/base/candidate.h" 17 #include "third_party/webrtc/p2p/base/candidate.h"
17 18
18 namespace jingle_glue { 19 namespace jingle_glue {
19 20
20 bool IPEndPointToSocketAddress(const net::IPEndPoint& ip_endpoint, 21 bool IPEndPointToSocketAddress(const net::IPEndPoint& ip_endpoint,
21 rtc::SocketAddress* address) { 22 rtc::SocketAddress* address) {
22 sockaddr_storage addr; 23 sockaddr_storage addr;
23 socklen_t len = sizeof(addr); 24 socklen_t len = sizeof(addr);
24 return ip_endpoint.ToSockAddr(reinterpret_cast<sockaddr*>(&addr), &len) && 25 return ip_endpoint.ToSockAddr(reinterpret_cast<sockaddr*>(&addr), &len) &&
25 rtc::SocketAddressFromSockAddrStorage(addr, address); 26 rtc::SocketAddressFromSockAddrStorage(addr, address);
26 } 27 }
27 28
28 bool SocketAddressToIPEndPoint(const rtc::SocketAddress& address, 29 bool SocketAddressToIPEndPoint(const rtc::SocketAddress& address,
29 net::IPEndPoint* ip_endpoint) { 30 net::IPEndPoint* ip_endpoint) {
30 sockaddr_storage addr; 31 sockaddr_storage addr;
31 int size = address.ToSockAddrStorage(&addr); 32 int size = address.ToSockAddrStorage(&addr);
32 return (size > 0) && 33 return (size > 0) &&
33 ip_endpoint->FromSockAddr(reinterpret_cast<sockaddr*>(&addr), size); 34 ip_endpoint->FromSockAddr(reinterpret_cast<sockaddr*>(&addr), size);
34 } 35 }
35 36
37 bool IPAddressNumberToIPAddress(const net::IPAddressNumber& ip_address_number,
Sergey Ulanov 2015/11/11 21:10:02 Don't really need to return bool here. rtc::IPAddr
38 rtc::IPAddress* ip_address) {
39 if (ip_address_number.size() == net::kIPv4AddressSize) {
40 uint32 address;
Sergey Ulanov 2015/11/11 21:10:02 Please change this to uint32_t
41 memcpy(&address, &ip_address_number[0], sizeof(uint32));
42 address = rtc::NetworkToHost32(address);
43 *ip_address = rtc::IPAddress(address);
44 return true;
45 }
46 if (ip_address_number.size() == net::kIPv6AddressSize) {
47 in6_addr address;
48 memcpy(&address, &ip_address_number[0], sizeof(in6_addr));
49 *ip_address = rtc::IPAddress(address);
50 return true;
51 }
52 return false;
53 }
54
36 std::string SerializeP2PCandidate(const cricket::Candidate& candidate) { 55 std::string SerializeP2PCandidate(const cricket::Candidate& candidate) {
37 // TODO(sergeyu): Use SDP to format candidates? 56 // TODO(sergeyu): Use SDP to format candidates?
38 base::DictionaryValue value; 57 base::DictionaryValue value;
39 value.SetString("ip", candidate.address().ipaddr().ToString()); 58 value.SetString("ip", candidate.address().ipaddr().ToString());
40 value.SetInteger("port", candidate.address().port()); 59 value.SetInteger("port", candidate.address().port());
41 value.SetString("type", candidate.type()); 60 value.SetString("type", candidate.type());
42 value.SetString("protocol", candidate.protocol()); 61 value.SetString("protocol", candidate.protocol());
43 value.SetString("username", candidate.username()); 62 value.SetString("username", candidate.username());
44 value.SetString("password", candidate.password()); 63 value.SetString("password", candidate.password());
45 value.SetDouble("preference", candidate.preference()); 64 value.SetDouble("preference", candidate.preference());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 candidate->set_protocol(protocol); 105 candidate->set_protocol(protocol);
87 candidate->set_username(username); 106 candidate->set_username(username);
88 candidate->set_password(password); 107 candidate->set_password(password);
89 candidate->set_preference(static_cast<float>(preference)); 108 candidate->set_preference(static_cast<float>(preference));
90 candidate->set_generation(generation); 109 candidate->set_generation(generation);
91 110
92 return true; 111 return true;
93 } 112 }
94 113
95 } // namespace jingle_glue 114 } // namespace jingle_glue
OLDNEW
« content/renderer/p2p/ipc_network_manager.cc ('K') | « jingle/glue/utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698