swrap: Automatically bind an ephemeral port if needed
authorAndreas Schneider <asn@samba.org>
Wed, 4 Nov 2015 10:21:23 +0000 (11:21 +0100)
committerAndreas Schneider <asn@samba.org>
Wed, 4 Nov 2015 14:11:20 +0000 (15:11 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
src/socket_wrapper.c

index b43c877d0a8e8ac84e746846d4bc3cbb241b7575..9ba212bafe41ea7a9d0ba431407f2cf36347638c 100644 (file)
@@ -3154,6 +3154,14 @@ static int swrap_listen(int s, int backlog)
                return libc_listen(s, backlog);
        }
 
+       if (si->bound == 0) {
+               ret = swrap_auto_bind(s, si, si->family);
+               if (ret == -1) {
+                       errno = EADDRINUSE;
+                       return ret;
+               }
+       }
+
        ret = libc_listen(s, backlog);
 
        return ret;