|
|
|
@ -39,7 +39,7 @@ int main(int argc,char* argv[]) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
@ -47,32 +47,38 @@ int main(int argc,char* argv[]) {
|
|
|
|
|
char preferred_transport = 'T';
|
|
|
|
|
struct sockaddr addr_struct;
|
|
|
|
|
int server_sock = create_local(preferred_local_network,preferred_transport,local_addr,local_port,&addr_struct);
|
|
|
|
|
int addrlen = sizeof(addr_struct);
|
|
|
|
|
int addrlen;
|
|
|
|
|
if (check_ip_ver(local_addr) == 4) {
|
|
|
|
|
addrlen = sizeof(struct sockaddr_in);
|
|
|
|
|
} else if (check_ip_ver(local_addr) == 6) {
|
|
|
|
|
addrlen = sizeof(struct sockaddr_in6);
|
|
|
|
|
} else {
|
|
|
|
|
exit(-7);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listen(server_sock,50); /* Arbitrary number, change later */
|
|
|
|
|
|
|
|
|
|
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_remote_network,preferred_transport,remote_addr,remote_port);
|
|
|
|
|
|
|
|
|
|
printf("Connection established to %s:%d\n",remote_addr,remote_port);
|
|
|
|
|
if (fork() == 0) {
|
|
|
|
|
struct sockaddr remote_addr_struct;
|
|
|
|
|
while (1) {
|
|
|
|
|
int from_client = accept(server_sock,&addr_struct,(socklen_t *)&addrlen);
|
|
|
|
|
int to_server = create_remote(preferred_remote_network,preferred_transport,remote_addr,remote_port,&remote_addr_struct);
|
|
|
|
|
|
|
|
|
|
/* fork returns 0 for a child, so we're in the child's execution
|
|
|
|
|
right now */
|
|
|
|
|
close(server_sock);
|
|
|
|
|
if (fork() == 0) {
|
|
|
|
|
forward_data(from_client,to_server);
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
printf("Connection established to %s:%d\n",remote_addr,remote_port);
|
|
|
|
|
if (fork() == 0) {
|
|
|
|
|
forward_data(to_server,from_client);
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
/* fork returns 0 for a child, so we're in the child's execution
|
|
|
|
|
right now */
|
|
|
|
|
close(server_sock);
|
|
|
|
|
if (fork() == 0) {
|
|
|
|
|
forward_data(from_client,to_server);
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
if (fork() == 0) {
|
|
|
|
|
forward_data(to_server,from_client);
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// recv(from_client,buffer,3000,0);
|
|
|
|
|
|
|
|
|
|