Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Consult the man page for details.
-t, --timeout=SEC Set timeout to SEC seconds, default off (0)
-v, --version Show program version
-x, --connect=STR CONNECT string passed to proxy server
-O, --oob Redirect Out-of-band data also

Traffic Shaping:
-m, --max-bandwidth=BPS Limit the bandwidth to BPS bits/second
Expand Down
31 changes: 29 additions & 2 deletions redir.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int timeout = 0;
int loglevel = LOG_NOTICE;
int do_syslog = 0;
int transproxy = 0;
int oob = 0;

char *target_addr = NULL;
int target_port = 0;
Expand Down Expand Up @@ -160,6 +161,7 @@ static int usage(int code)
" -t, --timeout=SEC Set timeout to SEC seconds, default off (0)\n"
" -v, --version Show program version\n"
" -x, --connect=STR CONNECT string passed to proxy server\n"
" -O, --oob Redirect Out-of-band data also\n"
#ifdef COMPAT_OPTIONS
"\n"
"Compatibility options:\n"
Expand Down Expand Up @@ -257,6 +259,7 @@ static void parse_args(int argc, char *argv[])
{"ftp", required_argument, 0, 'f'},
#endif
{"transproxy", no_argument, 0, 'p'},
{"oob", no_argument, 0, 'O'},
#ifndef NO_SHAPER
{"bufsize", required_argument, 0, 'z'},
{"max_bandwidth", required_argument, 0, 'm'}, /* compat */
Expand Down Expand Up @@ -292,7 +295,7 @@ static void parse_args(int argc, char *argv[])
#define SHAPER_OPTS ""
#endif
prognm = progname(argv[0]);
while ((opt = getopt_long(argc, argv, "b:hiI:l:npst:vx:" FTP_OPTS SHAPER_OPTS, long_options, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, "b:hiI:l:npst:vx:O" FTP_OPTS SHAPER_OPTS, long_options, NULL)) != -1) {
switch (opt) {
case 'b':
bind_addr = optarg;
Expand Down Expand Up @@ -371,6 +374,11 @@ static void parse_args(int argc, char *argv[])
case 'x':
connect_str = optarg;
break;

case 'O':
oob++;
break;

#ifdef COMPAT_OPTIONS
case 128: /* --caddr=1.2.3.4 */
compat = 1;
Expand Down Expand Up @@ -599,21 +607,40 @@ static void copyloop(int insock, int outsock, int timeout_secs)
syslog(LOG_DEBUG, "Entering copyloop() - timeout is %d", timeout_secs);
while (1) {
fd_set iofds;
fd_set exfds;

FD_ZERO(&iofds);
FD_SET(insock, &iofds);
FD_SET(outsock, &iofds);

if (oob) {
FD_ZERO(&exfds);
FD_SET(insock, &exfds);
FD_SET(outsock, &exfds);
}

/* Set up timeout, Linux returns seconds left in this structure
* so we have to reset it before each select(). */
timeout.tv_sec = timeout_secs;
timeout.tv_usec = 0;

if (select(max_fd + 1, &iofds, NULL, NULL, (timeout_secs ? &timeout : NULL)) <= 0) {
if (select(max_fd + 1, &iofds, NULL, (oob ? &exfds : NULL), (timeout_secs ? &timeout : NULL)) <= 0) {
syslog(LOG_DEBUG, "Connection timeout: %d sec", timeout_secs);
break;
}

if (oob && FD_ISSET(insock, &exfds)) {
bytes = recv(insock, buf, bufsize, MSG_OOB);
if (bytes > 0 && send(outsock, buf, bytes, MSG_OOB) != bytes)
break;
}

if (oob && FD_ISSET(outsock, &exfds)) {
bytes = recv(outsock, buf, bufsize, MSG_OOB);
if (bytes > 0 && send(insock, buf, bytes, MSG_OOB) != bytes)
break;
}

if (FD_ISSET(insock, &iofds)) {
bytes = read(insock, buf, bufsize);
if (bytes <= 0)
Expand Down