ports/124062: [patch] net/bounce: command line option -b does not work
Eugene Grosbein
eugen at kuzbass.ru
Wed May 28 12:20:01 UTC 2008
>Number: 124062
>Category: ports
>Synopsis: [patch] net/bounce: command line option -b does not work
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed May 28 12:20:00 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: Eugene Grosbein
>Release: FreeBSD 4.11-STABLE i386
>Organization:
Svyaz-Service JSC
>Environment:
>Description:
PR: ports/96263 introduced command line option -b
to bind client socket to an address for outgoing connection.
It did not allow to bind it to address differing
from server address, though. The code in files/patch-02
uses 'fallthrough' featue of C 'case' statement.
Next port's PR: ports/113069 broke this code.
>How-To-Repeat:
bounce -a 192.168.0.1 -b 100.100.100.100 -p 10000 remotehost 1000
This won't connect to remotehost from 100.100.100.100,
it rather connect from 192.168.0.1, that's bad.
>Fix:
Recover breakage from ports/113069 and, at last,
make it possible to connect using specified address
that differs from server one. This patch corrects
files/patch-02 to the kind it should be at first.
The file files/patch-03 is touched just due to context changes,
its own affects are the same.
diff -urN bounce.orig/Makefile bounce/Makefile
--- bounce.orig/Makefile 2007-09-01 06:14:30.000000000 +0800
+++ bounce/Makefile 2008-05-28 20:03:37.000000000 +0800
@@ -8,7 +8,7 @@
PORTNAME= bounce
PORTVERSION= 1.0
-PORTREVISION= 6
+PORTREVISION= 7
CATEGORIES= net security
MASTER_SITES= http://www.iagora.com/~espel/ \
${MASTER_SITE_LOCAL}
diff -urN bounce.orig/files/patch-02 bounce/files/patch-02
--- bounce.orig/files/patch-02 2006-07-08 06:32:20.000000000 +0800
+++ bounce/files/patch-02 2008-05-28 19:46:55.000000000 +0800
@@ -1,15 +1,24 @@
--- bounce.c.orig Fri Jun 2 12:58:37 2006
+++ bounce.c Fri Jun 2 13:25:28 2006
-@@ -138,7 +138,7 @@
+@@ -138,23 +138,32 @@
}
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;
+- struct sockaddr_in rem_addr, srv_addr, cl_addr;
++ struct sockaddr_in rem_addr, srv_addr, cl_addr, src_addr;
char *myname;
-@@ -153,8 +153,9 @@
+ struct hostent *hp, *hpLocal;
+
+ extern char *optarg;
+ extern int optind;
+ char *hostname = NULL;
++ char *sourcename = NULL;
+ char ch;
+
+ myname=argv[0];
/* Process arguments */
@@ -17,10 +26,17 @@
+ while( (ch = getopt(argc, argv, "p:a:b:")) != -1 ) {
switch(ch) {
+ case 'b': b = 1;
++ sourcename = malloc( strlen(optarg) + 1);
++ if( !sourcename ) {
++ fprintf( stderr, "Can't allocate memory!\n" );
++ exit(-1);
++ }
++ strcpy( sourcename, optarg );
++ break;
case 'a':
hostname = malloc( strlen(optarg) + 1);
if( !hostname ) {
-@@ -177,7 +178,7 @@
+@@ -177,7 +186,7 @@
argv += optind;
if (argc!=2) {
@@ -29,7 +45,34 @@
exit(-1);
}
if ((remoteport=atoi(argv[1]))<=0) {
-@@ -220,6 +221,7 @@
+@@ -188,6 +197,7 @@
+ memset((char *) &rem_addr, 0, sizeof(rem_addr));
+ memset((char *) &srv_addr, 0, sizeof(srv_addr));
+ memset((char *) &cl_addr, 0, sizeof(cl_addr));
++ memset((char *) &src_addr, 0, sizeof(src_addr));
+
+ cl_addr.sin_family=AF_INET;
+ cl_addr.sin_port=htons(remoteport);
+@@ -211,6 +221,18 @@
+ srv_addr.sin_addr=*(struct in_addr *)(hp->h_addr_list[0]);
+ }
+
++ if( sourcename ) {
++ if ((hpLocal=gethostbyname(sourcename))==NULL) {
++ src_addr.sin_addr.s_addr=inet_addr(sourcename);
++ if (src_addr.sin_addr.s_addr==-1) {
++ fprintf(stderr, "Unknown host: %s\n", sourcename);
++ exit(-1);
++ }
++ } else
++ src_addr.sin_addr=*(struct in_addr *)(hp->h_addr_list[0]);
++ }
++ src_addr.sin_family=AF_INET;
++
+ srv_addr.sin_family=AF_INET;
+ /* srv_addr.sin_addr.s_addr=htonl(INADDR_ANY); */
+ srv_addr.sin_port=htons(myport);
+@@ -220,6 +242,7 @@
exit(-1);
}
listen(srv_fd,QLEN);
@@ -37,16 +80,16 @@
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) {
+@@ -255,6 +278,12 @@
close(rem_fd);
exit(-1);
-+ }
-+ if (b) {
-+ if (bind(cl_fd,(struct sockaddr *)&srv_addr,sizeof(srv_addr))<0) {
+ }
++ if (b) { src_addr.sin_port=0;
++ if (bind(cl_fd,(struct sockaddr *)&src_addr,sizeof(src_addr))<0) {
+ close(rem_fd);
+ exit(-1);
+ }
- }
++ }
if (connect(cl_fd, (struct sockaddr *)&cl_addr,
sizeof(cl_addr))<0) {
+ close(rem_fd);
diff -urN bounce.orig/files/patch-03 bounce/files/patch-03
--- bounce.orig/files/patch-03 2007-06-06 19:24:47.000000000 +0800
+++ bounce/files/patch-03 2008-05-28 19:27:20.000000000 +0800
@@ -7,9 +7,9 @@
- int srv_fd, rem_fd, len, cl_fd, on=1, b=0;
+ int srv_fd, rem_fd, len, cl_fd, on=1, b=0, d=0;
int myport=DEFAULT_PORT, remoteport;
- struct sockaddr_in rem_addr, srv_addr, cl_addr;
+ struct sockaddr_in rem_addr, srv_addr, cl_addr, src_addr;
char *myname;
-@@ -153,9 +153,10 @@
+@@ -154,7 +154,7 @@
/* Process arguments */
@@ -17,11 +17,16 @@
+ while( (ch = getopt(argc, argv, "p:a:b:d")) != -1 ) {
switch(ch) {
case 'b': b = 1;
+ sourcename = malloc( strlen(optarg) + 1);
+@@ -173,6 +173,7 @@
+ strcpy( hostname, optarg );
+ break;
+
+ case 'd': d = 1; break;
- case 'a':
- hostname = malloc( strlen(optarg) + 1);
- if( !hostname ) {
-@@ -178,7 +179,7 @@
+ case 'p':
+ if ((myport=atoi(optarg))==0) {
+ fprintf(stderr,"Bad port number.\n");
+@@ -186,7 +187,7 @@
argv += optind;
if (argc!=2) {
@@ -30,15 +35,15 @@
exit(-1);
}
if ((remoteport=atoi(argv[1]))<=0) {
-@@ -261,6 +262,11 @@
- if (bind(cl_fd,(struct sockaddr *)&srv_addr,sizeof(srv_addr))<0) {
- close(rem_fd);
+@@ -284,6 +285,11 @@
exit(-1);
-+ }
-+ }
+ }
+ }
+ if (d) {
+ if ((hp=gethostbyname(argv[0]))!=NULL) {
+ cl_addr.sin_addr=*(struct in_addr *)(hp->h_addr_list[0]);
- }
- }
++ }
++ }
if (connect(cl_fd, (struct sockaddr *)&cl_addr,
+ sizeof(cl_addr))<0) {
+ close(rem_fd);
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list