1 diff -u srelay-0.4.6.orig/main.c srelay-0.4.6/main.c
2 --- srelay-0.4.6.orig/main.c 2003-03-26 20:45:12.000000000 +0000
3 +++ srelay-0.4.6/main.c 2007-08-09 13:53:30.000000000 +0100
5 char *ident = "srelay";
6 char *pidfile = PIDFILE;
7 char *pwdfile = PWDFILE;
8 +char *bindtodevice = NULL;
13 fprintf(stderr, "options:\n"
14 "\t-c file\tconfig file\n"
15 "\t-i i/f\tlisten interface IP[:PORT]\n"
16 +#ifdef SO_BINDTODEVICE
17 + "\t-J i/f\toutbound interface name\n"
19 "\t-m num\tmax child/thread\n"
20 "\t-o min\tidle timeout minutes\n"
21 "\t-p file\tpid file\n"
26 - while((ch = getopt(ac, av, "a:c:i:m:o:p:u:frstbvh?")) != -1)
27 + while((ch = getopt(ac, av, "a:c:i:J:m:o:p:u:frstbvh?")) != -1)
35 +#ifdef SO_BINDTODEVICE
37 + if (optarg != NULL) {
38 + bindtodevice = strdup(optarg);
45 idle_timeout = atol(optarg);
46 diff -u srelay-0.4.6.orig/socks.c srelay-0.4.6/socks.c
47 --- srelay-0.4.6.orig/socks.c 2003-04-13 22:13:25.000000000 +0100
48 +++ srelay-0.4.6/socks.c 2007-08-09 14:44:24.000000000 +0100
53 +#ifdef SO_BINDTODEVICE
55 +static int do_bindtodevice(int cs, char *dev)
58 + struct ifreq interface;
60 + strncpy(interface.ifr_name, dev, IFNAMSIZ);
61 + setreuid(PROCUID, 0);
62 + rc = setsockopt(cs, SOL_SOCKET, SO_BINDTODEVICE,
63 + (char *)&interface, sizeof(interface));
64 + setreuid(0, PROCUID);
66 + msg_out(crit, "setsockopt SO_BINDTODEVICE(%s) failed: %d", dev, errno);
71 int socks_direct_conn(int ver, struct socks_req *req)
74 @@ -1037,6 +1055,14 @@
78 +#ifdef SO_BINDTODEVICE
79 + if (bindtodevice && do_bindtodevice(cs, bindtodevice) < 0) {
86 if (connect(cs, res->ai_addr, res->ai_addrlen) < 0) {
89 @@ -1096,6 +1122,14 @@
93 +#ifdef SO_BINDTODEVICE
94 + if (bindtodevice && do_bindtodevice(acs, bindtodevice) < 0) {
95 + GEN_ERR_REP(req->s, ver);
101 if (bind_sock(acs, req, &ba) != 0) {
102 GEN_ERR_REP(req->s, ver);
104 @@ -1351,6 +1385,14 @@
108 +#ifdef SO_BINDTODEVICE
109 + if (bindtodevice && do_bindtodevice(cs, bindtodevice) < 0) {
110 + save_errno = errno;
116 if (connect(cs, res->ai_addr, res->ai_addrlen) < 0) {
119 diff -u srelay-0.4.6.orig/srelay.h srelay-0.4.6/srelay.h
120 --- srelay-0.4.6.orig/srelay.h 2003-04-14 06:36:15.000000000 +0100
121 +++ srelay-0.4.6/srelay.h 2007-08-09 13:46:06.000000000 +0100
124 extern char *pidfile;
125 extern char *pwdfile;
126 +extern char *bindtodevice;
127 extern int max_child;
128 extern int cur_child;
129 extern char method_tab[];