Compare commits
3 Commits
e664c1526d
...
54374082f4
Author | SHA1 | Date | |
---|---|---|---|
54374082f4 | |||
7dce5bbaa1 | |||
80263cb92e |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,3 @@
|
||||
proxy
|
||||
basicproxy
|
||||
main.o
|
||||
easysock.o
|
||||
|
5
Makefile
5
Makefile
@@ -1,11 +1,12 @@
|
||||
CC=gcc
|
||||
CFLAGS=
|
||||
EXEC_FILE=proxy
|
||||
EXEC_FILE=basicproxy
|
||||
|
||||
$(EXEC_FILE): main.o easysock.o
|
||||
$(CC) $(CFLAGS) main.o easysock.o -o $(EXEC_FILE)
|
||||
|
||||
|
||||
allwarn: CFLAGS+=-Wall
|
||||
allwarn: CFLAGS+=-Wall -Wextra -pedantic
|
||||
allwarn: $(EXEC_FILE)
|
||||
|
||||
clean: $(EXEC_FILE) main.o easysock.o
|
||||
|
25
main.c
25
main.c
@@ -12,6 +12,18 @@ void forward_data(int from_fd, int to_fd) {
|
||||
}
|
||||
}
|
||||
|
||||
int check_ip_ver(char* address) {
|
||||
char buffer[16]; /* 16 chars - 128 bits - is enough to hold an ipv6 address */
|
||||
if (inet_pton(AF_INET,address,buffer) == 1) {
|
||||
return 4;
|
||||
} else if (inet_pton(AF_INET6,address,buffer) == 1) {
|
||||
return 6;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char* argv[]) {
|
||||
|
||||
/* argv[1] = local address
|
||||
@@ -24,10 +36,17 @@ int main(int argc,char* argv[]) {
|
||||
char* remote_addr = argv[3];
|
||||
int remote_port = strtol(argv[4],NULL,10);
|
||||
|
||||
int preferred_network = 4;
|
||||
int preferred_local_network = check_ip_ver(local_addr);
|
||||
int preferred_remote_network = check_ip_ver(remote_addr);
|
||||
printf("Using %d for local\nUsing %d for remote\n",preferred_local_network,preferred_remote_network);
|
||||
|
||||
if ((preferred_local_network == -1) && (preferred_remote_network == -1)) {
|
||||
exit(-7);
|
||||
}
|
||||
|
||||
char preferred_transport = 'T';
|
||||
struct sockaddr addr_struct;
|
||||
int server_sock = create_local(preferred_network,preferred_transport,local_addr,local_port,&addr_struct);
|
||||
int server_sock = create_local(preferred_local_network,preferred_transport,local_addr,local_port,&addr_struct);
|
||||
int addrlen = sizeof(addr_struct);
|
||||
|
||||
listen(server_sock,50); /* Arbitrary number, change later */
|
||||
@@ -35,7 +54,7 @@ int main(int argc,char* argv[]) {
|
||||
printf("Listening on %s:%d\n",local_addr,local_port);
|
||||
while (1) {
|
||||
int from_client = accept(server_sock,&addr_struct,(socklen_t *)&addrlen);
|
||||
int to_server = create_remote(preferred_network,preferred_transport,remote_addr,remote_port);
|
||||
int to_server = create_remote(preferred_remote_network,preferred_transport,remote_addr,remote_port);
|
||||
|
||||
printf("Connection established to %s:%d\n",remote_addr,remote_port);
|
||||
if (fork() == 0) {
|
||||
|
Reference in New Issue
Block a user