OLD | NEW |
---|---|
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 "ppapi/shared_impl/private/net_address_private_impl.h" | 5 #include "ppapi/shared_impl/private/net_address_private_impl.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <winsock2.h> | 9 #include <winsock2.h> |
10 #include <ws2tcpip.h> | 10 #include <ws2tcpip.h> |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 | 274 |
275 if (include_port) | 275 if (include_port) |
276 base::StringAppendF(&description, "]:%u", net_addr->port); | 276 base::StringAppendF(&description, "]:%u", net_addr->port); |
277 | 277 |
278 return description; | 278 return description; |
279 } | 279 } |
280 | 280 |
281 PP_Var Describe(PP_Module /*module*/, | 281 PP_Var Describe(PP_Module /*module*/, |
282 const struct PP_NetAddress_Private* addr, | 282 const struct PP_NetAddress_Private* addr, |
283 PP_Bool include_port) { | 283 PP_Bool include_port) { |
284 const NetAddress* net_addr = ToNetAddress(addr); | 284 std::string str = NetAddressPrivateImpl::DescribeNetAddress(*addr, |
285 if (!IsValid(net_addr)) | 285 !!include_port); |
brettw
2012/10/31 23:34:23
Please use PP_ToBool(include_port) like the old co
Dmitry Polukhin
2012/11/01 07:59:52
Done.
| |
286 if (str.empty()) | |
286 return PP_MakeUndefined(); | 287 return PP_MakeUndefined(); |
287 | 288 return StringVar::StringToPPVar(str); |
288 std::string description; | |
289 if (net_addr->is_ipv6) { | |
290 description = ConvertIPv6AddressToString(net_addr, | |
291 PP_ToBool(include_port)); | |
292 } else { | |
293 description = ConvertIPv4AddressToString(net_addr, | |
294 PP_ToBool(include_port)); | |
295 } | |
296 return StringVar::StringToPPVar(description); | |
297 } | 289 } |
298 | 290 |
299 PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr, | 291 PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr, |
300 uint16_t port, | 292 uint16_t port, |
301 struct PP_NetAddress_Private* dest_addr) { | 293 struct PP_NetAddress_Private* dest_addr) { |
302 const NetAddress* src_net_addr = ToNetAddress(src_addr); | 294 const NetAddress* src_net_addr = ToNetAddress(src_addr); |
303 if (!IsValid(src_net_addr) || !dest_addr) | 295 if (!IsValid(src_net_addr) || !dest_addr) |
304 return PP_FALSE; | 296 return PP_FALSE; |
305 dest_addr->size = sizeof(NetAddress); // make sure 'size' is valid. | 297 dest_addr->size = sizeof(NetAddress); // make sure 'size' is valid. |
306 NetAddress* dest_net_addr = ToNetAddress(dest_addr); | 298 NetAddress* dest_net_addr = ToNetAddress(dest_addr); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 return false; | 483 return false; |
492 | 484 |
493 *port = net_addr->port; | 485 *port = net_addr->port; |
494 size_t address_size = GetAddressSize(net_addr); | 486 size_t address_size = GetAddressSize(net_addr); |
495 address->assign(&net_addr->address[0], &net_addr->address[address_size]); | 487 address->assign(&net_addr->address[0], &net_addr->address[address_size]); |
496 | 488 |
497 return true; | 489 return true; |
498 } | 490 } |
499 #endif // !defined(OS_NACL) | 491 #endif // !defined(OS_NACL) |
500 | 492 |
493 // static | |
494 std::string NetAddressPrivateImpl::DescribeNetAddress( | |
495 const PP_NetAddress_Private& addr, | |
496 bool include_port) { | |
497 const NetAddress* net_addr = ToNetAddress(&addr); | |
498 if (!IsValid(net_addr)) | |
499 return std::string(); | |
500 | |
501 // On Windows, |NetAddressToString()| doesn't work in the sandbox. On Mac, | |
502 // the output isn't consistent with RFC 5952, at least on Mac OS 10.6: | |
503 // |getnameinfo()| collapses length-one runs of zeros (and also doesn't | |
504 // display the scope). | |
505 if (net_addr->is_ipv6) | |
506 return ConvertIPv6AddressToString(net_addr, include_port); | |
507 else | |
brettw
2012/10/31 23:34:23
else
return
return
should be just
"return Conve
Dmitry Polukhin
2012/11/01 07:59:52
Done.
| |
508 return ConvertIPv4AddressToString(net_addr, include_port); | |
509 return std::string(); | |
510 } | |
511 | |
501 } // namespace ppapi | 512 } // namespace ppapi |
OLD | NEW |