Commit dc939388 authored by Subodh Iyengar's avatar Subodh Iyengar Committed by Facebook Github Bot 6

Add sa_len for sockaddr conversions

Summary:
Some platforms like Apple add a additional
field to sockaddr called sa_len.

This is not normally required by POSIX, so
all posix methods work correctly when a sockaddr
is passed in without a sa_len set.

However other functions which are not defined
by posix such as connectx require this field to
operate correctly.

Reviewed By: yfeldblum

Differential Revision: D3514266

fbshipit-source-id: f8e2941f337222486c81c911dbd06a2ce35e4f00
parent 99177311
......@@ -201,16 +201,23 @@ class IPAddress : boost::totally_ordered<IPAddress> {
}
memset(dest, 0, sizeof(sockaddr_storage));
dest->ss_family = family();
if (isV4()) {
sockaddr_in *sin = reinterpret_cast<sockaddr_in*>(dest);
sin->sin_addr = asV4().toAddr();
sin->sin_port = port;
#if defined(__APPLE__)
sin->sin_len = sizeof(*sin);
#endif
return sizeof(*sin);
} else if (isV6()) {
sockaddr_in6 *sin = reinterpret_cast<sockaddr_in6*>(dest);
sin->sin6_addr = asV6().toAddr();
sin->sin6_port = port;
sin->sin6_scope_id = asV6().getScopeId();
#if defined(__APPLE__)
sin->sin6_len = sizeof(*sin);
#endif
return sizeof(*sin);
} else {
throw InvalidAddressFamilyException(family());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment