--- bounce.c.orig Fri Jun 2 12:58:37 2006 +++ bounce.c Fri Jun 2 13:25:28 2006 @@ -138,7 +138,7 @@ } int main(int argc,char *argv[]) { - int srv_fd, rem_fd, len, cl_fd, on=1; + int srv_fd, rem_fd, len, cl_fd, on=1, b=0; int myport=DEFAULT_PORT, remoteport; struct sockaddr_in rem_addr, srv_addr, cl_addr; char *myname; @@ -153,8 +153,9 @@ /* Process arguments */ - while( (ch = getopt(argc, argv, "p:a:")) != -1 ) { + while( (ch = getopt(argc, argv, "p:a:b:")) != -1 ) { switch(ch) { + case 'b': b = 1; case 'a': hostname = malloc( strlen(optarg) + 1); if( !hostname ) { @@ -177,7 +178,7 @@ argv += optind; if (argc!=2) { - fprintf(stderr,"Use: %s [-a localaddr] [-p localport] machine port \n",myname); + fprintf(stderr,"Use: %s [-a localaddr | -b localaddr] [-p localport] machine port \n",myname); exit(-1); } if ((remoteport=atoi(argv[1]))<=0) { @@ -220,6 +221,7 @@ exit(-1); } listen(srv_fd,QLEN); + srv_addr.sin_port=0; signal(SIGCHLD, sigchld); printf("Ready to bounce connections from port %i to %s on port %i\n", @@ -254,6 +256,12 @@ if ((cl_fd=socket(PF_INET, SOCK_STREAM, 0))<0) { close(rem_fd); exit(-1); + } + if (b) { + if (bind(cl_fd,(struct sockaddr *)&srv_addr,sizeof(srv_addr))<0) { + close(rem_fd); + exit(-1); + } } if (connect(cl_fd, (struct sockaddr *)&cl_addr, sizeof(cl_addr))<0) {