bug fixes to extended_file output

This commit is contained in:
Zakir Durumeric 2013-08-29 14:51:26 -04:00
parent a5eb3d0a8d
commit 672143e9ba
3 changed files with 48 additions and 34 deletions

View File

@ -168,19 +168,21 @@ int recv_run(pthread_mutex_t *recv_ready_mutex)
log_fatal("recv", "could not allocate address bitmap");
}
log_debug("recv", "using dev %s", zconf.iface);
char errbuf[PCAP_ERRBUF_SIZE];
pc = pcap_open_live(zconf.iface, zconf.probe_module->pcap_snaplen,
PCAP_PROMISC, PCAP_TIMEOUT, errbuf);
if (pc == NULL) {
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) {
log_fatal("recv", "couldn't compile filter");
}
if (pcap_setfilter(pc, &bpf) < 0) {
log_fatal("recv", "couldn't install filter");
if (!zconf.dryrun) {
char errbuf[PCAP_ERRBUF_SIZE];
pc = pcap_open_live(zconf.iface, zconf.probe_module->pcap_snaplen,
PCAP_PROMISC, PCAP_TIMEOUT, errbuf);
if (pc == NULL) {
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) {
log_fatal("recv", "couldn't compile filter");
}
if (pcap_setfilter(pc, &bpf) < 0) {
log_fatal("recv", "couldn't install filter");
}
}
log_debug("recv", "receiver ready");
if (zconf.filter_duplicates) {
@ -202,12 +204,16 @@ int recv_run(pthread_mutex_t *recv_ready_mutex)
zconf.max_results = -1;
}
do {
if (pcap_dispatch(pc, 0, packet_cb, NULL) == -1) {
log_fatal("recv", "pcap_dispatch error");
}
if (zconf.max_results && zrecv.success_unique >= zconf.max_results) {
zsend.complete = 1;
break;
if (zconf.dryrun) {
sleep(1);
} else {
if (pcap_dispatch(pc, 0, packet_cb, NULL) == -1) {
log_fatal("recv", "pcap_dispatch error");
}
if (zconf.max_results && zrecv.success_unique >= zconf.max_results) {
zsend.complete = 1;
break;
}
}
} while (!(zsend.complete && (now()-zsend.finish > zconf.cooldown_secs)));
zrecv.finish = now();

View File

@ -144,7 +144,17 @@ static int get_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)

View File

@ -222,19 +222,17 @@ static void start_zmap(void)
}
// start threads
pthread_t *tsend, trecv, tmon;
if (!zconf.dryrun) {
int r = pthread_create(&trecv, NULL, start_recv, NULL);
if (r != 0) {
log_fatal("zmap", "unable to create recv thread");
exit(EXIT_FAILURE);
}
for (;;) {
pthread_mutex_lock(&recv_ready_mutex);
if (zconf.recv_ready) {
break;
}
pthread_mutex_unlock(&recv_ready_mutex);
int r = pthread_create(&trecv, NULL, start_recv, NULL);
if (r != 0) {
log_fatal("zmap", "unable to create recv thread");
exit(EXIT_FAILURE);
}
for (;;) {
pthread_mutex_lock(&recv_ready_mutex);
if (zconf.recv_ready) {
break;
}
pthread_mutex_unlock(&recv_ready_mutex);
}
tsend = malloc(zconf.senders * sizeof(pthread_t));
assert(tsend);
@ -263,7 +261,7 @@ static void start_zmap(void)
}
}
log_debug("zmap", "senders finished");
int r = pthread_join(trecv, NULL);
r = pthread_join(trecv, NULL);
if (r != 0) {
log_fatal("zmap", "unable to join recv thread");
exit(EXIT_FAILURE);
@ -402,7 +400,7 @@ int main(int argc, char *argv[])
zconf.raw_output_fields = (char*) "classification, saddr, "
"daddr, sport, dport, "
"seqnum, acknum, cooldown, "
"repeat, timstamp-str";
"repeat, timestamp-str";
zconf.filter_duplicates = 0;
} else {
zconf.output_module = get_output_module_by_name(args.output_module_arg);