1 Index: srelay-0.4.6/main.c
2 ===================================================================
3 --- srelay-0.4.6.orig/main.c 2008-02-28 13:21:30.000000000 +0100
4 +++ srelay-0.4.6/main.c 2008-02-28 13:21:30.000000000 +0100
6 char *ident = "srelay";
7 char *pidfile = PIDFILE;
8 char *pwdfile = PWDFILE;
9 +char *bindtodevice = NULL;
14 fprintf(stderr, "options:\n"
15 "\t-c file\tconfig file\n"
16 "\t-i i/f\tlisten interface IP[:PORT]\n"
17 +#ifdef SO_BINDTODEVICE
18 + "\t-J i/f\toutbound interface name\n"
20 "\t-m num\tmax child/thread\n"
21 "\t-o min\tidle timeout minutes\n"
22 "\t-p file\tpid file\n"
25 openlog("srelay", LOG_PID, LOG_DAEMON);
27 - while((ch = getopt(ac, av, "a:c:i:m:o:p:u:frstbvh?")) != -1)
28 + while((ch = getopt(ac, av, "a:c:i:J:m:o:p:u:frstbvh?")) != -1)
36 +#ifdef SO_BINDTODEVICE
38 + if (optarg != NULL) {
39 + bindtodevice = strdup(optarg);
46 idle_timeout = atol(optarg);
47 Index: srelay-0.4.6/socks.c
48 ===================================================================
49 --- srelay-0.4.6.orig/socks.c 2008-02-28 13:21:29.000000000 +0100
50 +++ srelay-0.4.6/socks.c 2008-02-28 13:21:30.000000000 +0100
55 +#ifdef SO_BINDTODEVICE
57 +static int do_bindtodevice(int cs, char *dev)
60 + struct ifreq interface;
62 + strncpy(interface.ifr_name, dev, IFNAMSIZ);
63 + setreuid(PROCUID, 0);
64 + rc = setsockopt(cs, SOL_SOCKET, SO_BINDTODEVICE,
65 + (char *)&interface, sizeof(interface));
66 + setreuid(0, PROCUID);
68 + msg_out(crit, "setsockopt SO_BINDTODEVICE(%s) failed: %d", dev, errno);
73 int socks_direct_conn(int ver, struct socks_req *req)
76 @@ -1037,6 +1055,14 @@
80 +#ifdef SO_BINDTODEVICE
81 + if (bindtodevice && do_bindtodevice(cs, bindtodevice) < 0) {
88 if (connect(cs, res->ai_addr, res->ai_addrlen) < 0) {
91 @@ -1096,6 +1122,14 @@
95 +#ifdef SO_BINDTODEVICE
96 + if (bindtodevice && do_bindtodevice(acs, bindtodevice) < 0) {
97 + GEN_ERR_REP(req->s, ver);
103 if (bind_sock(acs, req, &ba) != 0) {
104 GEN_ERR_REP(req->s, ver);
106 @@ -1351,6 +1385,14 @@
110 +#ifdef SO_BINDTODEVICE
111 + if (bindtodevice && do_bindtodevice(cs, bindtodevice) < 0) {
112 + save_errno = errno;
118 if (connect(cs, res->ai_addr, res->ai_addrlen) < 0) {
121 Index: srelay-0.4.6/srelay.h
122 ===================================================================
123 --- srelay-0.4.6.orig/srelay.h 2008-02-28 13:21:29.000000000 +0100
124 +++ srelay-0.4.6/srelay.h 2008-02-28 13:21:30.000000000 +0100
127 extern char *pidfile;
128 extern char *pwdfile;
129 +extern char *bindtodevice;
130 extern int max_child;
131 extern int cur_child;
132 extern char method_tab[];