dryrun no longer requires root access
This commit is contained in:
parent
0c83eabfd1
commit
a5eb3d0a8d
12
src/send.c
12
src/send.c
@ -142,6 +142,11 @@ static int get_socket(void)
|
|||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_dryrun_socket(void)
|
||||||
|
{
|
||||||
|
return socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
}
|
||||||
|
|
||||||
static inline ipaddr_n_t get_src_ip(ipaddr_n_t dst, int local_offset)
|
static inline ipaddr_n_t get_src_ip(ipaddr_n_t dst, int local_offset)
|
||||||
{
|
{
|
||||||
if (srcip_first == srcip_last) {
|
if (srcip_first == srcip_last) {
|
||||||
@ -156,7 +161,12 @@ int send_run(void)
|
|||||||
{
|
{
|
||||||
log_debug("send", "thread started");
|
log_debug("send", "thread started");
|
||||||
pthread_mutex_lock(&send_mutex);
|
pthread_mutex_lock(&send_mutex);
|
||||||
int sock = get_socket();
|
int sock;
|
||||||
|
if (zconf.dryrun) {
|
||||||
|
sock = get_dryrun_socket();
|
||||||
|
} else {
|
||||||
|
sock = get_socket();
|
||||||
|
}
|
||||||
struct sockaddr_ll sockaddr;
|
struct sockaddr_ll sockaddr;
|
||||||
// get source interface index
|
// get source interface index
|
||||||
struct ifreq if_idx;
|
struct ifreq if_idx;
|
||||||
|
30
src/zmap.c
30
src/zmap.c
@ -222,30 +222,32 @@ static void start_zmap(void)
|
|||||||
}
|
}
|
||||||
// start threads
|
// start threads
|
||||||
pthread_t *tsend, trecv, tmon;
|
pthread_t *tsend, trecv, tmon;
|
||||||
int r = pthread_create(&trecv, NULL, start_recv, NULL);
|
if (!zconf.dryrun) {
|
||||||
if (r != 0) {
|
int r = pthread_create(&trecv, NULL, start_recv, NULL);
|
||||||
log_fatal("zmap", "unable to create recv thread");
|
if (r != 0) {
|
||||||
exit(EXIT_FAILURE);
|
log_fatal("zmap", "unable to create recv thread");
|
||||||
}
|
exit(EXIT_FAILURE);
|
||||||
for (;;) {
|
}
|
||||||
pthread_mutex_lock(&recv_ready_mutex);
|
for (;;) {
|
||||||
if (zconf.recv_ready) {
|
pthread_mutex_lock(&recv_ready_mutex);
|
||||||
break;
|
if (zconf.recv_ready) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&recv_ready_mutex);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&recv_ready_mutex);
|
|
||||||
}
|
}
|
||||||
tsend = malloc(zconf.senders * sizeof(pthread_t));
|
tsend = malloc(zconf.senders * sizeof(pthread_t));
|
||||||
assert(tsend);
|
assert(tsend);
|
||||||
log_debug("zmap", "using %d sender threads", zconf.senders);
|
log_debug("zmap", "using %d sender threads", zconf.senders);
|
||||||
for (int i=0; i < zconf.senders; i++) {
|
for (int i=0; i < zconf.senders; i++) {
|
||||||
r = pthread_create(&tsend[i], NULL, start_send, NULL);
|
int r = pthread_create(&tsend[i], NULL, start_send, NULL);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
log_fatal("zmap", "unable to create send thread");
|
log_fatal("zmap", "unable to create send thread");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!zconf.quiet) {
|
if (!zconf.quiet) {
|
||||||
r = pthread_create(&tmon, NULL, start_mon, NULL);
|
int r = pthread_create(&tmon, NULL, start_mon, NULL);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
log_fatal("zmap", "unable to create monitor thread");
|
log_fatal("zmap", "unable to create monitor thread");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -254,14 +256,14 @@ static void start_zmap(void)
|
|||||||
|
|
||||||
// wait for completion
|
// wait for completion
|
||||||
for (int i=0; i < zconf.senders; i++) {
|
for (int i=0; i < zconf.senders; i++) {
|
||||||
pthread_join(tsend[i], NULL);
|
int r = pthread_join(tsend[i], NULL);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
log_fatal("zmap", "unable to join send thread");
|
log_fatal("zmap", "unable to join send thread");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log_debug("zmap", "senders finished");
|
log_debug("zmap", "senders finished");
|
||||||
pthread_join(trecv, NULL);
|
int r = pthread_join(trecv, NULL);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
log_fatal("zmap", "unable to join recv thread");
|
log_fatal("zmap", "unable to join recv thread");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
Loading…
Reference in New Issue
Block a user