| 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 } | 444 } |
| 445 default: | 445 default: |
| 446 // InitNetAddress sets net_addr->is_valid to false. | 446 // InitNetAddress sets net_addr->is_valid to false. |
| 447 return false; | 447 return false; |
| 448 } | 448 } |
| 449 return true;} | 449 return true;} |
| 450 | 450 |
| 451 // static | 451 // static |
| 452 bool NetAddressPrivateImpl::IPEndPointToNetAddress( | 452 bool NetAddressPrivateImpl::IPEndPointToNetAddress( |
| 453 const std::vector<unsigned char>& address, | 453 const std::vector<unsigned char>& address, |
| 454 int port, | 454 uint16 port, |
| 455 PP_NetAddress_Private* addr) { | 455 PP_NetAddress_Private* addr) { |
| 456 if (!addr) | 456 if (!addr) |
| 457 return false; | 457 return false; |
| 458 | 458 |
| 459 NetAddress* net_addr = InitNetAddress(addr); | 459 NetAddress* net_addr = InitNetAddress(addr); |
| 460 switch (address.size()) { | 460 switch (address.size()) { |
| 461 case kIPv4AddressSize: { | 461 case kIPv4AddressSize: { |
| 462 net_addr->is_valid = true; | 462 net_addr->is_valid = true; |
| 463 net_addr->is_ipv6 = false; | 463 net_addr->is_ipv6 = false; |
| 464 net_addr->port = static_cast<uint16_t>(port); | 464 net_addr->port = port; |
| 465 std::copy(address.begin(), address.end(), net_addr->address); | 465 std::copy(address.begin(), address.end(), net_addr->address); |
| 466 break; | 466 break; |
| 467 } | 467 } |
| 468 case kIPv6AddressSize: { | 468 case kIPv6AddressSize: { |
| 469 net_addr->is_valid = true; | 469 net_addr->is_valid = true; |
| 470 net_addr->is_ipv6 = true; | 470 net_addr->is_ipv6 = true; |
| 471 net_addr->port = static_cast<uint16_t>(port); | 471 net_addr->port = port; |
| 472 std::copy(address.begin(), address.end(), net_addr->address); | 472 std::copy(address.begin(), address.end(), net_addr->address); |
| 473 break; | 473 break; |
| 474 } | 474 } |
| 475 default: | 475 default: |
| 476 // InitNetAddress sets net_addr->is_valid to false. | 476 // InitNetAddress sets net_addr->is_valid to false. |
| 477 return false; | 477 return false; |
| 478 } | 478 } |
| 479 | 479 |
| 480 return true; | 480 return true; |
| 481 } | 481 } |
| 482 | 482 |
| 483 // static | 483 // static |
| 484 bool NetAddressPrivateImpl::NetAddressToIPEndPoint( | 484 bool NetAddressPrivateImpl::NetAddressToIPEndPoint( |
| 485 const PP_NetAddress_Private& addr, | 485 const PP_NetAddress_Private& addr, |
| 486 std::vector<unsigned char>* address, | 486 std::vector<unsigned char>* address, |
| 487 int* port) { | 487 uint16* port) { |
| 488 if (!address || !port) | 488 if (!address || !port) |
| 489 return false; | 489 return false; |
| 490 | 490 |
| 491 const NetAddress* net_addr = ToNetAddress(&addr); | 491 const NetAddress* net_addr = ToNetAddress(&addr); |
| 492 if (!IsValid(net_addr)) | 492 if (!IsValid(net_addr)) |
| 493 return false; | 493 return false; |
| 494 | 494 |
| 495 *port = net_addr->port; | 495 *port = net_addr->port; |
| 496 size_t address_size = GetAddressSize(net_addr); | 496 size_t address_size = GetAddressSize(net_addr); |
| 497 address->assign(&net_addr->address[0], &net_addr->address[address_size]); | 497 address->assign(&net_addr->address[0], &net_addr->address[address_size]); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |