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

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

Issue 9722008: Add CreateFromIPv[46]Address() in PPB_NetAddress_Private. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 a->sin6_family = AF_INET6; 323 a->sin6_family = AF_INET6;
324 a->sin6_addr = in6addr_any; 324 a->sin6_addr = in6addr_any;
325 } else { 325 } else {
326 sockaddr_in* a = reinterpret_cast<sockaddr_in*>(addr->data); 326 sockaddr_in* a = reinterpret_cast<sockaddr_in*>(addr->data);
327 addr->size = sizeof(*a); 327 addr->size = sizeof(*a);
328 a->sin_family = AF_INET; 328 a->sin_family = AF_INET;
329 a->sin_addr.s_addr = INADDR_ANY; 329 a->sin_addr.s_addr = INADDR_ANY;
330 } 330 }
331 } 331 }
332 332
333 void CreateFromIPv4Address(const uint8_t ip[4],
334 uint16_t port,
335 struct PP_NetAddress_Private* addr_out) {
336 sockaddr_in* a = reinterpret_cast<sockaddr_in*>(addr_out->data);
337 addr_out->size = sizeof(*a);
338 memset(a, 0, sizeof(*a));
viettrungluu 2012/03/21 17:42:55 Might as well zero all of |data| (as in |GetAnyAdd
Sergey Ulanov 2012/03/21 18:14:51 Done.
339 a->sin_family = AF_INET;
340 memcpy(&(a->sin_addr), ip, sizeof(a->sin_addr));
341 a->sin_port = htons(port);
342 }
343
344 void CreateFromIPv6Address(const uint8_t ip[16],
345 uint32_t scope_id,
346 uint16_t port,
347 struct PP_NetAddress_Private* addr_out) {
348 sockaddr_in6* a = reinterpret_cast<sockaddr_in6*>(addr_out->data);
349 addr_out->size = sizeof(*a);
350 memset(a, 0, sizeof(*a));
viettrungluu 2012/03/21 17:42:55 "
Sergey Ulanov 2012/03/21 18:14:51 Done.
351 a->sin6_family = AF_INET6;
352 memcpy(&(a->sin6_addr), ip, sizeof(a->sin6_addr));
353 a->sin6_port = htons(port);
354 a->sin6_scope_id = scope_id;
viettrungluu 2012/03/21 17:42:55 Maybe we should include a GetScopeID() in the 1.1
Sergey Ulanov 2012/03/21 18:14:51 Done.
355 }
356
333 const PPB_NetAddress_Private_0_1 net_address_private_interface_0_1 = { 357 const PPB_NetAddress_Private_0_1 net_address_private_interface_0_1 = {
334 &AreEqual, 358 &AreEqual,
335 &AreHostsEqual, 359 &AreHostsEqual,
336 &Describe, 360 &Describe,
337 &ReplacePort, 361 &ReplacePort,
338 &GetAnyAddress 362 &GetAnyAddress
339 }; 363 };
340 364
341 const PPB_NetAddress_Private_1_0 net_address_private_interface_1_0 = { 365 const PPB_NetAddress_Private_1_0 net_address_private_interface_1_0 = {
342 &AreEqual, 366 &AreEqual,
343 &AreHostsEqual, 367 &AreHostsEqual,
344 &Describe, 368 &Describe,
345 &ReplacePort, 369 &ReplacePort,
346 &GetAnyAddress, 370 &GetAnyAddress,
347 &GetFamily, 371 &GetFamily,
348 &GetPort, 372 &GetPort,
349 &GetAddress 373 &GetAddress
350 }; 374 };
351 375
376 const PPB_NetAddress_Private_1_1 net_address_private_interface_1_1 = {
377 &AreEqual,
378 &AreHostsEqual,
379 &Describe,
380 &ReplacePort,
381 &GetAnyAddress,
382 &GetFamily,
383 &GetPort,
384 &GetAddress,
385 &CreateFromIPv4Address,
386 &CreateFromIPv6Address
387 };
388
352 } // namespace 389 } // namespace
353 390
354 namespace thunk { 391 namespace thunk {
355 392
356 PPAPI_THUNK_EXPORT const PPB_NetAddress_Private_0_1* 393 PPAPI_THUNK_EXPORT const PPB_NetAddress_Private_0_1*
357 GetPPB_NetAddress_Private_0_1_Thunk() { 394 GetPPB_NetAddress_Private_0_1_Thunk() {
358 return &net_address_private_interface_0_1; 395 return &net_address_private_interface_0_1;
359 } 396 }
360 397
361 PPAPI_THUNK_EXPORT const PPB_NetAddress_Private_1_0* 398 PPAPI_THUNK_EXPORT const PPB_NetAddress_Private_1_0*
362 GetPPB_NetAddress_Private_1_0_Thunk() { 399 GetPPB_NetAddress_Private_1_0_Thunk() {
363 return &net_address_private_interface_1_0; 400 return &net_address_private_interface_1_0;
364 } 401 }
365 402
403 PPAPI_THUNK_EXPORT const PPB_NetAddress_Private_1_1*
404 GetPPB_NetAddress_Private_1_1_Thunk() {
405 return &net_address_private_interface_1_1;
406 }
407
366 } // namespace thunk 408 } // namespace thunk
367 409
368 // static 410 // static
369 const PP_NetAddress_Private NetAddressPrivateImpl::kInvalidNetAddress = { 0 }; 411 const PP_NetAddress_Private NetAddressPrivateImpl::kInvalidNetAddress = { 0 };
370 412
371 // static 413 // static
372 bool NetAddressPrivateImpl::ValidateNetAddress( 414 bool NetAddressPrivateImpl::ValidateNetAddress(
373 const PP_NetAddress_Private& addr) { 415 const PP_NetAddress_Private& addr) {
374 if (addr.size < sizeof(reinterpret_cast<sockaddr*>(0)->sa_family)) 416 if (addr.size < sizeof(reinterpret_cast<sockaddr*>(0)->sa_family))
375 return false; 417 return false;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 net::IPEndPoint ip_end_point; 495 net::IPEndPoint ip_end_point;
454 if (!NetAddressToIPEndPoint(net_addr, &ip_end_point)) 496 if (!NetAddressToIPEndPoint(net_addr, &ip_end_point))
455 return false; 497 return false;
456 498
457 *address_list = net::AddressList::CreateFromIPAddress(ip_end_point.address(), 499 *address_list = net::AddressList::CreateFromIPAddress(ip_end_point.address(),
458 ip_end_point.port()); 500 ip_end_point.port());
459 return true; 501 return true;
460 } 502 }
461 503
462 } // namespace ppapi 504 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698