Compare commits
4 Commits
97d428d61d
...
330e6fd27b
Author | SHA1 | Date | |
---|---|---|---|
330e6fd27b | |||
70b6b6b604 | |||
5f11a3294b | |||
b7b3911c4d |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
proxy
|
||||||
|
easysock.o
|
5
Makefile
Normal file
5
Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
CC=gcc
|
||||||
|
main: main.c easysock.c
|
||||||
|
$(CC) main.c easysock.c -o proxy
|
||||||
|
allwarn: main.c easysock.c
|
||||||
|
$(CC) -Wall main.c easysock.c -o proxy
|
@@ -7,3 +7,6 @@ It is written in C, and has a small file size and memory footprint.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
./proxy <local-address> <local-port> <remote-address> <remote-port>
|
||||||
|
19
main.c
19
main.c
@@ -3,6 +3,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "easysock.h"
|
#include "easysock.h"
|
||||||
|
|
||||||
void forward_data(int from_fd, int to_fd) {
|
void forward_data(int from_fd, int to_fd) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
char* buffer = malloc(3000*sizeof(char));
|
char* buffer = malloc(3000*sizeof(char));
|
||||||
@@ -11,20 +12,32 @@ void forward_data(int from_fd, int to_fd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main(int argc,char* argv[]) {
|
||||||
|
|
||||||
|
/* argv[1] = local address
|
||||||
|
argv[2] = local port
|
||||||
|
argv[3] = remote address
|
||||||
|
argv[4] = remote port */
|
||||||
|
|
||||||
|
char* local_addr = argv[1];
|
||||||
|
int local_port = strtol(argv[2],NULL,10);
|
||||||
|
char* remote_addr = argv[3];
|
||||||
|
int remote_port = strtol(argv[4],NULL,10);
|
||||||
|
|
||||||
int preferred_network = 4;
|
int preferred_network = 4;
|
||||||
char preferred_transport = 'T';
|
char preferred_transport = 'T';
|
||||||
struct sockaddr addr_struct;
|
struct sockaddr addr_struct;
|
||||||
int server_sock = create_local(preferred_network,preferred_transport,"127.0.0.1",3000,&addr_struct);
|
int server_sock = create_local(preferred_network,preferred_transport,local_addr,local_port,&addr_struct);
|
||||||
int addrlen = sizeof(addr_struct);
|
int addrlen = sizeof(addr_struct);
|
||||||
|
|
||||||
listen(server_sock,50); /* Arbitrary number, change later */
|
listen(server_sock,50); /* Arbitrary number, change later */
|
||||||
|
|
||||||
|
printf("Listening on %s:%d\n",local_addr,local_port);
|
||||||
while (1) {
|
while (1) {
|
||||||
int from_client = accept(server_sock,&addr_struct,(socklen_t *)&addrlen);
|
int from_client = accept(server_sock,&addr_struct,(socklen_t *)&addrlen);
|
||||||
int to_server = create_remote(preferred_network,preferred_transport,"127.0.0.1",5000);
|
int to_server = create_remote(preferred_network,preferred_transport,remote_addr,remote_port);
|
||||||
|
|
||||||
|
printf("Connection established to %s:%d\n",remote_addr,remote_port);
|
||||||
if (fork() == 0) {
|
if (fork() == 0) {
|
||||||
|
|
||||||
/* fork returns 0 for a child, so we're in the child's execution
|
/* fork returns 0 for a child, so we're in the child's execution
|
||||||
|
Reference in New Issue
Block a user