diff --git a/src/send.c b/src/send.c index 4426da8..c76f87e 100644 --- a/src/send.c +++ b/src/send.c @@ -132,7 +132,7 @@ int send_init(void) return EXIT_SUCCESS; } -static int get_socket(void) +int get_socket(void) { int sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if (sock <= 0) { @@ -142,7 +142,7 @@ static int get_socket(void) return sock; } -static int get_dryrun_socket(void) +int get_dryrun_socket(void) { // we need a socket in order to gather details about the system // such as source MAC address and IP address. However, because @@ -167,16 +167,11 @@ static inline ipaddr_n_t get_src_ip(ipaddr_n_t dst, int local_offset) } // one sender thread -int send_run(void) +int send_run(int sock) { log_debug("send", "thread started"); pthread_mutex_lock(&send_mutex); - int sock; - if (zconf.dryrun) { - sock = get_dryrun_socket(); - } else { - sock = get_socket(); - } + struct sockaddr_ll sockaddr; // get source interface index struct ifreq if_idx; diff --git a/src/send.h b/src/send.h index 1b96120..553f56d 100644 --- a/src/send.h +++ b/src/send.h @@ -9,7 +9,9 @@ #ifndef SEND_H #define SEND_H +int get_socket(void); +int get_dryrun_socket(void); int send_init(void); -int send_run(void); +int send_run(int); -#endif //_SEND_H +#endif //SEND_H diff --git a/src/zmap.c b/src/zmap.c index 016b3ee..cafb7a2 100644 --- a/src/zmap.c +++ b/src/zmap.c @@ -90,10 +90,12 @@ static void set_cpu(void) pthread_mutex_unlock(&cpu_affinity_mutex); } -static void* start_send(__attribute__((unused)) void *arg) +static void* start_send(void *arg) { + uintptr_t v = (uintptr_t) arg; + int sock = (int) v & 0xFFFF; set_cpu(); - send_run(); + send_run(sock); return NULL; } @@ -238,7 +240,14 @@ static void start_zmap(void) assert(tsend); log_debug("zmap", "using %d sender threads", zconf.senders); for (int i=0; i < zconf.senders; i++) { - int r = pthread_create(&tsend[i], NULL, start_send, NULL); + uintptr_t sock; + if (zconf.dryrun) { + sock = get_dryrun_socket(); + } else { + sock = get_socket(); + } + + int r = pthread_create(&tsend[i], NULL, start_send, (void*) sock); if (r != 0) { log_fatal("zmap", "unable to create send thread"); exit(EXIT_FAILURE);