Exemplo n.º 1
0
static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx,
			  int sock, int *fd)
{
	int num_pkts = pbd->h1.num_pkts, i;
	struct tpacket3_hdr *hdr;
	struct sockaddr_ll *sll;

	hdr = (void *) ((uint8_t *) pbd + pbd->h1.offset_to_first_pkt);
	sll = (void *) ((uint8_t *) hdr + TPACKET_ALIGN(sizeof(*hdr)));

	for (i = 0; i < num_pkts && likely(sigint == 0); ++i) {
		uint8_t *packet = ((uint8_t *) hdr + hdr->tp_mac);
		pcap_pkthdr_t phdr;

		if (ctx->packet_type != -1)
			if (ctx->packet_type != sll->sll_pkttype)
				goto next;

		ctx->pkts_seen++;

		if (dump_to_pcap(ctx)) {
			int ret;

			tpacket3_hdr_to_pcap_pkthdr(hdr, sll, &phdr, ctx->magic);

			ret = __pcap_io->write_pcap(*fd, &phdr, ctx->magic, packet,
						    pcap_get_length(&phdr, ctx->magic));
			if (unlikely(ret != (int) pcap_get_total_length(&phdr, ctx->magic)))
				panic("Write error to pcap!\n");
		}

		__show_frame_hdr(packet, hdr->tp_snaplen, ctx->link_type, sll,
				 hdr, ctx->print_mode, true, ctx->pkts_seen);

		dissector_entry_point(packet, hdr->tp_snaplen, ctx->link_type,
				      ctx->print_mode, sll);
next:
                hdr = (void *) ((uint8_t *) hdr + hdr->tp_next_offset);
		sll = (void *) ((uint8_t *) hdr + TPACKET_ALIGN(sizeof(*hdr)));

		if (frame_count_max != 0) {
			if (unlikely(ctx->pkts_seen >= frame_count_max)) {
				sigint = 1;
				break;
			}
		}

		update_pcap_next_dump(ctx, hdr->tp_snaplen, fd, sock, true);
	}
}
Exemplo n.º 2
0
static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx,
			  int sock, int *fd, unsigned long *frame_count)
{
	uint8_t *packet;
	int num_pkts = pbd->h1.num_pkts, i, ret;
	struct tpacket3_hdr *hdr;
	pcap_pkthdr_t phdr;
	struct sockaddr_ll *sll;

	hdr = (void *) ((uint8_t *) pbd + pbd->h1.offset_to_first_pkt);
	sll = (void *) ((uint8_t *) hdr + TPACKET_ALIGN(sizeof(*hdr)));

	for (i = 0; i < num_pkts && likely(sigint == 0); ++i) {
		__label__ next;
		packet = ((uint8_t *) hdr + hdr->tp_mac);

		if (ctx->packet_type != -1)
			if (ctx->packet_type != sll->sll_pkttype)
				goto next;

		(*frame_count)++;

		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,
						    pcap_get_length(&phdr, ctx->magic));
			if (unlikely(ret != pcap_get_total_length(&phdr, ctx->magic)))
				panic("Write error to pcap!\n");
		}

		__show_frame_hdr(sll, hdr, ctx->print_mode, true);

		dissector_entry_point(packet, hdr->tp_snaplen, ctx->link_type,
				      ctx->print_mode);
		next:

                hdr = (void *) ((uint8_t *) hdr + hdr->tp_next_offset);
		sll = (void *) ((uint8_t *) hdr + TPACKET_ALIGN(sizeof(*hdr)));

		if (frame_count_max != 0) {
			if (unlikely(*frame_count >= frame_count_max)) {
				sigint = 1;
				break;
			}
		}

		if (dump_to_pcap(ctx)) {
			if (ctx->dump_mode == DUMP_INTERVAL_SIZE) {
				interval += hdr->tp_snaplen;
				if (interval > ctx->dump_interval) {
					next_dump = true;
					interval = 0;
				}
			}

			if (next_dump) {
				*fd = next_multi_pcap_file(ctx, *fd);
				next_dump = false;

				if (unlikely(ctx->verbose))
					print_pcap_file_stats(sock, ctx);
			}
		}
	}
}