Commit 4dc4309f by Michael Pastushkov

x

parent 8f998e68
...@@ -253,7 +253,7 @@ int wait_connection(void) { ...@@ -253,7 +253,7 @@ int wait_connection(void) {
int bytes = recvfrom(rc.client_socket, buf, sizeof(buf), MSG_PEEK, (struct sockaddr *)&rc.client_addr, &client_addr_size); int bytes = recvfrom(rc.client_socket, buf, sizeof(buf), MSG_PEEK, (struct sockaddr *)&rc.client_addr, &client_addr_size);
if (bytes < 0) { if (bytes < 0) {
if (errno != EINTR) if (errno != EINTR)
perror("wait_connection: accept()"); perror("wait_connection: recvfrom(PEEK)");
return 1; return 1;
} }
} else { } else {
...@@ -365,6 +365,24 @@ int use(void) ...@@ -365,6 +365,24 @@ int use(void)
} }
if (FD_ISSET(rc.client_socket, &io)) if (FD_ISSET(rc.client_socket, &io))
{ {
if (options.proto == SOCK_DGRAM) {
count_recv = recvfrom(rc.client_socket, buffer, sizeof(buffer), MSG_PEEK, (struct sockaddr *)&client_addr, &addr_len);
if (count_recv < 0) {
perror("use() - PEEK");
}
if (rc.my_addr.sin_port == 0) {
rc.my_addr = client_addr;
if (options.log > 1)
printf("my address %s:%d\tpid: %d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port), getpid());
} else {
if (compare_clients(rc.my_addr, client_addr)) {
if (options.log > 1)
printf("ignore %s:%d\tpid: %d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port), getpid());
continue; // not our business
}
}
}
/* Processing request from local, sending it to remote*/ /* Processing request from local, sending it to remote*/
count_recv = (options.proto == SOCK_DGRAM) ? count_recv = (options.proto == SOCK_DGRAM) ?
recvfrom(rc.client_socket, buffer, sizeof(buffer), 0, (struct sockaddr *)&client_addr, &addr_len) : recvfrom(rc.client_socket, buffer, sizeof(buffer), 0, (struct sockaddr *)&client_addr, &addr_len) :
......
...@@ -54,6 +54,7 @@ struct struct_rc { ...@@ -54,6 +54,7 @@ struct struct_rc {
struct sockaddr_in server_addr; struct sockaddr_in server_addr;
struct sockaddr_in client_addr; struct sockaddr_in client_addr;
struct sockaddr_in remote_addr; struct sockaddr_in remote_addr;
struct sockaddr_in my_addr;
struct hostent *remote_host; struct hostent *remote_host;
}; };
......
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