[BusyBox] nc problem still stumps me
Jim Treadway
jim at stardot-tech.com
Mon May 6 13:48:03 UTC 2002
On Fri, 3 May 2002, Tom Oehser wrote:
> Well, I looked at the strace and the source for the original nc and
> the busybox nc, and I don't see anything obvious why the busybox nc
> doesn't work the same way. If I have something like:
>
> while [ true ] ; do nc -l -p 11111 -e /bin/true ; done
>
> and repeatedly connect to it, the real nc will continue to work every
> time, but the busybox nc will work once and then fail saying that the
> port is already in use and it can't bind. What I don't understand is
> that it seems to be the condition busybox *leaves* it in that is bad,
> not the way it initializes it- that is, after the busybox one runs,
> the real nc can't bind it, either.
>
> But, what confuses me is that nc just hands the file descriptor off
> to an execed process- so nc should have *nothing* to do with how it
> is handled when that process ends. There must be some flag or socket
> option or setup that affects the socket itself?
>
> I'll keep at it, but I'm open to ideas...
I think it just needs to set SO_REUSEADDR on the socket; the following
patch should fix it.
Jim
--- ./networking/nc.c.orig Mon May 6 12:46:52 2002
+++ ./networking/nc.c Mon May 6 12:43:39 2002
@@ -47,7 +47,8 @@
int do_listen = 0, lport = 0, delay = 0, tmpfd, opt, sfd, x;
char buf[BUFSIZ];
#ifdef GAPING_SECURITY_HOLE
- char * pr00gie = NULL;
+ char *pr00gie = NULL;
+ int flags;
#endif
struct sockaddr_in address;
@@ -100,6 +101,12 @@
if (bind(sfd, (struct sockaddr *) &address, sizeof(address)) < 0)
perror_msg_and_die("bind");
+#ifdef GAPING_SECURITY_HOLE
+ flags = 1;
+ if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &flags,
+ sizeof(flags)))
+ perror_msg_and_die("setsockopt(SO_REUSEADDR)");
+#endif
}
if (do_listen) {
More information about the busybox
mailing list