Add support for platforms without sa_len to SocketAddress, and modify
some code to use it

git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@135790 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Host/common/SocketAddress.cpp b/source/Host/common/SocketAddress.cpp
index 7e3929d..a22dc7a 100644
--- a/source/Host/common/SocketAddress.cpp
+++ b/source/Host/common/SocketAddress.cpp
@@ -11,6 +11,7 @@
 #include <stddef.h>
 
 // C Includes
+#include <assert.h>
 #include <string.h>
 
 // C++ Includes
@@ -77,10 +78,25 @@
     return GetLength () != 0;
 }
 
+static socklen_t 
+GetFamilyLength (sa_family_t family)
+{
+    switch (family)
+    {
+        case AF_INET:  return sizeof(struct sockaddr_in);
+        case AF_INET6: return sizeof(struct sockaddr_in6);
+    }
+    assert(0 && "Unsupported address family");
+}
+
 socklen_t
 SocketAddress::GetLength () const
 {
+#if defined(__APPLE__)
     return m_socket_addr.sa.sa_len;
+#else
+    return GetFamilyLength (GetFamily());
+#endif
 }
 
 socklen_t
@@ -89,12 +105,6 @@
     return sizeof (sockaddr_t);
 }
 
-void
-SocketAddress::SetLength (socklen_t len)
-{
-    m_socket_addr.sa.sa_len = len;
-}
-
 sa_family_t
 SocketAddress::GetFamily () const
 {
@@ -105,6 +115,9 @@
 SocketAddress::SetFamily (sa_family_t family)
 {
     m_socket_addr.sa.sa_family = family;
+#if defined(__APPLE__)
+    m_socket_addr.sa.sa_len = GetFamilyLength (family);
+#endif
 }
 
 in_port_t
@@ -228,7 +241,6 @@
             if (SetPort (port))
             {
                 m_socket_addr.sa_ipv4.sin_addr.s_addr = htonl (INADDR_ANY);
-                SetLength (sizeof(m_socket_addr.sa_ipv4));
                 return true;
             }
             break;
@@ -238,7 +250,6 @@
             if (SetPort (port))
             {
                 m_socket_addr.sa_ipv6.sin6_addr = in6addr_any;
-                SetLength (sizeof(m_socket_addr.sa_ipv6));
                 return true;
             }            
             break;