source: lib/pcap_next_ex.c @ a21af3d

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since a21af3d was a21af3d, checked in by Perry Lorier <perry@…>, 15 years ago

Kill dead (commented out) code

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include "config.h"
2
3#ifndef HAVE_PCAP_NEXT_EX
4#include <stdio.h>
5#include <pcap.h>
6#ifdef HAVE_PCAP_INT_H
7# include <pcap-int.h>
8#endif
9#include <string.h>
10#include <libtrace.h>
11#include <stdlib.h>
12
13struct pcap_data_t {
14        struct pcap_pkthdr *header;
15        u_char *payload;
16};
17
18
19static struct pcap_data_t pcap_data;
20
21static void trace_pcap_handler(u_char *user, const struct pcap_pkthdr *pcaphdr,const u_char *pcappkt) {
22        struct pcap_data_t *packet = (struct pcap_data_t *)user;
23
24        /* pcaphdr and pcappkt don't seem to persist for particularly long
25         * so we need to memcpy them. Obviously, this spoils the whole
26         * zero-copy concept but if you're using outdated pcap libraries
27         * you deserve everything you get
28         */
29        memcpy(packet->header, pcaphdr, sizeof(struct pcap_pkthdr));
30        memcpy(packet->payload, pcappkt, packet->header->len);
31}
32
33
34int pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,
35                        const u_char **pkt_data) {
36
37        int pcapbytes = 0;
38
39        pcap_data.header = *pkt_header;
40        pcap_data.payload = *pkt_data;
41
42        pcapbytes = pcap_dispatch(p, 1, &trace_pcap_handler,
43                       (u_char *) &pcap_data);
44
45        if (pcapbytes == -1)
46                return -1;
47
48        if (pcapbytes == 0 && pcap_file(p) != NULL)
49                return -2;
50
51        if (pcapbytes == 0)
52                return 0;
53
54        return 1;
55}
56#endif
Note: See TracBrowser for help on using the repository browser.