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

Side by Side Diff: ppapi/shared_impl/private/net_address_private_impl.cc

Issue 10309002: Reimplements net::AddressList without struct addrinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: get_canonical_name -> canonical_name. iterator to indexing Created 8 years, 7 months 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 | Annotate | Revision Log
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 "ppapi/shared_impl/private/net_address_private_impl.h" 5 #include "ppapi/shared_impl/private/net_address_private_impl.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/sys_byteorder.h" 14 #include "base/sys_byteorder.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "net/base/address_list.h" 16 #include "net/base/address_list.h"
17 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 #include "net/base/sys_addrinfo.h"
20 #include "ppapi/c/pp_var.h" 19 #include "ppapi/c/pp_var.h"
21 #include "ppapi/c/private/ppb_net_address_private.h" 20 #include "ppapi/c/private/ppb_net_address_private.h"
22 #include "ppapi/shared_impl/var.h" 21 #include "ppapi/shared_impl/var.h"
23 #include "ppapi/thunk/thunk.h" 22 #include "ppapi/thunk/thunk.h"
24 23
25 #if defined(OS_MACOSX) 24 #if defined(OS_MACOSX)
26 // This is a bit evil, but it's standard operating procedure for |s6_addr|.... 25 // This is a bit evil, but it's standard operating procedure for |s6_addr|....
27 #define s6_addr16 __u6_addr.__u6_addr16 26 #define s6_addr16 __u6_addr.__u6_addr16
28 #endif 27 #endif
29 28
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 CHECK_LE(sa_length, sizeof(net_addr->data)); 464 CHECK_LE(sa_length, sizeof(net_addr->data));
466 net_addr->size = sa_length; 465 net_addr->size = sa_length;
467 memcpy(net_addr->data, sa, net_addr->size); 466 memcpy(net_addr->data, sa, net_addr->size);
468 return true; 467 return true;
469 } 468 }
470 469
471 // static 470 // static
472 bool NetAddressPrivateImpl::IPEndPointToNetAddress( 471 bool NetAddressPrivateImpl::IPEndPointToNetAddress(
473 const net::IPEndPoint& ip, 472 const net::IPEndPoint& ip,
474 PP_NetAddress_Private* net_addr) { 473 PP_NetAddress_Private* net_addr) {
475 sockaddr_storage storage = { 0 }; 474 net::SockaddrStorage storage;
476 size_t length = sizeof(storage);
477 475
478 return ip.ToSockAddr(reinterpret_cast<sockaddr*>(&storage), &length) && 476 return ip.ToSockAddr(storage.addr, &storage.addr_len) &&
479 SockaddrToNetAddress(reinterpret_cast<const sockaddr*>(&storage), length, 477 SockaddrToNetAddress(storage.addr, storage.addr_len, net_addr);
480 net_addr);
481 } 478 }
482 479
483 // static 480 // static
484 bool NetAddressPrivateImpl::AddressListToNetAddress( 481 bool NetAddressPrivateImpl::AddressListToNetAddress(
485 const net::AddressList& address_list, 482 const net::AddressList& address_list,
486 PP_NetAddress_Private* net_addr) { 483 PP_NetAddress_Private* net_addr) {
487 const addrinfo* head = address_list.head(); 484 return !address_list.empty() && IPEndPointToNetAddress(address_list.front(),
488 return head && SockaddrToNetAddress(head->ai_addr, head->ai_addrlen, 485 net_addr);
489 net_addr);
490 } 486 }
491 487
492 // static 488 // static
493 bool NetAddressPrivateImpl::NetAddressToIPEndPoint( 489 bool NetAddressPrivateImpl::NetAddressToIPEndPoint(
494 const PP_NetAddress_Private& net_addr, 490 const PP_NetAddress_Private& net_addr,
495 net::IPEndPoint* ip_end_point) { 491 net::IPEndPoint* ip_end_point) {
496 if (!ip_end_point || !ValidateNetAddress(net_addr)) 492 if (!ip_end_point || !ValidateNetAddress(net_addr))
497 return false; 493 return false;
498 494
499 if (!ip_end_point->FromSockAddr( 495 if (!ip_end_point->FromSockAddr(
500 reinterpret_cast<const sockaddr*>(net_addr.data), net_addr.size)) { 496 reinterpret_cast<const sockaddr*>(net_addr.data), net_addr.size)) {
501 return false; 497 return false;
502 } 498 }
503 499
504 return true; 500 return true;
505 } 501 }
506 502
507 // static 503 // static
508 bool NetAddressPrivateImpl::NetAddressToAddressList( 504 bool NetAddressPrivateImpl::NetAddressToAddressList(
509 const PP_NetAddress_Private& net_addr, net::AddressList* address_list) { 505 const PP_NetAddress_Private& net_addr, net::AddressList* address_list) {
510 if (!address_list) 506 if (!address_list)
511 return false; 507 return false;
512 508
513 net::IPEndPoint ip_end_point; 509 net::IPEndPoint ip_end_point;
514 if (!NetAddressToIPEndPoint(net_addr, &ip_end_point)) 510 if (!NetAddressToIPEndPoint(net_addr, &ip_end_point))
515 return false; 511 return false;
516 512
517 *address_list = net::AddressList::CreateFromIPAddress(ip_end_point.address(), 513 *address_list = net::AddressList(ip_end_point);
518 ip_end_point.port());
519 return true; 514 return true;
520 } 515 }
521 516
522 } // namespace ppapi 517 } // namespace ppapi
OLDNEW
« no previous file with comments | « net/websockets/websocket_throttle_unittest.cc ('k') | ppapi/shared_impl/private/ppb_host_resolver_shared.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698