Right now, bind just returns 0 on success (and -1 on failure). I'd
like to change bind to return the port it's bound to on success. The
patch below adds this code for the unix sockets code. The windows code
looks like it'd be the same, but I can't test it so I'd have to find
someone to help with that.
--
Matt Diephouse
http://matt.diephouse.com
Index: src/io/io_unix.c
===================================================================
--- src/io/io_unix.c (revision 16202)
+++ src/io/io_unix.c (working copy)
@@ -776,7 +776,18 @@
return -1;
}
- return 0;
+ /* bind was successful. return the port number we're bound to. */
+ if (io->local.sin_port)
+ return ntohs(io->local.sin_port);
+ else {
+ struct sockaddr_in server;
+ int length;
+
+ if (getsockname(io->fd, (struct sockaddr *)&server, &length) == -1)
+ return 0;
+ else
+ return ntohs(server.sin_port);
+ }
}
/*