Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added argument for the bind address to use. #7

Merged
merged 1 commit into from
Jun 17, 2017
Merged
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
17 changes: 13 additions & 4 deletions proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void plog(int priority, const char *format, ...);

int server_sock, client_sock, remote_sock, remote_port = 0;
int connections_processed = 0;
char *remote_host, *cmd_in, *cmd_out;
char *bind_addr, *remote_host, *cmd_in, *cmd_out;
bool foreground = FALSE;
bool use_syslog = FALSE;

Expand All @@ -89,10 +89,12 @@ int main(int argc, char *argv[]) {
int local_port;
pid_t pid;

bind_addr = NULL;

local_port = parse_options(argc, argv);

if (local_port < 0) {
printf("Syntax: %s -l local_port -h remote_host -p remote_port [-i \"input parser\"] [-o \"output parser\"] [-f (stay in foreground)] [-s (use syslog)]\n", argv[0]);
printf("Syntax: %s [-b bind_address] -l local_port -h remote_host -p remote_port [-i \"input parser\"] [-o \"output parser\"] [-f (stay in foreground)] [-s (use syslog)]\n", argv[0]);
return local_port;
}

Expand Down Expand Up @@ -132,11 +134,14 @@ int main(int argc, char *argv[]) {
int parse_options(int argc, char *argv[]) {
int c, local_port = 0;

while ((c = getopt(argc, argv, "l:h:p:i:o:fs")) != -1) {
while ((c = getopt(argc, argv, "b:l:h:p:i:o:fs")) != -1) {
switch(c) {
case 'l':
local_port = atoi(optarg);
break;
case 'b':
bind_addr = optarg;
break;
case 'h':
remote_host = optarg;
break;
Expand Down Expand Up @@ -181,7 +186,11 @@ int create_socket(int port) {
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
server_addr.sin_addr.s_addr = INADDR_ANY;
if (bind_addr == NULL) {
server_addr.sin_addr.s_addr = INADDR_ANY;
} else {
server_addr.sin_addr.s_addr = inet_addr(bind_addr);
}

if (bind(server_sock, (struct sockaddr*)&server_addr, sizeof(server_addr)) != 0) {
return SERVER_BIND_ERROR;
Expand Down