Index: ppapi/shared_impl/private/net_address_private_impl.cc |
diff --git a/ppapi/shared_impl/private/net_address_private_impl.cc b/ppapi/shared_impl/private/net_address_private_impl.cc |
index 5edf5a4a38b0a849f8657cf9dd142c26a45e5970..cb5ba4174175a39c0ee4c9afa861e76160a97fe8 100644 |
--- a/ppapi/shared_impl/private/net_address_private_impl.cc |
+++ b/ppapi/shared_impl/private/net_address_private_impl.cc |
@@ -48,15 +48,22 @@ COMPILE_ASSERT(sizeof(reinterpret_cast<PP_NetAddress_Private*>(0)->data) >= |
sizeof(sockaddr_storage), PP_NetAddress_Private_data_too_small); |
#endif |
-uint16_t GetFamily(const PP_NetAddress_Private* addr) { |
- return reinterpret_cast<const sockaddr*>(addr->data)->sa_family; |
+PP_AddressFamily_Private GetFamily(const PP_NetAddress_Private* addr) { |
+ switch (reinterpret_cast<const sockaddr*>(addr->data)->sa_family) { |
+ case AF_INET: |
+ return PP_ADDRESSFAMILY_IPV4; |
+ case AF_INET6: |
+ return PP_ADDRESSFAMILY_IPV6; |
+ default: |
+ return PP_ADDRESSFAMILY_UNSPECIFIED; |
+ } |
} |
uint16_t GetPort(const PP_NetAddress_Private* addr) { |
- if (GetFamily(addr) == AF_INET) { |
+ if (GetFamily(addr) == PP_ADDRESSFAMILY_IPV4) { |
viettrungluu
2012/02/15 01:43:03
Now that GetFamily() has a nontrivial cost, you sh
yzshen1
2012/02/15 18:40:55
Done. (I did both.)
On 2012/02/15 01:43:03, viett
|
const sockaddr_in* a = reinterpret_cast<const sockaddr_in*>(addr->data); |
return ntohs(a->sin_port); |
- } else if (GetFamily(addr) == AF_INET6) { |
+ } else if (GetFamily(addr) == PP_ADDRESSFAMILY_IPV6) { |
const sockaddr_in6* a = reinterpret_cast<const sockaddr_in6*>(addr->data); |
return ntohs(a->sin6_port); |
} |
@@ -67,13 +74,13 @@ uint16_t GetPort(const PP_NetAddress_Private* addr) { |
PP_Bool GetAddress(const PP_NetAddress_Private* addr, |
void* address, |
uint16_t address_size) { |
- if (GetFamily(addr) == AF_INET) { |
+ if (GetFamily(addr) == PP_ADDRESSFAMILY_IPV4) { |
viettrungluu
2012/02/15 01:43:03
"
yzshen1
2012/02/15 18:40:55
Done.
|
const sockaddr_in* a = reinterpret_cast<const sockaddr_in*>(addr->data); |
if (address_size >= sizeof(a->sin_addr.s_addr)) { |
memcpy(address, &(a->sin_addr.s_addr), sizeof(a->sin_addr.s_addr)); |
return PP_TRUE; |
} |
- } else if (GetFamily(addr) == AF_INET6) { |
+ } else if (GetFamily(addr) == PP_ADDRESSFAMILY_IPV6) { |
const sockaddr_in6* a = reinterpret_cast<const sockaddr_in6*>(addr->data); |
if (address_size >= sizeof(a->sin6_addr.s6_addr)) { |
memcpy(address, &(a->sin6_addr.s6_addr), sizeof(a->sin6_addr.s6_addr)); |
@@ -93,13 +100,13 @@ PP_Bool AreHostsEqual(const PP_NetAddress_Private* addr1, |
if (GetFamily(addr1) != GetFamily(addr2)) |
viettrungluu
2012/02/15 01:43:03
Similarly, save the family of addr1 and compare it
yzshen1
2012/02/15 18:40:55
Done.
|
return PP_FALSE; |
- if (GetFamily(addr1) == AF_INET) { |
+ if (GetFamily(addr1) == PP_ADDRESSFAMILY_IPV4) { |
const sockaddr_in* a1 = reinterpret_cast<const sockaddr_in*>(addr1->data); |
const sockaddr_in* a2 = reinterpret_cast<const sockaddr_in*>(addr2->data); |
return PP_FromBool(a1->sin_addr.s_addr == a2->sin_addr.s_addr); |
} |
- if (GetFamily(addr1) == AF_INET6) { |
+ if (GetFamily(addr1) == PP_ADDRESSFAMILY_IPV6) { |
const sockaddr_in6* a1 = reinterpret_cast<const sockaddr_in6*>(addr1->data); |
const sockaddr_in6* a2 = reinterpret_cast<const sockaddr_in6*>(addr2->data); |
return PP_FromBool(a1->sin6_flowinfo == a2->sin6_flowinfo && |
@@ -119,13 +126,13 @@ PP_Bool AreEqual(const PP_NetAddress_Private* addr1, |
return PP_FALSE; |
// Note: Here, we know that |addr1| and |addr2| have the same family. |
- if (GetFamily(addr1) == AF_INET) { |
+ if (GetFamily(addr1) == PP_ADDRESSFAMILY_IPV4) { |
const sockaddr_in* a1 = reinterpret_cast<const sockaddr_in*>(addr1->data); |
const sockaddr_in* a2 = reinterpret_cast<const sockaddr_in*>(addr2->data); |
return PP_FromBool(a1->sin_port == a2->sin_port); |
} |
- if (GetFamily(addr1) == AF_INET6) { |
+ if (GetFamily(addr1) == PP_ADDRESSFAMILY_IPV6) { |
const sockaddr_in6* a1 = reinterpret_cast<const sockaddr_in6*>(addr1->data); |
const sockaddr_in6* a2 = reinterpret_cast<const sockaddr_in6*>(addr2->data); |
return PP_FromBool(a1->sin6_port == a2->sin6_port); |
@@ -237,12 +244,12 @@ PP_Var Describe(PP_Module /*module*/, |
// display the scope). |
// TODO(viettrungluu): Consider switching to this on Linux. |
switch (GetFamily(addr)) { |
- case AF_INET: { |
+ case PP_ADDRESSFAMILY_IPV4: { |
const sockaddr_in* a = reinterpret_cast<const sockaddr_in*>(addr->data); |
return StringVar::StringToPPVar( |
ConvertIPv4AddressToString(a, !!include_port)); |
} |
- case AF_INET6: { |
+ case PP_ADDRESSFAMILY_IPV6: { |
const sockaddr_in6* a = reinterpret_cast<const sockaddr_in6*>(addr->data); |
return StringVar::StringToPPVar( |
ConvertIPv6AddressToString(a, !!include_port)); |
@@ -268,13 +275,13 @@ PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr, |
if (!NetAddressPrivateImpl::ValidateNetAddress(*src_addr)) |
return PP_FALSE; |
- if (GetFamily(src_addr) == AF_INET) { |
+ if (GetFamily(src_addr) == PP_ADDRESSFAMILY_IPV4) { |
viettrungluu
2012/02/15 01:43:03
"
yzshen1
2012/02/15 18:40:55
Done.
|
memmove(dest_addr, src_addr, sizeof(*src_addr)); |
reinterpret_cast<sockaddr_in*>(dest_addr->data)->sin_port = htons(port); |
return PP_TRUE; |
} |
- if (GetFamily(src_addr) == AF_INET6) { |
+ if (GetFamily(src_addr) == PP_ADDRESSFAMILY_IPV6) { |
memmove(dest_addr, src_addr, sizeof(*src_addr)); |
reinterpret_cast<sockaddr_in6*>(dest_addr->data)->sin6_port = htons(port); |
return PP_TRUE; |
@@ -343,13 +350,17 @@ bool NetAddressPrivateImpl::ValidateNetAddress( |
return false; |
// TODO(viettrungluu): more careful validation? |
- // Just do a size check for AF_INET. |
- if (GetFamily(&addr) == AF_INET && addr.size >= sizeof(sockaddr_in)) |
+ // Just do a size check for IPv4. |
+ if (GetFamily(&addr) == PP_ADDRESSFAMILY_IPV4 && |
viettrungluu
2012/02/15 01:43:03
"
yzshen1
2012/02/15 18:40:55
Done.
|
+ addr.size >= sizeof(sockaddr_in)) { |
return true; |
+ } |
- // Ditto for AF_INET6. |
- if (GetFamily(&addr) == AF_INET6 && addr.size >= sizeof(sockaddr_in6)) |
+ // Ditto for IPv6. |
+ if (GetFamily(&addr) == PP_ADDRESSFAMILY_IPV6 && |
+ addr.size >= sizeof(sockaddr_in6)) { |
return true; |
+ } |
// Reject everything else. |
return false; |