bug fixes to extended_file output
This commit is contained in:
parent
a5eb3d0a8d
commit
672143e9ba
44
src/recv.c
44
src/recv.c
@ -168,19 +168,21 @@ int recv_run(pthread_mutex_t *recv_ready_mutex)
|
|||||||
log_fatal("recv", "could not allocate address bitmap");
|
log_fatal("recv", "could not allocate address bitmap");
|
||||||
}
|
}
|
||||||
log_debug("recv", "using dev %s", zconf.iface);
|
log_debug("recv", "using dev %s", zconf.iface);
|
||||||
char errbuf[PCAP_ERRBUF_SIZE];
|
if (!zconf.dryrun) {
|
||||||
pc = pcap_open_live(zconf.iface, zconf.probe_module->pcap_snaplen,
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
PCAP_PROMISC, PCAP_TIMEOUT, errbuf);
|
pc = pcap_open_live(zconf.iface, zconf.probe_module->pcap_snaplen,
|
||||||
if (pc == NULL) {
|
PCAP_PROMISC, PCAP_TIMEOUT, errbuf);
|
||||||
log_fatal("recv", "could not open device %s: %s",
|
if (pc == NULL) {
|
||||||
zconf.iface, errbuf);
|
log_fatal("recv", "could not open device %s: %s",
|
||||||
}
|
zconf.iface, errbuf);
|
||||||
struct bpf_program bpf;
|
}
|
||||||
if (pcap_compile(pc, &bpf, zconf.probe_module->pcap_filter, 1, 0) < 0) {
|
struct bpf_program bpf;
|
||||||
log_fatal("recv", "couldn't compile filter");
|
if (pcap_compile(pc, &bpf, zconf.probe_module->pcap_filter, 1, 0) < 0) {
|
||||||
}
|
log_fatal("recv", "couldn't compile filter");
|
||||||
if (pcap_setfilter(pc, &bpf) < 0) {
|
}
|
||||||
log_fatal("recv", "couldn't install filter");
|
if (pcap_setfilter(pc, &bpf) < 0) {
|
||||||
|
log_fatal("recv", "couldn't install filter");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log_debug("recv", "receiver ready");
|
log_debug("recv", "receiver ready");
|
||||||
if (zconf.filter_duplicates) {
|
if (zconf.filter_duplicates) {
|
||||||
@ -202,12 +204,16 @@ int recv_run(pthread_mutex_t *recv_ready_mutex)
|
|||||||
zconf.max_results = -1;
|
zconf.max_results = -1;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
if (pcap_dispatch(pc, 0, packet_cb, NULL) == -1) {
|
if (zconf.dryrun) {
|
||||||
log_fatal("recv", "pcap_dispatch error");
|
sleep(1);
|
||||||
}
|
} else {
|
||||||
if (zconf.max_results && zrecv.success_unique >= zconf.max_results) {
|
if (pcap_dispatch(pc, 0, packet_cb, NULL) == -1) {
|
||||||
zsend.complete = 1;
|
log_fatal("recv", "pcap_dispatch error");
|
||||||
break;
|
}
|
||||||
|
if (zconf.max_results && zrecv.success_unique >= zconf.max_results) {
|
||||||
|
zsend.complete = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (!(zsend.complete && (now()-zsend.finish > zconf.cooldown_secs)));
|
} while (!(zsend.complete && (now()-zsend.finish > zconf.cooldown_secs)));
|
||||||
zrecv.finish = now();
|
zrecv.finish = now();
|
||||||
|
12
src/send.c
12
src/send.c
@ -144,7 +144,17 @@ static int get_socket(void)
|
|||||||
|
|
||||||
static int get_dryrun_socket(void)
|
static int get_dryrun_socket(void)
|
||||||
{
|
{
|
||||||
return socket(AF_INET, SOCK_STREAM, 0);
|
// we need a socket in order to gather details about the system
|
||||||
|
// such as source MAC address and IP address. However, because
|
||||||
|
// we don't want to require root access in order to run dryrun,
|
||||||
|
// we just create a TCP socket.
|
||||||
|
int sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (sock <= 0) {
|
||||||
|
log_fatal("send", "couldn't create socket. "
|
||||||
|
"Error: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
return sock;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
26
src/zmap.c
26
src/zmap.c
@ -222,19 +222,17 @@ static void start_zmap(void)
|
|||||||
}
|
}
|
||||||
// start threads
|
// start threads
|
||||||
pthread_t *tsend, trecv, tmon;
|
pthread_t *tsend, trecv, tmon;
|
||||||
if (!zconf.dryrun) {
|
int r = pthread_create(&trecv, NULL, start_recv, NULL);
|
||||||
int r = pthread_create(&trecv, NULL, start_recv, NULL);
|
if (r != 0) {
|
||||||
if (r != 0) {
|
log_fatal("zmap", "unable to create recv thread");
|
||||||
log_fatal("zmap", "unable to create recv thread");
|
exit(EXIT_FAILURE);
|
||||||
exit(EXIT_FAILURE);
|
}
|
||||||
}
|
for (;;) {
|
||||||
for (;;) {
|
pthread_mutex_lock(&recv_ready_mutex);
|
||||||
pthread_mutex_lock(&recv_ready_mutex);
|
if (zconf.recv_ready) {
|
||||||
if (zconf.recv_ready) {
|
break;
|
||||||
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);
|
||||||
@ -263,7 +261,7 @@ static void start_zmap(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
log_debug("zmap", "senders finished");
|
log_debug("zmap", "senders finished");
|
||||||
int r = pthread_join(trecv, NULL);
|
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);
|
||||||
@ -402,7 +400,7 @@ int main(int argc, char *argv[])
|
|||||||
zconf.raw_output_fields = (char*) "classification, saddr, "
|
zconf.raw_output_fields = (char*) "classification, saddr, "
|
||||||
"daddr, sport, dport, "
|
"daddr, sport, dport, "
|
||||||
"seqnum, acknum, cooldown, "
|
"seqnum, acknum, cooldown, "
|
||||||
"repeat, timstamp-str";
|
"repeat, timestamp-str";
|
||||||
zconf.filter_duplicates = 0;
|
zconf.filter_duplicates = 0;
|
||||||
} else {
|
} else {
|
||||||
zconf.output_module = get_output_module_by_name(args.output_module_arg);
|
zconf.output_module = get_output_module_by_name(args.output_module_arg);
|
||||||
|
Loading…
Reference in New Issue
Block a user