Commit 7d496dba by Michael Pastushkov

another try

parent c30dcd97
...@@ -353,15 +353,9 @@ int use(void) ...@@ -353,15 +353,9 @@ int use(void)
for (;;) for (;;)
{ {
int proxy_sock;
struct sockaddr_in proxy_addr;
struct sockaddr_in proxy_addr2;
int proxy_port = 12340;
FD_ZERO(&io); FD_ZERO(&io);
FD_SET(rc.client_socket, &io); FD_SET(rc.client_socket, &io);
FD_SET(rc.remote_socket, &io); FD_SET(rc.remote_socket, &io);
int max_fd = (rc.client_socket > rc.remote_socket) ? rc.client_socket : rc.remote_socket; int max_fd = (rc.client_socket > rc.remote_socket) ? rc.client_socket : rc.remote_socket;
/* Waiting for data */ /* Waiting for data */
...@@ -370,27 +364,8 @@ int use(void) ...@@ -370,27 +364,8 @@ int use(void)
break; break;
} }
if (options.mode == MODE_SERVER && options.proto == SOCK_DGRAM) { /* EXPERIMENTAL */ FD_ZERO(&io);
if ((proxy_sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { FD_SET(rc.client_socket, &io);
perror("proxy socket creation failed");
return 1;
}
memset(&proxy_addr, 0, sizeof(proxy_addr));
proxy_addr.sin_family = AF_INET;
proxy_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
proxy_addr.sin_port = htons(proxy_port);
// Bind the socket to the specific IP and port
if (bind(proxy_sock, (struct sockaddr *)&proxy_addr, sizeof(proxy_addr)) < 0) {
perror("bind failed");
close(proxy_sock);
return 1;
}
printf("** proxy sock created and mound to %d", proxy_port);
}
if (FD_ISSET(rc.client_socket, &io)) if (FD_ISSET(rc.client_socket, &io))
{ {
/* Processing request from local, sending it to remote*/ /* Processing request from local, sending it to remote*/
...@@ -414,45 +389,22 @@ int use(void) ...@@ -414,45 +389,22 @@ int use(void)
decode(buffer, count_recv) : decode(buffer, count_recv) :
encode(buffer, count_recv); encode(buffer, count_recv);
if (options.mode == MODE_SERVER && options.proto == SOCK_DGRAM) { /* EXPERIMENTAL */ count_sent = (options.proto == SOCK_DGRAM) ?
sendto(rc.remote_socket, buffer, count_recv, 0, (struct sockaddr *)&rc.remote_addr, sizeof(rc.remote_addr)) :
count_sent = sendto(proxy_sock, buffer, count_recv, 0, (struct sockaddr *)&rc.remote_addr, sizeof(rc.remote_addr)); send(rc.remote_socket, buffer, count_recv, 0);
if (count_sent < 0) {
perror("sendto proxy_sockfailed");
close(proxy_sock);
return 1;
}
printf("** bytes sent to remote: %d\n", count_recv);
} else {
count_sent = (options.proto == SOCK_DGRAM) ?
sendto(rc.remote_socket, buffer, count_recv, 0, (struct sockaddr *)&rc.remote_addr, sizeof(rc.remote_addr)) :
send(rc.remote_socket, buffer, count_recv, 0);
}
if (options.log > 2) if (options.log > 1)
printf("forwarded %d / %d bytes from local to remote\n", count_recv, count_sent); printf("recv %d\t%s:%d\tpid:\n", ntohs(client_addr.sin_port), inet_ntoa(client_addr.sin_addr), getpid());
} }
FD_ZERO(&io);
FD_SET(rc.remote_socket, &io);
if (FD_ISSET(rc.remote_socket, &io)) if (FD_ISSET(rc.remote_socket, &io))
{ {
/* Processing response from remote, sending it back to local */ /* Processing response from remote, sending it back to local */
count_recv = (options.proto == SOCK_DGRAM) ?
if (options.mode == MODE_SERVER && options.proto == SOCK_DGRAM) { /* EXPERIMENTAL */ recvfrom(rc.remote_socket, buffer, sizeof(buffer), 0, NULL, NULL) :
recv(rc.remote_socket, buffer, sizeof(buffer), 0);
count_recv = recvfrom(proxy_sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&proxy_addr2, &addr_len);
if (count_sent < 0) {
perror("recvfrom proxy_sock failed");
close(proxy_sock);
return 1;
}
printf("** bytes received from remote: %d, port: %d, address: %s\n", count_recv, proxy_addr2.sin_port, inet_ntoa(proxy_addr2.sin_addr));
} else {
count_recv = (options.proto == SOCK_DGRAM) ?
recvfrom(rc.remote_socket, buffer, sizeof(buffer), 0, NULL, NULL) :
recv(rc.remote_socket, buffer, sizeof(buffer), 0);
}
if (count_recv < 0) { if (count_recv < 0) {
perror("use: recv(rc.remote_socket)"); perror("use: recv(rc.remote_socket)");
...@@ -473,8 +425,8 @@ int use(void) ...@@ -473,8 +425,8 @@ int use(void)
sendto(rc.client_socket, buffer, count_recv, 0, (struct sockaddr *)&client_addr, addr_len) : sendto(rc.client_socket, buffer, count_recv, 0, (struct sockaddr *)&client_addr, addr_len) :
send(rc.client_socket, buffer, count_recv, 0); send(rc.client_socket, buffer, count_recv, 0);
if (options.log > 2) if (options.log > 1)
printf("forwarded %d / %d bytes from remote to local\n", count_recv, count_sent); printf("sent %d\t%s:%d\tpid:\n", ntohs(client_addr.sin_port), inet_ntoa(client_addr.sin_addr), getpid());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment