[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [BusyBox] nc.c - setsockopt SO_REUSEADDR
From: "Joseph Chiu" <josephc () idealab ! com>
Date: 2002-05-31 13:14:03
[Download RAW message or body]
Hi,
While trying to implement bash-httpd, I found that the busybox nc (netcat)
fails under certain conditions when re-listening to the same port:
# nc -l -p 9090
# nc -l -p 9090
nc: bind: Unknown Error: errno=125
asm/errno.h defines:
#define EADDRINUSE 125 /* Address already in use */
Looking at the original (non-busybox) netcat, I see the author calls
setsockopt with SO_REUSEADDR. I think the following change might be useful
in nc.c:
if (lport != 0) {
memset(&address.sin_addr, 0, sizeof(address.sin_addr));
address.sin_port = htons(lport);
+ opt = 1;
+ if (setsockopt (sfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt)) < 0)
+ perror_msg_and_die("setsockopt");
if (bind(sfd, (struct sockaddr *) &address, sizeof(address)) < 0)
perror_msg_and_die("bind");
}
With this fix, I can now use bash-httpd -- A field-modifiable webserver in
2K bytes! :)
Thanks.
Joseph
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic