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
}
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());