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

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

Issue 10993078: Use extensions socket permission for TCP/UDP socket APIs in Pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <ws2tcpip.h> 9 #include <ws2tcpip.h>
10 #elif defined(OS_POSIX) 10 #elif defined(OS_POSIX)
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 325
326 if (include_port) 326 if (include_port)
327 base::StringAppendF(&description, "]:%u", port); 327 base::StringAppendF(&description, "]:%u", port);
328 328
329 return description; 329 return description;
330 } 330 }
331 331
332 PP_Var Describe(PP_Module /*module*/, 332 PP_Var Describe(PP_Module /*module*/,
333 const struct PP_NetAddress_Private* addr, 333 const struct PP_NetAddress_Private* addr,
334 PP_Bool include_port) { 334 PP_Bool include_port) {
335 if (!NetAddressPrivateImpl::ValidateNetAddress(*addr)) 335 std::string str =
336 NetAddressPrivateImpl::DescribeNetAddress(*addr, !!include_port);
337 if (str.empty())
336 return PP_MakeUndefined(); 338 return PP_MakeUndefined();
337 339 return StringVar::StringToPPVar(str);
338 // On Windows, |NetAddressToString()| doesn't work in the sandbox. On Mac,
339 // the output isn't consistent with RFC 5952, at least on Mac OS 10.6:
340 // |getnameinfo()| collapses length-one runs of zeros (and also doesn't
341 // display the scope).
342 switch (GetFamilyInternal(addr)) {
343 case AF_INET: {
344 const sockaddr_in* a = reinterpret_cast<const sockaddr_in*>(addr->data);
345 return StringVar::StringToPPVar(
346 ConvertIPv4AddressToString(a, !!include_port));
347 }
348 case AF_INET6: {
349 const sockaddr_in6* a = reinterpret_cast<const sockaddr_in6*>(addr->data);
350 return StringVar::StringToPPVar(
351 ConvertIPv6AddressToString(a, !!include_port));
352 }
353 default:
354 NOTREACHED();
355 break;
356 }
357 return PP_MakeUndefined();
358 } 340 }
359 341
360 PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr, 342 PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr,
361 uint16_t port, 343 uint16_t port,
362 struct PP_NetAddress_Private* dest_addr) { 344 struct PP_NetAddress_Private* dest_addr) {
363 if (!NetAddressPrivateImpl::ValidateNetAddress(*src_addr)) 345 if (!NetAddressPrivateImpl::ValidateNetAddress(*src_addr))
364 return PP_FALSE; 346 return PP_FALSE;
365 347
366 switch (GetFamilyInternal(src_addr)) { 348 switch (GetFamilyInternal(src_addr)) {
367 case AF_INET: { 349 case AF_INET: {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 const PP_NetAddress_Private& net_addr, 518 const PP_NetAddress_Private& net_addr,
537 std::vector<unsigned char>* address, 519 std::vector<unsigned char>* address,
538 int* port) { 520 int* port) {
539 if (!address || !port || !ValidateNetAddress(net_addr)) 521 if (!address || !port || !ValidateNetAddress(net_addr))
540 return false; 522 return false;
541 523
542 return SockaddrToIPEndPoint( 524 return SockaddrToIPEndPoint(
543 reinterpret_cast<const sockaddr&>(*net_addr.data), address, port); 525 reinterpret_cast<const sockaddr&>(*net_addr.data), address, port);
544 } 526 }
545 527
528 // static
529 std::string NetAddressPrivateImpl::DescribeNetAddress(
530 const PP_NetAddress_Private& addr,
531 bool include_port) {
532 if (!NetAddressPrivateImpl::ValidateNetAddress(addr))
533 return std::string();
534
535 // On Windows, |NetAddressToString()| doesn't work in the sandbox. On Mac,
536 // the output isn't consistent with RFC 5952, at least on Mac OS 10.6:
537 // |getnameinfo()| collapses length-one runs of zeros (and also doesn't
538 // display the scope).
539 switch (GetFamilyInternal(&addr)) {
540 case AF_INET: {
541 const sockaddr_in* a = reinterpret_cast<const sockaddr_in*>(&addr.data);
542 return ConvertIPv4AddressToString(a, include_port);
543 }
544 case AF_INET6: {
545 const sockaddr_in6* a = reinterpret_cast<const sockaddr_in6*>(&addr.data);
546 return ConvertIPv6AddressToString(a, include_port);
547 }
548 default:
549 NOTREACHED();
550 break;
551 }
552 return std::string();
553 }
554
546 } // namespace ppapi 555 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698