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 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 if (scope != 0) | 188 if (scope != 0) |
189 base::StringAppendF(&description, "%%%u", scope); | 189 base::StringAppendF(&description, "%%%u", scope); |
190 | 190 |
191 if (include_port) | 191 if (include_port) |
192 base::StringAppendF(&description, "]:%u", port); | 192 base::StringAppendF(&description, "]:%u", port); |
193 | 193 |
194 return description; | 194 return description; |
195 } | 195 } |
196 #endif // OS_WIN || OS_MAC | 196 #endif // OS_WIN || OS_MAC |
197 | 197 |
198 PP_Var Describe(PP_Module module, | 198 PP_Var Describe(PP_Module /*module*/, |
199 const struct PP_NetAddress_Private* addr, | 199 const struct PP_NetAddress_Private* addr, |
200 PP_Bool include_port) { | 200 PP_Bool include_port) { |
201 if (!NetAddressPrivateImpl::ValidateNetAddress(*addr)) | 201 if (!NetAddressPrivateImpl::ValidateNetAddress(*addr)) |
202 return PP_MakeUndefined(); | 202 return PP_MakeUndefined(); |
203 | 203 |
204 #if defined(OS_WIN) || defined(OS_MACOSX) | 204 #if defined(OS_WIN) || defined(OS_MACOSX) |
205 // On Windows, |NetAddressToString()| doesn't work in the sandbox. On Mac, | 205 // On Windows, |NetAddressToString()| doesn't work in the sandbox. On Mac, |
206 // the output isn't consistent with RFC 5952, at least on Mac OS 10.6: | 206 // the output isn't consistent with RFC 5952, at least on Mac OS 10.6: |
207 // |getnameinfo()| collapses length-one runs of zeros (and also doesn't | 207 // |getnameinfo()| collapses length-one runs of zeros (and also doesn't |
208 // display the scope). | 208 // display the scope). |
209 // TODO(viettrungluu): Consider switching to this on Linux. | 209 // TODO(viettrungluu): Consider switching to this on Linux. |
210 switch (GetFamily(*addr)) { | 210 switch (GetFamily(*addr)) { |
211 case AF_INET: { | 211 case AF_INET: { |
212 const sockaddr_in* a = reinterpret_cast<const sockaddr_in*>(addr->data); | 212 const sockaddr_in* a = reinterpret_cast<const sockaddr_in*>(addr->data); |
213 return StringVar::StringToPPVar( | 213 return StringVar::StringToPPVar( |
214 module, ConvertIPv4AddressToString(a, !!include_port)); | 214 ConvertIPv4AddressToString(a, !!include_port)); |
215 } | 215 } |
216 case AF_INET6: { | 216 case AF_INET6: { |
217 const sockaddr_in6* a = reinterpret_cast<const sockaddr_in6*>(addr->data); | 217 const sockaddr_in6* a = reinterpret_cast<const sockaddr_in6*>(addr->data); |
218 return StringVar::StringToPPVar( | 218 return StringVar::StringToPPVar( |
219 module, ConvertIPv6AddressToString(a, !!include_port)); | 219 ConvertIPv6AddressToString(a, !!include_port)); |
220 } | 220 } |
221 default: | 221 default: |
222 NOTREACHED(); | 222 NOTREACHED(); |
223 break; | 223 break; |
224 } | 224 } |
225 return PP_MakeUndefined(); | 225 return PP_MakeUndefined(); |
226 #else | 226 #else |
227 const sockaddr* a = reinterpret_cast<const sockaddr*>(addr->data); | 227 const sockaddr* a = reinterpret_cast<const sockaddr*>(addr->data); |
228 socklen_t l = addr->size; | 228 socklen_t l = addr->size; |
229 std::string description = | 229 std::string description = |
230 include_port ? net::NetAddressToStringWithPort(a, l) : | 230 include_port ? net::NetAddressToStringWithPort(a, l) : |
231 net::NetAddressToString(a, l); | 231 net::NetAddressToString(a, l); |
232 return StringVar::StringToPPVar(module, description); | 232 return StringVar::StringToPPVar(description); |
233 #endif | 233 #endif |
234 } | 234 } |
235 | 235 |
236 PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr, | 236 PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr, |
237 uint16_t port, | 237 uint16_t port, |
238 struct PP_NetAddress_Private* dest_addr) { | 238 struct PP_NetAddress_Private* dest_addr) { |
239 if (!NetAddressPrivateImpl::ValidateNetAddress(*src_addr)) | 239 if (!NetAddressPrivateImpl::ValidateNetAddress(*src_addr)) |
240 return PP_FALSE; | 240 return PP_FALSE; |
241 | 241 |
242 if (GetFamily(*src_addr) == AF_INET) { | 242 if (GetFamily(*src_addr) == AF_INET) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 net::IPEndPoint ip_end_point; | 369 net::IPEndPoint ip_end_point; |
370 if (!NetAddressToIPEndPoint(net_addr, &ip_end_point)) | 370 if (!NetAddressToIPEndPoint(net_addr, &ip_end_point)) |
371 return false; | 371 return false; |
372 | 372 |
373 *address_list = net::AddressList::CreateFromIPAddress(ip_end_point.address(), | 373 *address_list = net::AddressList::CreateFromIPAddress(ip_end_point.address(), |
374 ip_end_point.port()); | 374 ip_end_point.port()); |
375 return true; | 375 return true; |
376 } | 376 } |
377 | 377 |
378 } // namespace ppapi | 378 } // namespace ppapi |
OLD | NEW |