mirror of
https://github.com/drk1wi/portspoof.git
synced 2024-06-30 02:31:41 +00:00
Update connection.cpp
This commit is contained in:
parent
1decde66c7
commit
af6cd4d79e
@ -117,23 +117,17 @@ void* process_connection(void *arg)
|
|||||||
{
|
{
|
||||||
|
|
||||||
timestamp = time(NULL);
|
timestamp = time(NULL);
|
||||||
|
|
||||||
if(configuration->getConfigValue(OPT_NOT_NMAP_SCANNER))
|
|
||||||
n = 1; // just reply...
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nonblock(threads[tid].clients[i]);
|
nonblock(threads[tid].clients[i]);
|
||||||
FD_ZERO(&read_mask);
|
FD_ZERO(&read_mask);
|
||||||
FD_SET(threads[tid].clients[i], &read_mask);
|
FD_SET(threads[tid].clients[i], &read_mask);
|
||||||
|
select_return = select(threads[tid].clients[i], &read_mask, (fd_set *) nullptr, (fd_set *) nullptr,
|
||||||
|
&tv);
|
||||||
|
|
||||||
select_return = select(threads[tid].clients[i], &read_mask, (fd_set *)0, (fd_set *)0, &tv);
|
|
||||||
|
|
||||||
if(select_return < 0) /* [timeout=0, -1= ERROR] is returned */
|
if (select_return < 0) /* [timeout=0, -1= ERROR] is returned */
|
||||||
{
|
|
||||||
n=-1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
n = -1;
|
||||||
|
} else {
|
||||||
n = 0;
|
n = 0;
|
||||||
int data_to_be_read_size = 0;
|
int data_to_be_read_size = 0;
|
||||||
|
|
||||||
@ -145,19 +139,49 @@ void* process_connection(void *arg)
|
|||||||
buffer_size = data_to_be_read_size;
|
buffer_size = data_to_be_read_size;
|
||||||
n = recv(threads[tid].clients[i], buffer, buffer_size, 0);
|
n = recv(threads[tid].clients[i], buffer, buffer_size, 0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int error_code;
|
||||||
|
socklen_t error_code_size = sizeof(error_code);
|
||||||
|
getsockopt(threads[tid].clients[i], SOL_SOCKET, SO_ERROR, &error_code, &error_code_size);
|
||||||
|
|
||||||
|
if (error_code) {
|
||||||
|
|
||||||
|
if (getsockopt(threads[tid].clients[i], SOL_IP, SO_ORIGINAL_DST, (struct sockaddr *) &peer_sockaddr,
|
||||||
|
(socklen_t *) (socklen_t *) &peer_sockaddr_len)) {
|
||||||
|
perror("Getsockopt failed: Have you set up your IPTABLES rules correctly ?");
|
||||||
|
goto close_socket;
|
||||||
|
} else
|
||||||
|
original_port = ntohs(peer_sockaddr.sin_port);
|
||||||
|
|
||||||
|
get_ipstr(threads[tid].clients[i], threads[tid].client_src_ip[i], ipstr);
|
||||||
|
|
||||||
|
close_socket:
|
||||||
|
if (configuration->getConfigValue(OPT_DEBUG))
|
||||||
|
fprintf(stdout, "Thread nr. %d : client %d closed connection\n", tid, threads[tid].clients[i]);
|
||||||
|
|
||||||
|
close(threads[tid].clients[i]);
|
||||||
|
|
||||||
|
fingerp.addTimedOutConnection(threads[tid].client_src_ip[i], original_port);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&new_connection_mutex);
|
||||||
|
threads[tid].clients[i] = 0;
|
||||||
|
threads[tid].client_count--;
|
||||||
|
pthread_mutex_unlock(&new_connection_mutex);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
|
||||||
// Linux
|
// Linux
|
||||||
if ( getsockopt (threads[tid].clients[i], SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&peer_sockaddr, (socklen_t*) &peer_sockaddr_len ))
|
if ( getsockopt (threads[tid].clients[i], SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&peer_sockaddr, (socklen_t*) &peer_sockaddr_len ))
|
||||||
perror("Getsockopt failed");
|
perror("Getsockopt failed");
|
||||||
|
|
||||||
get_ipstr(threads[tid].clients[i], ipstr);
|
get_ipstr(threads[tid].clients[i], ipstr);
|
||||||
original_port = ntohs(peer_sockaddr.sin_port);
|
original_port = ntohs(peer_sockaddr.sin_port);
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
//LOG
|
//LOG
|
||||||
char* msg=(char*)malloc(MAX_LOG_MSG_LEN);
|
char* msg=(char*)malloc(MAX_LOG_MSG_LEN);
|
||||||
@ -205,18 +229,15 @@ void* process_connection(void *arg)
|
|||||||
if(send(threads[tid].clients[i], buffertosend, buffertosendsize,0)==-1)
|
if(send(threads[tid].clients[i], buffertosend, buffertosendsize,0)==-1)
|
||||||
perror("Send to socket failed");
|
perror("Send to socket failed");
|
||||||
|
|
||||||
|
|
||||||
close(threads[tid].clients[i]);
|
close(threads[tid].clients[i]);
|
||||||
|
|
||||||
free(buffertosend);
|
free(buffertosend);
|
||||||
|
|
||||||
pthread_mutex_lock(&new_connection_mutex);
|
pthread_mutex_lock(&new_connection_mutex);
|
||||||
threads[tid].clients[i] = 0;
|
threads[tid].clients[i] = 0;
|
||||||
threads[tid].client_count--;
|
threads[tid].client_count--;
|
||||||
pthread_mutex_unlock(&new_connection_mutex);
|
pthread_mutex_unlock(&new_connection_mutex);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user