tsocket: more fill in sa.sa_len if the system supports it
authorMatthieu Patou <mat@matws.net>
Mon, 1 Nov 2010 21:30:47 +0000 (08:30 +1100)
committerMatthieu Patou <mat@matws.net>
Tue, 2 Nov 2010 21:55:38 +0000 (00:55 +0300)
lib/tsocket/tsocket_bsd.c

index 974db19216dd474c595930f912ef1b945710f8f9..7bec3c52d60b01320d4a18a6434531cb601aa753 100644 (file)
@@ -1312,6 +1312,9 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local,
        }
 
        if (do_bind) {
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
+               lbsda->u.sa.sa_len = lbsda->sa_socklen;
+#endif
                ret = bind(fd, &lbsda->u.sa, lbsda->sa_socklen);
                if (ret == -1) {
                        int saved_errno = errno;
@@ -1328,6 +1331,9 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local,
                        return -1;
                }
 
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
+               rbsda->u.sa.sa_len = rbsda->sa_socklen;
+#endif
                ret = connect(fd, &rbsda->u.sa, rbsda->sa_socklen);
                if (ret == -1) {
                        int saved_errno = errno;
@@ -1363,6 +1369,9 @@ int _tdgram_inet_udp_socket(const struct tsocket_address *local,
                errno = EINVAL;
                return -1;
        }
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
+       lbsda->u.sa.sa_len = lbsda->sa_socklen;
+#endif
 
        ret = tdgram_bsd_dgram_socket(local, remote, false,
                                      mem_ctx, dgram, location);