Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 May 2006 19:04:11 -0700 (PDT)
From:      matt wilbur <matt@efs.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/97868: Binary file /tmp/pf.YYjfPTHu matches
Message-ID:  <200605250204.k4P24BMJ082107@sublime.efs.org>
Resent-Message-ID: <200605250210.k4P2AJ6M004111@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         97868
>Category:       ports
>Synopsis:       update and adoption of net/bounce port
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 25 02:10:18 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     matt wilbur
>Release:        FreeBSD 6.1-RC i386
>Organization:
>Environment:
System: FreeBSD sublime.efs.org 6.1-RC FreeBSD 6.1-RC #2: Fri Apr 28 21:58:23 PDT 2006 root@sublime.efs.org:/usr/obj/usr/src/sys/SMP i386


	
>Description:
	added myself as maintainer, fixed port MASTER_SITE url. upgrading host to RELENG_6 but have used this port for years, it still works great on -STABLE.
>How-To-Repeat:
	
>Fix:
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	bounce
#	bounce/work
#	bounce/work/.install_done.bounce-1.0._usr_local
#	bounce/work/.extract_done.bounce-1.0._usr_local
#	bounce/work/bounce.c.orig
#	bounce/work/.patch_done.bounce-1.0._usr_local
#	bounce/work/.configure_done.bounce-1.0._usr_local
#	bounce/work/bounce
#	bounce/work/.build_done.bounce-1.0._usr_local
#	bounce/work/.PLIST.mktmp
#	bounce/work/.PLIST.flattened
#	bounce/work/.PLIST.setuid
#	bounce/work/.PLIST.writable
#	bounce/work/.PLIST.objdump
#	bounce/work/bounce.c
#	bounce/files
#	bounce/files/patch-01
#	bounce/pkg-descr
#	bounce/Makefile
#	bounce/pkg-plist
#	bounce/distinfo
#
echo c - bounce
mkdir -p bounce > /dev/null 2>&1
echo c - bounce/work
mkdir -p bounce/work > /dev/null 2>&1
echo x - bounce/work/.install_done.bounce-1.0._usr_local
sed 's/^X//' >bounce/work/.install_done.bounce-1.0._usr_local << 'END-of-bounce/work/.install_done.bounce-1.0._usr_local'
END-of-bounce/work/.install_done.bounce-1.0._usr_local
echo x - bounce/work/.extract_done.bounce-1.0._usr_local
sed 's/^X//' >bounce/work/.extract_done.bounce-1.0._usr_local << 'END-of-bounce/work/.extract_done.bounce-1.0._usr_local'
END-of-bounce/work/.extract_done.bounce-1.0._usr_local
echo x - bounce/work/bounce.c.orig
sed 's/^X//' >bounce/work/bounce.c.orig << 'END-of-bounce/work/bounce.c.orig'
X/* socket bouncer, by orabidoo  12 Feb '95 
X   using code from mark@cairo.anu.edu.au's general purpose telnet server.
X*/
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <sys/time.h>
X#include <sys/resource.h>
X
X#ifdef _AIX
X#include <sys/select.h>
X#endif
X
X#include <fcntl.h>
X#include <errno.h>
X#include <netinet/in.h>
X#include <netdb.h>
X#include <arpa/inet.h>
X#include <sys/ioctl.h>
X#include <signal.h>
X#include <sys/wait.h>
X
X#define    QLEN           5
X#define    DEFAULT_PORT   1523
X
Xchar sbuf[16384], cbuf[16384];
Xextern int errno;
Xextern char *sys_errlist[];
X
Xvoid sigchld() {
X  signal(SIGCHLD, sigchld);
X  while(waitpid(0, (int *)0, WNOHANG|WUNTRACED)>=0);
X}
X
Xvoid communicate(int sfd, int cfd) {
X    char *chead, *ctail, *shead, *stail;
X    int num, nfd, spos, cpos;
X
X    extern int errno;
X    fd_set rd, wr;
X
X    struct itimerval itime;
X
X    itime.it_interval.tv_sec=0;
X    itime.it_interval.tv_usec=0;
X    itime.it_value.tv_sec=21600;
X    itime.it_value.tv_usec=0;
X    setitimer(ITIMER_REAL,&itime,NULL);
X    /* arbitrary connection time limit: 6 hours (in case the client hangs) */
X
X    chead=ctail=cbuf;
X    cpos=0;
X    shead=stail=sbuf;
X    spos=0;
X    while (1) {
X        FD_ZERO(&rd);
X        FD_ZERO(&wr);
X        if (spos<sizeof(sbuf)-1) 
X	    FD_SET(sfd, &rd);
X        if (ctail>chead)
X	    FD_SET(sfd, &wr);
X        if (cpos<sizeof(cbuf)-1)
X	    FD_SET(cfd, &rd);
X        if (stail>shead)
X	    FD_SET(cfd, &wr);
X        nfd=select(256, &rd, &wr, 0, 0);
X        if (nfd<=0) continue;
X        if (FD_ISSET(sfd, &rd)) {
X            num=read(sfd,stail,sizeof(sbuf)-spos);
X            if ((num==-1) && (errno != EWOULDBLOCK)) return;
X            if (num==0) {
X#ifdef FNDELAY
X		fcntl(sfd,F_SETFL,fcntl(sfd,F_GETFL,0)&~FNDELAY);
X		fcntl(cfd,F_SETFL,fcntl(cfd,F_GETFL,0)&~FNDELAY);
X#endif
X		if (ctail!=chead) write(sfd,chead,ctail-chead);
X		if (stail!=shead) write(cfd,shead,stail-shead);
X		write(cfd,chead,0);
X		return;
X	    }
X	    
X            if (num>0) {
X                spos+=num;
X                stail+=num;
X                if (!--nfd) continue;
X            }
X        }
X        if (FD_ISSET(cfd, &rd)) {
X            num=read(cfd,ctail,sizeof(cbuf)-cpos);
X            if ((num==-1) && (errno != EWOULDBLOCK)) return;
X            if (num==0) {
X#ifdef FNDELAY
X		fcntl(sfd,F_SETFL,fcntl(sfd,F_GETFL,0)&~FNDELAY);
X		fcntl(cfd,F_SETFL,fcntl(cfd,F_GETFL,0)&~FNDELAY);
X#endif
X		if (ctail!=chead) write(sfd,chead,ctail-chead);
X		if (stail!=shead) write(cfd,shead,stail-shead);
X		write(sfd,chead,0);
X		return;
X	    }
X		
X            if (num>0) {
X                cpos+=num;
X                ctail+=num;
X                if (!--nfd) continue;
X            }
X        }
X        if (FD_ISSET(sfd, &wr)) {
X            num=write(sfd,chead,ctail-chead);
X            if ((num==-1) && (errno != EWOULDBLOCK)) return;
X            if (num>0) {
X                chead += num;
X                if (chead==ctail) {
X                    chead=ctail=cbuf;
X                    cpos=0;
X                }
X                if (!--nfd) continue;
X            }
X        }
X        if (FD_ISSET(cfd, &wr)) {
X            num=write(cfd,shead,stail-shead);
X            if ((num==-1) && (errno != EWOULDBLOCK)) return;
X            if (num>0) {
X                shead += num;
X                if (shead==stail) {
X                    shead=stail=sbuf;
X                    spos=0;
X                }
X                if (!--nfd) continue;
X            }
X        }
X    }
X}
X
Xint main(int argc,char *argv[]) {
X    int srv_fd, rem_fd, len, cl_fd, on=1;
X    int myport=DEFAULT_PORT, remoteport;
X    struct sockaddr_in rem_addr, srv_addr, cl_addr;
X    char *myname;
X    struct hostent *hp;
X
X    myname=argv[0];
X    if (argc==5) {
X	if (strcmp(argv[1],"-p")==0) {
X	    if ((myport=atoi(argv[2]))==0) {
X		fprintf(stderr,"Bad port number.\n");
X		exit(-1);
X	    }
X	    argv+=2;
X	    argc-=2;
X	} else {
X	    fprintf(stderr,"Use: %s [-p localport] machine port \n",myname);
X	    exit(-1);
X	}
X    }
X    if (argc!=3) {
X	fprintf(stderr,"Use: %s [-p localport] machine port \n",myname);
X	exit(-1);
X    }
X    if ((remoteport=atoi(argv[2]))<=0) {
X	fprintf(stderr, "Bad remote port number.\n");
X	exit(-1);
X    }
X
X    memset((char *) &rem_addr, 0, sizeof(rem_addr));
X    memset((char *) &srv_addr, 0, sizeof(srv_addr));
X    memset((char *) &cl_addr, 0, sizeof(cl_addr));
X
X    cl_addr.sin_family=AF_INET;
X    cl_addr.sin_port=htons(remoteport);
X    if ((hp=gethostbyname(argv[1]))==NULL) {
X	cl_addr.sin_addr.s_addr=inet_addr(argv[1]);
X	if (cl_addr.sin_addr.s_addr==-1) {
X	    fprintf(stderr, "Unknown host.\n");
X	    exit(-1);
X	}
X    } else
X	cl_addr.sin_addr=*(struct in_addr *)(hp->h_addr_list[0]);
X
X    srv_addr.sin_family=AF_INET;
X    srv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
X    srv_addr.sin_port=htons(myport);
X    srv_fd=socket(PF_INET,SOCK_STREAM,0);
X    if (bind(srv_fd,&srv_addr,sizeof(srv_addr))==-1) {
X	perror("bind");
X        exit(-1);
X    }
X    listen(srv_fd,QLEN);
X
X    signal(SIGCHLD, sigchld);
X    printf("Ready to bounce connections from port %i to %s on port %i\n",
X	   myport, argv[1], remoteport);
X    close(0); close(1); close(2);
X    chdir("/");
X#ifdef TIOCNOTTY
X    if ((rem_fd=open("/dev/tty", O_RDWR)) >= 0) {
X        ioctl(rem_fd, TIOCNOTTY, (char *)0);
X        close(rem_fd);
X    }
X#endif
X    if (fork()) exit(0);
X    while (1) {
X	len=sizeof(rem_addr);
X	rem_fd=accept(srv_fd,&rem_addr,&len);
X	if (rem_fd<0) {
X	  if (errno==EINTR) continue;
X	  exit(-1);
X        }
X	switch(fork()) {
X	  case -1:
X	    /* we're in the background.. no-one to complain to */
X	    break;
X	  case 0:                           /* child process */
X	    close(rem_fd);
X	    break;
X	  default:			    /* parent process */
X	    close(srv_fd);                  /* close original socket */
X	    if ((cl_fd=socket(PF_INET, SOCK_STREAM, 0))<0) {
X		close(rem_fd);
X		exit(-1);
X	    }
X	    if (connect(cl_fd, (struct sockaddr *)&cl_addr, 
X	                sizeof(cl_addr))<0) {
X		close(rem_fd);
X		exit(-1);
X	    }
X	    
X	    setsockopt(cl_fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
X	    setsockopt(rem_fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
X
X	    communicate(cl_fd, rem_fd);
X	    close(rem_fd);
X	    exit(0);
X	}
X    }
X}
X
END-of-bounce/work/bounce.c.orig
echo x - bounce/work/.patch_done.bounce-1.0._usr_local
sed 's/^X//' >bounce/work/.patch_done.bounce-1.0._usr_local << 'END-of-bounce/work/.patch_done.bounce-1.0._usr_local'
END-of-bounce/work/.patch_done.bounce-1.0._usr_local
echo x - bounce/work/.configure_done.bounce-1.0._usr_local
sed 's/^X//' >bounce/work/.configure_done.bounce-1.0._usr_local << 'END-of-bounce/work/.configure_done.bounce-1.0._usr_local'
END-of-bounce/work/.configure_done.bounce-1.0._usr_local
echo x - bounce/work/bounce
sed 's/^X//' >bounce/work/bounce << 'END-of-bounce/work/bounce'
XELF	
X
X
X
+QPutUp9tY0J8#e[^_8#M8#8#Dž Dž Dž
XXV6:E@5jjh%u	Ẽ@Puh
Xv
X
X
X
X
X
X
X
X
X*:JZjzʉډ
X*:JZjz
X
X
X
END-of-bounce/work/bounce
echo x - bounce/work/.build_done.bounce-1.0._usr_local
sed 's/^X//' >bounce/work/.build_done.bounce-1.0._usr_local << 'END-of-bounce/work/.build_done.bounce-1.0._usr_local'
END-of-bounce/work/.build_done.bounce-1.0._usr_local
echo x - bounce/work/.PLIST.mktmp
sed 's/^X//' >bounce/work/.PLIST.mktmp << 'END-of-bounce/work/.PLIST.mktmp'
X@comment $FreeBSD: ports/net/bounce/pkg-plist,v 1.3 2001/11/24 01:32:22 petef Exp $
Xsbin/bounce
END-of-bounce/work/.PLIST.mktmp
echo x - bounce/work/.PLIST.flattened
sed 's/^X//' >bounce/work/.PLIST.flattened << 'END-of-bounce/work/.PLIST.flattened'
X/usr/local/sbin/bounce
END-of-bounce/work/.PLIST.flattened
echo x - bounce/work/.PLIST.setuid
sed 's/^X//' >bounce/work/.PLIST.setuid << 'END-of-bounce/work/.PLIST.setuid'
END-of-bounce/work/.PLIST.setuid
echo x - bounce/work/.PLIST.writable
sed 's/^X//' >bounce/work/.PLIST.writable << 'END-of-bounce/work/.PLIST.writable'
END-of-bounce/work/.PLIST.writable
echo x - bounce/work/.PLIST.objdump
sed 's/^X//' >bounce/work/.PLIST.objdump << 'END-of-bounce/work/.PLIST.objdump'
X
X/usr/local/sbin/bounce:     file format elf32-i386-freebsd
X
XDYNAMIC RELOCATION RECORDS
XOFFSET   TYPE              VALUE 
X0804a8e0 R_386_COPY        __stderrp
X0804a8e4 R_386_COPY        optarg
X0804a8e8 R_386_COPY        optind
X0804a840 R_386_JUMP_SLOT   strcpy
X0804a844 R_386_JUMP_SLOT   waitpid
X0804a848 R_386_JUMP_SLOT   ioctl
X0804a84c R_386_JUMP_SLOT   printf
X0804a850 R_386_JUMP_SLOT   connect
X0804a854 R_386_JUMP_SLOT   __inet_addr
X0804a858 R_386_JUMP_SLOT   setitimer
X0804a85c R_386_JUMP_SLOT   perror
X0804a860 R_386_JUMP_SLOT   malloc
X0804a864 R_386_JUMP_SLOT   socket
X0804a868 R_386_JUMP_SLOT   select
X0804a86c R_386_JUMP_SLOT   accept
X0804a870 R_386_JUMP_SLOT   write
X0804a874 R_386_JUMP_SLOT   fprintf
X0804a878 R_386_JUMP_SLOT   bind
X0804a87c R_386_JUMP_SLOT   chdir
X0804a880 R_386_JUMP_SLOT   setsockopt
X0804a884 R_386_JUMP_SLOT   __error
X0804a888 R_386_JUMP_SLOT   signal
X0804a88c R_386_JUMP_SLOT   read
X0804a890 R_386_JUMP_SLOT   listen
X0804a894 R_386_JUMP_SLOT   fork
X0804a898 R_386_JUMP_SLOT   __inet_ntoa
X0804a89c R_386_JUMP_SLOT   getopt
X0804a8a0 R_386_JUMP_SLOT   _init_tls
X0804a8a4 R_386_JUMP_SLOT   syslog
X0804a8a8 R_386_JUMP_SLOT   gethostbyname
X0804a8ac R_386_JUMP_SLOT   atexit
X0804a8b0 R_386_JUMP_SLOT   fwrite
X0804a8b4 R_386_JUMP_SLOT   exit
X0804a8b8 R_386_JUMP_SLOT   atoi
X0804a8bc R_386_JUMP_SLOT   open
X0804a8c0 R_386_JUMP_SLOT   fcntl
X0804a8c4 R_386_JUMP_SLOT   close
X
X
END-of-bounce/work/.PLIST.objdump
echo x - bounce/work/bounce.c
sed 's/^X//' >bounce/work/bounce.c << 'END-of-bounce/work/bounce.c'
X/* socket bouncer, by orabidoo  12 Feb '95 
X   using code from mark@cairo.anu.edu.au's general purpose telnet server.
X   Hacked by scot@poptart.org (April 1999) to allow a local bind address
X   and syslog logging.
X*/
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <sys/time.h>
X#include <sys/resource.h>
X
X#ifdef _AIX
X#include <sys/select.h>
X#endif
X
X#include <fcntl.h>
X#include <errno.h>
X#include <netinet/in.h>
X#include <netdb.h>
X#include <arpa/inet.h>
X#include <sys/ioctl.h>
X#include <signal.h>
X#include <sys/wait.h>
X#include <unistd.h>
X#include <syslog.h>
X#include <stdlib.h>
X#include <string.h>
X
X#define    QLEN           5
X#define    DEFAULT_PORT   1523
X
Xchar sbuf[16384], cbuf[16384];
X
Xvoid sigchld() {
X  signal(SIGCHLD, sigchld);
X  while(waitpid(0, (int *)0, WNOHANG|WUNTRACED)>=0);
X}
X
Xvoid communicate(int sfd, int cfd) {
X    char *chead, *ctail, *shead, *stail;
X    int num, nfd, spos, cpos;
X
X    extern int errno;
X    fd_set rd, wr;
X
X    struct itimerval itime;
X
X    itime.it_interval.tv_sec=0;
X    itime.it_interval.tv_usec=0;
X    itime.it_value.tv_sec=21600;
X    itime.it_value.tv_usec=0;
X    setitimer(ITIMER_REAL,&itime,NULL);
X    /* arbitrary connection time limit: 6 hours (in case the client hangs) */
X
X    chead=ctail=cbuf;
X    cpos=0;
X    shead=stail=sbuf;
X    spos=0;
X    while (1) {
X        FD_ZERO(&rd);
X        FD_ZERO(&wr);
X        if (spos<sizeof(sbuf)-1) 
X	    FD_SET(sfd, &rd);
X        if (ctail>chead)
X	    FD_SET(sfd, &wr);
X        if (cpos<sizeof(cbuf)-1)
X	    FD_SET(cfd, &rd);
X        if (stail>shead)
X	    FD_SET(cfd, &wr);
X        nfd=select(256, &rd, &wr, 0, 0);
X        if (nfd<=0) continue;
X        if (FD_ISSET(sfd, &rd)) {
X            num=read(sfd,stail,sizeof(sbuf)-spos);
X            if ((num==-1) && (errno != EWOULDBLOCK)) return;
X            if (num==0) {
X#ifdef FNDELAY
X		fcntl(sfd,F_SETFL,fcntl(sfd,F_GETFL,0)&~FNDELAY);
X		fcntl(cfd,F_SETFL,fcntl(cfd,F_GETFL,0)&~FNDELAY);
X#endif
X		if (ctail!=chead) write(sfd,chead,ctail-chead);
X		if (stail!=shead) write(cfd,shead,stail-shead);
X		write(cfd,chead,0);
X		return;
X	    }
X	    
X            if (num>0) {
X                spos+=num;
X                stail+=num;
X                if (!--nfd) continue;
X            }
X        }
X        if (FD_ISSET(cfd, &rd)) {
X            num=read(cfd,ctail,sizeof(cbuf)-cpos);
X            if ((num==-1) && (errno != EWOULDBLOCK)) return;
X            if (num==0) {
X#ifdef FNDELAY
X		fcntl(sfd,F_SETFL,fcntl(sfd,F_GETFL,0)&~FNDELAY);
X		fcntl(cfd,F_SETFL,fcntl(cfd,F_GETFL,0)&~FNDELAY);
X#endif
X		if (ctail!=chead) write(sfd,chead,ctail-chead);
X		if (stail!=shead) write(cfd,shead,stail-shead);
X		write(sfd,chead,0);
X		return;
X	    }
X		
X            if (num>0) {
X                cpos+=num;
X                ctail+=num;
X                if (!--nfd) continue;
X            }
X        }
X        if (FD_ISSET(sfd, &wr)) {
X            num=write(sfd,chead,ctail-chead);
X            if ((num==-1) && (errno != EWOULDBLOCK)) return;
X            if (num>0) {
X                chead += num;
X                if (chead==ctail) {
X                    chead=ctail=cbuf;
X                    cpos=0;
X                }
X                if (!--nfd) continue;
X            }
X        }
X        if (FD_ISSET(cfd, &wr)) {
X            num=write(cfd,shead,stail-shead);
X            if ((num==-1) && (errno != EWOULDBLOCK)) return;
X            if (num>0) {
X                shead += num;
X                if (shead==stail) {
X                    shead=stail=sbuf;
X                    spos=0;
X                }
X                if (!--nfd) continue;
X            }
X        }
X    }
X}
X
Xint main(int argc,char *argv[]) {
X    int srv_fd, rem_fd, len, cl_fd, on=1;
X    int myport=DEFAULT_PORT, remoteport;
X    struct sockaddr_in rem_addr, srv_addr, cl_addr;
X    char *myname;
X    struct hostent *hp, *hpLocal;
X
X    extern char *optarg;
X    extern int optind;
X    char *hostname = NULL;
X    char ch;
X
X    myname=argv[0];
X
X    /* Process arguments */
X
X    while( (ch = getopt(argc, argv, "p:a:")) != -1  ) {
X      switch(ch) { 
X      case 'a':
X	hostname = malloc( strlen(optarg) + 1);
X	if( !hostname ) {
X	  fprintf( stderr, "Can't allocate memory!\n" );
X	  exit(-1);
X	}
X	strcpy( hostname, optarg );
X	break;
X
X      case 'p':
X	if ((myport=atoi(optarg))==0) {
X	  fprintf(stderr,"Bad port number.\n");
X	  exit(-1);
X	}
X	break;
X      }
X    }
X
X    argc -= optind;
X    argv += optind;
X
X    if (argc!=2) {
X	fprintf(stderr,"Use: %s [-a localaddr] [-p localport] machine port \n",myname);
X	exit(-1);
X    }
X    if ((remoteport=atoi(argv[1]))<=0) {
X	fprintf(stderr, "Bad remote port number.\n");
X	exit(-1);
X    }
X
X    memset((char *) &rem_addr, 0, sizeof(rem_addr));
X    memset((char *) &srv_addr, 0, sizeof(srv_addr));
X    memset((char *) &cl_addr, 0, sizeof(cl_addr));
X
X    cl_addr.sin_family=AF_INET;
X    cl_addr.sin_port=htons(remoteport);
X    if ((hp=gethostbyname(argv[0]))==NULL) {
X	cl_addr.sin_addr.s_addr=inet_addr(argv[0]);
X	if (cl_addr.sin_addr.s_addr==-1) {
X	    fprintf(stderr, "Unknown host.\n");
X	    exit(-1);
X	}
X    } else
X	cl_addr.sin_addr=*(struct in_addr *)(hp->h_addr_list[0]);
X
X    if( hostname ) {
X      if ((hpLocal=gethostbyname(hostname))==NULL) {
X	srv_addr.sin_addr.s_addr=inet_addr(hostname);
X	if (srv_addr.sin_addr.s_addr==-1) {
X	    fprintf(stderr, "Unknown host: %s\n", hostname);
X	    exit(-1);
X	}
X    } else
X	srv_addr.sin_addr=*(struct in_addr *)(hp->h_addr_list[0]);
X    }
X
X    srv_addr.sin_family=AF_INET;
X    /*    srv_addr.sin_addr.s_addr=htonl(INADDR_ANY); */
X    srv_addr.sin_port=htons(myport);
X    srv_fd=socket(PF_INET,SOCK_STREAM,0);
X    if (bind(srv_fd,(struct sockaddr *)&srv_addr,sizeof(srv_addr))==-1) {
X	perror("bind");
X        exit(-1);
X    }
X    listen(srv_fd,QLEN);
X
X    signal(SIGCHLD, sigchld);
X    printf("Ready to bounce connections from port %i to %s on port %i\n",
X	   myport, argv[0], remoteport);
X    close(0); close(1); close(2);
X    chdir("/");
X#ifdef TIOCNOTTY
X    if ((rem_fd=open("/dev/tty", O_RDWR)) >= 0) {
X        ioctl(rem_fd, TIOCNOTTY, (char *)0);
X        close(rem_fd);
X    }
X#endif
X    if (fork()) exit(0);
X    while (1) {
X	len=sizeof(rem_addr);
X	rem_fd=accept(srv_fd,(struct sockaddr *)&rem_addr,&len);
X	if (rem_fd<0) {
X	  if (errno==EINTR) continue;
X	  exit(-1);
X        }
X	syslog( LOG_NOTICE, "connection from %s to local port %i.  Bouncing to %s, %i",
X		inet_ntoa(rem_addr.sin_addr), myport, argv[0], remoteport );
X	switch(fork()) {
X	  case -1:
X	    /* we're in the background.. no-one to complain to */
X	    break;
X	  case 0:                           /* child process */
X	    close(rem_fd);
X	    break;
X	  default:			    /* parent process */
X	    close(srv_fd);                  /* close original socket */
X	    if ((cl_fd=socket(PF_INET, SOCK_STREAM, 0))<0) {
X		close(rem_fd);
X		exit(-1);
X	    }
X	    if (connect(cl_fd, (struct sockaddr *)&cl_addr, 
X	                sizeof(cl_addr))<0) {
X		close(rem_fd);
X		exit(-1);
X	    }
X	    
X	    setsockopt(cl_fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
X	    setsockopt(rem_fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
X
X	    communicate(cl_fd, rem_fd);
X	    close(rem_fd);
X	    exit(0);
X	}
X    }
X}
X
END-of-bounce/work/bounce.c
echo c - bounce/files
mkdir -p bounce/files > /dev/null 2>&1
echo x - bounce/files/patch-01
sed 's/^X//' >bounce/files/patch-01 << 'END-of-bounce/files/patch-01'
X--- bounce.c.orig	Fri Jan 14 20:47:39 2000
X+++ bounce.c	Fri Jan 14 20:48:56 2000
X@@ -1,5 +1,7 @@
X /* socket bouncer, by orabidoo  12 Feb '95 
X    using code from mark@cairo.anu.edu.au's general purpose telnet server.
X+   Hacked by scot@poptart.org (April 1999) to allow a local bind address
X+   and syslog logging.
X */
X 
X #include <stdio.h>
X@@ -20,13 +22,15 @@
X #include <sys/ioctl.h>
X #include <signal.h>
X #include <sys/wait.h>
X+#include <unistd.h>
X+#include <syslog.h>
X+#include <stdlib.h>
X+#include <string.h>
X 
X #define    QLEN           5
X #define    DEFAULT_PORT   1523
X 
X char sbuf[16384], cbuf[16384];
X-extern int errno;
X-extern char *sys_errlist[];
X 
X void sigchld() {
X   signal(SIGCHLD, sigchld);
X@@ -138,27 +142,45 @@
X     int myport=DEFAULT_PORT, remoteport;
X     struct sockaddr_in rem_addr, srv_addr, cl_addr;
X     char *myname;
X-    struct hostent *hp;
X+    struct hostent *hp, *hpLocal;
X+
X+    extern char *optarg;
X+    extern int optind;
X+    char *hostname = NULL;
X+    char ch;
X 
X     myname=argv[0];
X-    if (argc==5) {
X-	if (strcmp(argv[1],"-p")==0) {
X-	    if ((myport=atoi(argv[2]))==0) {
X-		fprintf(stderr,"Bad port number.\n");
X-		exit(-1);
X-	    }
X-	    argv+=2;
X-	    argc-=2;
X-	} else {
X-	    fprintf(stderr,"Use: %s [-p localport] machine port \n",myname);
X-	    exit(-1);
X+
X+    /* Process arguments */
X+
X+    while( (ch = getopt(argc, argv, "p:a:")) != -1  ) {
X+      switch(ch) { 
X+      case 'a':
X+	hostname = malloc( strlen(optarg) + 1);
X+	if( !hostname ) {
X+	  fprintf( stderr, "Can't allocate memory!\n" );
X+	  exit(-1);
X+	}
X+	strcpy( hostname, optarg );
X+	break;
X+
X+      case 'p':
X+	if ((myport=atoi(optarg))==0) {
X+	  fprintf(stderr,"Bad port number.\n");
X+	  exit(-1);
X 	}
X+	break;
X+      }
X     }
X-    if (argc!=3) {
X-	fprintf(stderr,"Use: %s [-p localport] machine port \n",myname);
X+
X+    argc -= optind;
X+    argv += optind;
X+
X+    if (argc!=2) {
X+	fprintf(stderr,"Use: %s [-a localaddr] [-p localport] machine port \n",myname);
X 	exit(-1);
X     }
X-    if ((remoteport=atoi(argv[2]))<=0) {
X+    if ((remoteport=atoi(argv[1]))<=0) {
X 	fprintf(stderr, "Bad remote port number.\n");
X 	exit(-1);
X     }
X@@ -169,8 +191,8 @@
X 
X     cl_addr.sin_family=AF_INET;
X     cl_addr.sin_port=htons(remoteport);
X-    if ((hp=gethostbyname(argv[1]))==NULL) {
X-	cl_addr.sin_addr.s_addr=inet_addr(argv[1]);
X+    if ((hp=gethostbyname(argv[0]))==NULL) {
X+	cl_addr.sin_addr.s_addr=inet_addr(argv[0]);
X 	if (cl_addr.sin_addr.s_addr==-1) {
X 	    fprintf(stderr, "Unknown host.\n");
X 	    exit(-1);
X@@ -178,11 +200,22 @@
X     } else
X 	cl_addr.sin_addr=*(struct in_addr *)(hp->h_addr_list[0]);
X 
X+    if( hostname ) {
X+      if ((hpLocal=gethostbyname(hostname))==NULL) {
X+	srv_addr.sin_addr.s_addr=inet_addr(hostname);
X+	if (srv_addr.sin_addr.s_addr==-1) {
X+	    fprintf(stderr, "Unknown host: %s\n", hostname);
X+	    exit(-1);
X+	}
X+    } else
X+	srv_addr.sin_addr=*(struct in_addr *)(hp->h_addr_list[0]);
X+    }
X+
X     srv_addr.sin_family=AF_INET;
X-    srv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
X+    /*    srv_addr.sin_addr.s_addr=htonl(INADDR_ANY); */
X     srv_addr.sin_port=htons(myport);
X     srv_fd=socket(PF_INET,SOCK_STREAM,0);
X-    if (bind(srv_fd,&srv_addr,sizeof(srv_addr))==-1) {
X+    if (bind(srv_fd,(struct sockaddr *)&srv_addr,sizeof(srv_addr))==-1) {
X 	perror("bind");
X         exit(-1);
X     }
X@@ -190,7 +223,7 @@
X 
X     signal(SIGCHLD, sigchld);
X     printf("Ready to bounce connections from port %i to %s on port %i\n",
X-	   myport, argv[1], remoteport);
X+	   myport, argv[0], remoteport);
X     close(0); close(1); close(2);
X     chdir("/");
X #ifdef TIOCNOTTY
X@@ -202,11 +235,13 @@
X     if (fork()) exit(0);
X     while (1) {
X 	len=sizeof(rem_addr);
X-	rem_fd=accept(srv_fd,&rem_addr,&len);
X+	rem_fd=accept(srv_fd,(struct sockaddr *)&rem_addr,&len);
X 	if (rem_fd<0) {
X 	  if (errno==EINTR) continue;
X 	  exit(-1);
X         }
X+	syslog( LOG_NOTICE, "connection from %s to local port %i.  Bouncing to %s, %i",
X+		inet_ntoa(rem_addr.sin_addr), myport, argv[0], remoteport );
X 	switch(fork()) {
X 	  case -1:
X 	    /* we're in the background.. no-one to complain to */
END-of-bounce/files/patch-01
echo x - bounce/pkg-descr
sed 's/^X//' >bounce/pkg-descr << 'END-of-bounce/pkg-descr'
XA little program to bounce tcp connections to another machine/port.
XBy default it listens on port 1523.
X
XAuthor: Roger Espel Llima
XWWW: http://www.iagora.com/~espel/hacks.html
END-of-bounce/pkg-descr
echo x - bounce/Makefile
sed 's/^X//' >bounce/Makefile << 'END-of-bounce/Makefile'
X# ex:ts=8
X# Ports collection makefile for:  bounce
X# Date created:			  Mon Dec 23, 1998
X# Whom:				  David O'Brien (obrien@NUXI.com)
X#
X# $FreeBSD: ports/net/bounce/Makefile,v 1.17 2003/02/20 18:50:52 knu Exp $
X#
X
XPORTNAME=	bounce
XPORTVERSION=	1.0
XCATEGORIES=	net security
XMASTER_SITES=	http://www.iagora.com/~espel/bounce.c \
X		${MASTER_SITE_LOCAL}
XMASTER_SITE_SUBDIR=	obrien
XDISTNAME=	bounce
XEXTRACT_SUFX=	.c
X
XMAINTAINER=	matt@efs.org
XCOMMENT=	Bounce tcp connections to another machine/port
X
XNO_WRKSUBDIR=	yes
X
Xdo-extract:
X	@${MKDIR} ${WRKDIR}
X	@${CP} ${DISTDIR}/${DISTFILES} ${WRKDIR}
X
Xdo-build:
X	(cd ${WRKSRC} && ${CC} ${CFLAGS} -o ${DISTNAME} ${DISTNAME}.c)
X
Xdo-install:
X	${INSTALL_PROGRAM} ${WRKSRC}/${DISTNAME} ${PREFIX}/sbin
X
X.include <bsd.port.mk>
END-of-bounce/Makefile
echo x - bounce/pkg-plist
sed 's/^X//' >bounce/pkg-plist << 'END-of-bounce/pkg-plist'
X@comment $FreeBSD: ports/net/bounce/pkg-plist,v 1.3 2001/11/24 01:32:22 petef Exp $
Xsbin/bounce
END-of-bounce/pkg-plist
echo x - bounce/distinfo
sed 's/^X//' >bounce/distinfo << 'END-of-bounce/distinfo'
XMD5 (bounce.c) = 9ec7c53022f4c6a0559c7bbcc08080f1
XSHA256 (bounce.c) = 2f2174556c55dc327bb109ad1a933b378666df103b08680763acf953c0013652
XSIZE (bounce.c) = 6189
END-of-bounce/distinfo
exit

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200605250204.k4P24BMJ082107>