| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 13 #include "base/stringprintf.h" |
| 12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 13 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 14 #include "net/base/sys_addrinfo.h" | 16 #include "net/base/sys_addrinfo.h" |
| 15 #include "net/base/sys_byteorder.h" | 17 #include "net/base/sys_byteorder.h" |
| 16 #include "ppapi/c/pp_var.h" | 18 #include "ppapi/c/pp_var.h" |
| 17 #include "ppapi/c/private/ppb_net_address_private.h" | 19 #include "ppapi/c/private/ppb_net_address_private.h" |
| 18 #include "ppapi/shared_impl/var.h" | 20 #include "ppapi/shared_impl/var.h" |
| 19 #include "ppapi/thunk/thunk.h" | 21 #include "ppapi/thunk/thunk.h" |
| 20 | 22 |
| 21 // The net address interface doesn't have a normal C -> C++ thunk since it | 23 // The net address interface doesn't have a normal C -> C++ thunk since it |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 87 |
| 86 return PP_FALSE; | 88 return PP_FALSE; |
| 87 } | 89 } |
| 88 | 90 |
| 89 PP_Var Describe(PP_Module module, | 91 PP_Var Describe(PP_Module module, |
| 90 const struct PP_NetAddress_Private* addr, | 92 const struct PP_NetAddress_Private* addr, |
| 91 PP_Bool include_port) { | 93 PP_Bool include_port) { |
| 92 if (!NetAddressPrivateImpl::ValidateNetAddress(*addr)) | 94 if (!NetAddressPrivateImpl::ValidateNetAddress(*addr)) |
| 93 return PP_MakeUndefined(); | 95 return PP_MakeUndefined(); |
| 94 | 96 |
| 97 #if defined(OS_WIN) |
| 98 // On Windows, |NetAddressToString()| doesn't work in the sandbox. |
| 99 // TODO(viettrungluu): Consider switching to this everywhere once it's fully |
| 100 // implemented. |
| 101 switch (GetFamily(*addr)) { |
| 102 case AF_INET: { |
| 103 const sockaddr_in* a = reinterpret_cast<const sockaddr_in*>(addr->data); |
| 104 unsigned ip = ntohl(a->sin_addr.s_addr); |
| 105 unsigned port = ntohs(a->sin_port); |
| 106 std::string description = base::StringPrintf( |
| 107 "%u.%u.%u.%u", |
| 108 (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff); |
| 109 if (include_port) |
| 110 description.append(base::StringPrintf(":%u", port)); |
| 111 return StringVar::StringToPPVar(module, description); |
| 112 } |
| 113 case AF_INET6: |
| 114 // TODO(viettrungluu): crbug.com/103969 |
| 115 NOTIMPLEMENTED(); |
| 116 break; |
| 117 default: |
| 118 NOTREACHED(); |
| 119 break; |
| 120 } |
| 121 return PP_MakeUndefined(); |
| 122 #else |
| 95 const sockaddr* a = reinterpret_cast<const sockaddr*>(addr->data); | 123 const sockaddr* a = reinterpret_cast<const sockaddr*>(addr->data); |
| 96 socklen_t l = addr->size; | 124 socklen_t l = addr->size; |
| 97 std::string description = | 125 std::string description = |
| 98 include_port ? net::NetAddressToStringWithPort(a, l) : | 126 include_port ? net::NetAddressToStringWithPort(a, l) : |
| 99 net::NetAddressToString(a, l); | 127 net::NetAddressToString(a, l); |
| 100 return StringVar::StringToPPVar(module, description); | 128 return StringVar::StringToPPVar(module, description); |
| 129 #endif |
| 101 } | 130 } |
| 102 | 131 |
| 103 PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr, | 132 PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr, |
| 104 uint16_t port, | 133 uint16_t port, |
| 105 struct PP_NetAddress_Private* dest_addr) { | 134 struct PP_NetAddress_Private* dest_addr) { |
| 106 if (!NetAddressPrivateImpl::ValidateNetAddress(*src_addr)) | 135 if (!NetAddressPrivateImpl::ValidateNetAddress(*src_addr)) |
| 107 return PP_FALSE; | 136 return PP_FALSE; |
| 108 | 137 |
| 109 if (GetFamily(*src_addr) == AF_INET) { | 138 if (GetFamily(*src_addr) == AF_INET) { |
| 110 memmove(dest_addr, src_addr, sizeof(*src_addr)); | 139 memmove(dest_addr, src_addr, sizeof(*src_addr)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 197 |
| 169 // Ditto for AF_INET6. | 198 // Ditto for AF_INET6. |
| 170 if (GetFamily(addr) == AF_INET6 && addr.size >= sizeof(sockaddr_in6)) | 199 if (GetFamily(addr) == AF_INET6 && addr.size >= sizeof(sockaddr_in6)) |
| 171 return true; | 200 return true; |
| 172 | 201 |
| 173 // Reject everything else. | 202 // Reject everything else. |
| 174 return false; | 203 return false; |
| 175 } | 204 } |
| 176 | 205 |
| 177 } // namespace ppapi | 206 } // namespace ppapi |
| OLD | NEW |