4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change
on this file since 77285d9 was
77285d9,
checked in by Shane Alcock <salcock@…>, 16 years ago
|
OpenBSD compatibility fixes - adding in various #defines and #includes that are needed to compile under OpenBSD
Added a replacement pcap_next_ex function for systems that aren't running pcap-0.8 or better
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | #include "config.h" |
---|
2 | |
---|
3 | #ifndef HAVE_PCAP_NEXT_EX |
---|
4 | #include <stdio.h> |
---|
5 | #include <pcap.h> |
---|
6 | #if HAVE_PCAP_INT_H |
---|
7 | # include <pcap-int.h> |
---|
8 | #else |
---|
9 | //# error "Need pcap-int.h for declaration of pcap_t" |
---|
10 | #endif |
---|
11 | #include <string.h> |
---|
12 | #include <libtrace.h> |
---|
13 | #include <stdlib.h> |
---|
14 | |
---|
15 | struct pcap_data_t { |
---|
16 | struct pcap_pkthdr *header; |
---|
17 | u_char *payload; |
---|
18 | }; |
---|
19 | |
---|
20 | |
---|
21 | static struct pcap_data_t pcap_data; |
---|
22 | |
---|
23 | static void trace_pcap_handler(u_char *user, const struct pcap_pkthdr *pcaphdr,const u_char *pcappkt) { |
---|
24 | struct pcap_data_t *packet = (struct pcap_data_t *)user; |
---|
25 | |
---|
26 | /* pcaphdr and pcappkt don't seem to persist for particularly long |
---|
27 | * so we need to memcpy them. Obviously, this spoils the whole |
---|
28 | * zero-copy concept but if you're using outdated pcap libraries |
---|
29 | * you deserve everything you get |
---|
30 | */ |
---|
31 | memcpy(packet->header, pcaphdr, sizeof(struct pcap_pkthdr)); |
---|
32 | memcpy(packet->payload, pcappkt, packet->header->len); |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | int pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header, |
---|
37 | const u_char **pkt_data) { |
---|
38 | |
---|
39 | int pcapbytes = 0; |
---|
40 | |
---|
41 | pcap_data.header = *pkt_header; |
---|
42 | pcap_data.payload = *pkt_data; |
---|
43 | |
---|
44 | pcapbytes = pcap_dispatch(p, 1, &trace_pcap_handler, |
---|
45 | (u_char *) &pcap_data); |
---|
46 | |
---|
47 | if (pcapbytes == -1) |
---|
48 | return -1; |
---|
49 | |
---|
50 | if (pcapbytes == 0 && pcap_file(p) != NULL) |
---|
51 | return -2; |
---|
52 | |
---|
53 | if (pcapbytes == 0) |
---|
54 | return 0; |
---|
55 | |
---|
56 | //*pkt_header = pcap_data.header; |
---|
57 | //*pkt_data = pcap_data.payload; |
---|
58 | |
---|
59 | |
---|
60 | return 1; |
---|
61 | } |
---|
62 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.