Skip to content

Commit 0e7f4d8

Browse files
committed
initialize socklen size
1 parent 751baf4 commit 0e7f4d8

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

‎net/scan/tcphalfopen.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ static void* wait_for_syn_ack(void* data)
474474
char ip[16];
475475
port_t port;
476476
uint8_t* buffer = (uint8_t*) malloc(USHRT_MAX); //Its Big!
477+
socklen_t sl;
477478

478479
dbg("Sniffer thread initialising\n");
479480

@@ -485,7 +486,7 @@ static void* wait_for_syn_ack(void* data)
485486
return NULL;
486487
}
487488

488-
socklen_t sl;
489+
sl = sizeof(saddr);
489490
while (ret != 0)
490491
{
491492
//Receive a packet

‎test/server.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ static struct thread_info_data* g_tdata;
2929

3030
struct thread_info_data
3131
{
32-
int id;
3332
port_t portno;
3433
size_t index;
3534
int socket_type;
@@ -125,7 +124,7 @@ static void* start_parallel_server(void* data)
125124
port_t portno;
126125
int connfd, socket_type;
127126
socklen_t s;
128-
struct sockaddr_in servaddr, cli;
127+
struct sockaddr_in servaddr, cliaddr;
129128
struct thread_info_data* d = (struct thread_info_data*) data;
130129

131130
portno = d->portno;
@@ -140,6 +139,7 @@ static void* start_parallel_server(void* data)
140139
PHSCAN_CS_PROTECT(dbg("Socket successfully created.\n"), &m);
141140

142141
memset(&servaddr, 0, sizeof(servaddr));
142+
memset(&cliaddr, 0, sizeof(cliaddr));
143143

144144
// Assign IP and port
145145
servaddr.sin_family = AF_INET;
@@ -160,18 +160,23 @@ static void* start_parallel_server(void* data)
160160
perror("listen");
161161
exit (1);
162162
}
163-
PHSCAN_CS_PROTECT(info("[Thread %p] Server listening to 0.0.0.0/0 on port %d ...\n", (void*)pthread_self(), portno), &m);
163+
PHSCAN_CS_PROTECT(info("[Thread %p] Server listening to 0.0.0.0/0 on port %d ...\n",
164+
(void*)pthread_self(), portno), &m);
164165

165166
while (1)
166167
{
168+
s = sizeof(cliaddr);
167169
// Accept the data packet from client and verification
168-
connfd = accept(g_sockfds[d->index], (SA*)&cli, &s);
170+
connfd = accept(g_sockfds[d->index], (SA*)&cliaddr, &s);
169171
if (connfd < 0)
170172
{
171173
perror("accept");
172174
exit (1);
173175
}
174-
PHSCAN_CS_PROTECT(info("[Thread %p] Client `%s' connected.\n", (void*)pthread_self(), inet_ntoa(cli.sin_addr)), &m);
176+
PHSCAN_CS_PROTECT(info("[Thread %p] Client `%s' connected to port %u.\n",
177+
(void*)pthread_self(), inet_ntoa(cliaddr.sin_addr), portno), &m);
178+
// Close this client
179+
close(connfd);
175180
}
176181

177182
server_cleanup();
@@ -244,7 +249,6 @@ int main(int argc, char* argv[])
244249
// Create a thread per listening port (don't overuse..)
245250
for (i = 0; i < g_port_count; ++i)
246251
{
247-
g_tdata[i].id = i;
248252
g_tdata[i].portno = g_port_list[i];
249253
g_tdata[i].index = i;
250254
g_tdata[i].socket_type = socket_type;

0 commit comments

Comments
 (0)