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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 // the output isn't consistent with RFC 5952, at least on Mac OS 10.6: | 512 // the output isn't consistent with RFC 5952, at least on Mac OS 10.6: |
513 // |getnameinfo()| collapses length-one runs of zeros (and also doesn't | 513 // |getnameinfo()| collapses length-one runs of zeros (and also doesn't |
514 // display the scope). | 514 // display the scope). |
515 if (net_addr->is_ipv6) | 515 if (net_addr->is_ipv6) |
516 return ConvertIPv6AddressToString(net_addr, include_port); | 516 return ConvertIPv6AddressToString(net_addr, include_port); |
517 return ConvertIPv4AddressToString(net_addr, include_port); | 517 return ConvertIPv4AddressToString(net_addr, include_port); |
518 } | 518 } |
519 | 519 |
520 // static | 520 // static |
521 void NetAddressPrivateImpl::CreateNetAddressPrivateFromIPv4Address( | 521 void NetAddressPrivateImpl::CreateNetAddressPrivateFromIPv4Address( |
522 const PP_NetAddress_IPv4_Dev& ipv4_addr, | 522 const PP_NetAddress_IPv4& ipv4_addr, |
523 PP_NetAddress_Private* addr) { | 523 PP_NetAddress_Private* addr) { |
524 CreateFromIPv4Address(ipv4_addr.addr, ConvertFromNetEndian16(ipv4_addr.port), | 524 CreateFromIPv4Address(ipv4_addr.addr, ConvertFromNetEndian16(ipv4_addr.port), |
525 addr); | 525 addr); |
526 } | 526 } |
527 | 527 |
528 // static | 528 // static |
529 void NetAddressPrivateImpl::CreateNetAddressPrivateFromIPv6Address( | 529 void NetAddressPrivateImpl::CreateNetAddressPrivateFromIPv6Address( |
530 const PP_NetAddress_IPv6_Dev& ipv6_addr, | 530 const PP_NetAddress_IPv6& ipv6_addr, |
531 PP_NetAddress_Private* addr) { | 531 PP_NetAddress_Private* addr) { |
532 CreateFromIPv6Address(ipv6_addr.addr, 0, | 532 CreateFromIPv6Address(ipv6_addr.addr, 0, |
533 ConvertFromNetEndian16(ipv6_addr.port), addr); | 533 ConvertFromNetEndian16(ipv6_addr.port), addr); |
534 } | 534 } |
535 | 535 |
536 // static | 536 // static |
537 PP_NetAddress_Family_Dev NetAddressPrivateImpl::GetFamilyFromNetAddressPrivate( | 537 PP_NetAddress_Family NetAddressPrivateImpl::GetFamilyFromNetAddressPrivate( |
538 const PP_NetAddress_Private& addr) { | 538 const PP_NetAddress_Private& addr) { |
539 const NetAddress* net_addr = ToNetAddress(&addr); | 539 const NetAddress* net_addr = ToNetAddress(&addr); |
540 if (!IsValid(net_addr)) | 540 if (!IsValid(net_addr)) |
541 return PP_NETADDRESS_FAMILY_UNSPECIFIED; | 541 return PP_NETADDRESS_FAMILY_UNSPECIFIED; |
542 return net_addr->is_ipv6 ? PP_NETADDRESS_FAMILY_IPV6 : | 542 return net_addr->is_ipv6 ? PP_NETADDRESS_FAMILY_IPV6 : |
543 PP_NETADDRESS_FAMILY_IPV4; | 543 PP_NETADDRESS_FAMILY_IPV4; |
544 } | 544 } |
545 | 545 |
546 // static | 546 // static |
547 bool NetAddressPrivateImpl::DescribeNetAddressPrivateAsIPv4Address( | 547 bool NetAddressPrivateImpl::DescribeNetAddressPrivateAsIPv4Address( |
548 const PP_NetAddress_Private& addr, | 548 const PP_NetAddress_Private& addr, |
549 PP_NetAddress_IPv4_Dev* ipv4_addr) { | 549 PP_NetAddress_IPv4* ipv4_addr) { |
550 if (!ipv4_addr) | 550 if (!ipv4_addr) |
551 return false; | 551 return false; |
552 | 552 |
553 const NetAddress* net_addr = ToNetAddress(&addr); | 553 const NetAddress* net_addr = ToNetAddress(&addr); |
554 if (!IsValid(net_addr) || net_addr->is_ipv6) | 554 if (!IsValid(net_addr) || net_addr->is_ipv6) |
555 return false; | 555 return false; |
556 | 556 |
557 ipv4_addr->port = ConvertToNetEndian16(net_addr->port); | 557 ipv4_addr->port = ConvertToNetEndian16(net_addr->port); |
558 | 558 |
559 COMPILE_ASSERT(sizeof(ipv4_addr->addr) == kIPv4AddressSize, | 559 COMPILE_ASSERT(sizeof(ipv4_addr->addr) == kIPv4AddressSize, |
560 mismatched_IPv4_address_size); | 560 mismatched_IPv4_address_size); |
561 memcpy(ipv4_addr->addr, net_addr->address, kIPv4AddressSize); | 561 memcpy(ipv4_addr->addr, net_addr->address, kIPv4AddressSize); |
562 | 562 |
563 return true; | 563 return true; |
564 } | 564 } |
565 | 565 |
566 // static | 566 // static |
567 bool NetAddressPrivateImpl::DescribeNetAddressPrivateAsIPv6Address( | 567 bool NetAddressPrivateImpl::DescribeNetAddressPrivateAsIPv6Address( |
568 const PP_NetAddress_Private& addr, | 568 const PP_NetAddress_Private& addr, |
569 PP_NetAddress_IPv6_Dev* ipv6_addr) { | 569 PP_NetAddress_IPv6* ipv6_addr) { |
570 if (!ipv6_addr) | 570 if (!ipv6_addr) |
571 return false; | 571 return false; |
572 | 572 |
573 const NetAddress* net_addr = ToNetAddress(&addr); | 573 const NetAddress* net_addr = ToNetAddress(&addr); |
574 if (!IsValid(net_addr) || !net_addr->is_ipv6) | 574 if (!IsValid(net_addr) || !net_addr->is_ipv6) |
575 return false; | 575 return false; |
576 | 576 |
577 ipv6_addr->port = ConvertToNetEndian16(net_addr->port); | 577 ipv6_addr->port = ConvertToNetEndian16(net_addr->port); |
578 | 578 |
579 COMPILE_ASSERT(sizeof(ipv6_addr->addr) == kIPv6AddressSize, | 579 COMPILE_ASSERT(sizeof(ipv6_addr->addr) == kIPv6AddressSize, |
580 mismatched_IPv6_address_size); | 580 mismatched_IPv6_address_size); |
581 memcpy(ipv6_addr->addr, net_addr->address, kIPv6AddressSize); | 581 memcpy(ipv6_addr->addr, net_addr->address, kIPv6AddressSize); |
582 | 582 |
583 return true; | 583 return true; |
584 } | 584 } |
585 | 585 |
586 } // namespace ppapi | 586 } // namespace ppapi |
OLD | NEW |