summaryrefslogtreecommitdiff
path: root/netsniff-ng.c
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-06-12 14:11:06 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-06-12 14:11:06 +0200
commit44b463529a8a9f2ccd1ec2acb8a4dfc117a636cb (patch)
treef7e0b8b3e7349938cd5300684795b4fc98f10a7a /netsniff-ng.c
parent9c645ee7da2a82529ff3ed01d04e0893904d7702 (diff)
netsniff-ng: walk_t3_block: prevent fd from double close
Only close the very first pcap file of multi-pcap files once, and not once during next_multi_pcap_file and once during exit. Discovered by Coverty scanner. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'netsniff-ng.c')
-rw-r--r--netsniff-ng.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c
index ec4faeb..14ce8f2 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -812,7 +812,7 @@ static void print_pcap_file_stats(int sock, struct ctx *ctx)
}
static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx,
- int sock, int fd, unsigned long *frame_count)
+ int sock, int *fd, unsigned long *frame_count)
{
uint8_t *packet;
int num_pkts = pbd->h1.num_pkts, i, ret;
@@ -836,7 +836,7 @@ static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx,
if (dump_to_pcap(ctx)) {
tpacket3_hdr_to_pcap_pkthdr(hdr, sll, &phdr, ctx->magic);
- ret = __pcap_io->write_pcap(fd, &phdr, ctx->magic, packet,
+ ret = __pcap_io->write_pcap(*fd, &phdr, ctx->magic, packet,
pcap_get_length(&phdr, ctx->magic));
if (unlikely(ret != pcap_get_total_length(&phdr, ctx->magic)))
panic("Write error to pcap!\n");
@@ -868,7 +868,7 @@ static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx,
}
if (next_dump) {
- fd = next_multi_pcap_file(ctx, fd);
+ *fd = next_multi_pcap_file(ctx, *fd);
next_dump = false;
if (unlikely(ctx->verbose))
@@ -971,7 +971,7 @@ static void recv_only_or_dump(struct ctx *ctx)
while (likely(sigint == 0)) {
while (user_may_pull_from_rx_block((pbd = (void *)
rx_ring.frames[it].iov_base))) {
- walk_t3_block(pbd, ctx, sock, fd, &frame_count);
+ walk_t3_block(pbd, ctx, sock, &fd, &frame_count);
kernel_may_pull_from_rx_block(pbd);
it = (it + 1) % rx_ring.layout3.tp_block_nr;