Skip to content

Commit

Permalink
Add support for establishing a single connection when using cooked so…
Browse files Browse the repository at this point in the history
…ckets.
  • Loading branch information
gamemann committed Apr 19, 2024
1 parent 289b3a7 commit f8f428c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,23 @@ void *thread_hdl(void *temp)
tcpsin.sin_port = htons(ti->seq.tcp.dst_port);
memset(&tcpsin.sin_zero, 0, sizeof(tcpsin.sin_zero));

// If we're using one connection for a cooked socket, open and connect socket now.
if (ti->seq.tcp.use_socket && ti->seq.tcp.one_connection) {
if ((sock_fd = socket(sock_domain, sock_type, sock_proto)) < 0)
{
fprintf(stderr, "ERROR - Cannot setup TCP cook socket :: %s.\n", strerror(errno));

pthread_exit(NULL);
}

if (connect(sock_fd, (struct sockaddr *)&tcpsin, sizeof(tcpsin)) != 0)
{
fprintf(stderr, "ERROR - Cannot connect to destination using cooked sockets :: %s.\n", strerror(errno));

pthread_exit(NULL);
}
}

// Loop.
while (1)
{
Expand Down Expand Up @@ -621,7 +638,7 @@ void *thread_hdl(void *temp)
tcph->check = csum_tcpudp_magic(iph->saddr, iph->daddr, (tcph->doff * 4) + data_len, IPPROTO_TCP, csum_partial(tcph, (tcph->doff * 4) + data_len, 0));
}

if (ti->seq.tcp.use_socket)
if (ti->seq.tcp.use_socket && !ti->seq.tcp.one_connection)
{
if ((sock_fd = socket(sock_domain, sock_type, sock_proto)) < 0)
{
Expand Down

0 comments on commit f8f428c

Please sign in to comment.