From: Subodh Iyengar Date: Tue, 5 Jul 2016 05:46:06 +0000 (-0700) Subject: Add sa_len for sockaddr conversions X-Git-Tag: 2016.07.26~80 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=dc93938852aa64604563afbc8d185062f01153f2;hp=9917731199d890499d7a732c1573281b4976bb16 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 --- diff --git a/folly/IPAddress.h b/folly/IPAddress.h index 52b00a8a..c5f31c77 100644 --- a/folly/IPAddress.h +++ b/folly/IPAddress.h @@ -201,16 +201,23 @@ class IPAddress : boost::totally_ordered { } memset(dest, 0, sizeof(sockaddr_storage)); dest->ss_family = family(); + if (isV4()) { sockaddr_in *sin = reinterpret_cast(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(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());