Opened 7 years ago
Closed 7 years ago
#395 closed defect (fixed)
Support for pcap-ng / pcap nanosecond resolution
Reported by: | mbligh@… | Owned by: | rjs51 |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | libtrace-library | Version: | |
Keywords: | Cc: |
Description
Ugh. This thing doesn't seem to support attachement. There's no email address I can see.
diff --git a/trace/libtrace-3.0.18/lib/format_pcapfile.c b/trace/libtrace-3.0.18/lib/format_pcapfile.c index 2ef6417..71d6aff 100644 --- a/trace/libtrace-3.0.18/lib/format_pcapfile.c +++ b/trace/libtrace-3.0.18/lib/format_pcapfile.c @@ -71,6 +71,23 @@ typedef struct pcapfile_header_t {
uint32_t network; /* data link type */
} pcapfile_header_t;
+#define MAGIC1 0xa1b2c3d4 Original +#define MAGIC2 0xa1b23c4d Newer nanosecond format + +static inline int header_is_backwards_magic(pcapfile_header_t *header) {
header->magic_number == byteswap32(MAGIC2)); |
+} + +static inline int header_is_magic(pcapfile_header_t *header) {
header->magic_number == MAGIC2 |
+ header_is_backwards_magic(header)); +} + +static inline int trace_in_nanoseconds(pcapfile_header_t *header) { + Sadly, nothing seems to use sigfigs. Sigh.
header->magic_number == byteswap32(MAGIC2)); |
+} +
struct pcapfile_format_data_t {
struct {
/* Indicates whether the event API should replicate the pauses
@@ -98,18 +115,20 @@ static int pcapfile_probe_magic(io_t *io)
pcapfile_header_t header; int len; len = wandio_peek(io, &header, sizeof(header));
+
/* Is this long enough? */ if (len < (int)sizeof(header)) {
return 0;
} /* Pcap magic? */
header.magic_number == 0xd4c3b2a1) { |
+ if (header_is_magic(&header)) {
return 1;
} /* Nope, not pcap */ return 0;
}
+
static int pcapfile_init_input(libtrace_t *libtrace) {
libtrace->format_data = malloc(sizeof(struct pcapfile_format_data_t));
@@ -145,7 +164,7 @@ static inline uint16_t swaps(libtrace_t *libtrace, uint16_t num)
return num;
/* We can use the PCAP magic number to determine the byte order */
- if (DATA(libtrace)->header.magic_number == 0xd4c3b2a1)
+ if (header_is_backwards_magic(&(DATA(libtrace)->header)))
return byteswap16(num);
return num;
@@ -160,7 +179,7 @@ static inline uint32_t swapl(libtrace_t *libtrace, uint32_t num)
return num;
/* We can use the PCAP magic number to determine the byte order */
- if (DATA(libtrace)->header.magic_number == 0xd4c3b2a1)
+ if (header_is_backwards_magic(&(DATA(libtrace)->header)))
return byteswap32(num);
return num;
@@ -196,10 +215,10 @@ static int pcapfile_start_input(libtrace_t *libtrace)
return -1;
}
- if (swapl(libtrace,DATA(libtrace)->header.magic_number) !=
- 0xa1b2c3d4) {
+ if (!header_is_magic(&(DATA(libtrace)->header))) {
trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,
"Not a pcap tracefile (magic=%08x)\n",swapl(libtrace,DATA(libtrace)->header.magic_number));
+ fprintf(stderr, "Not a pcap tracefile (magic=%08x)\n",swapl(libtrace,DATA(libtrace)->header.magic_number));
return -1; /* Not a pcap file */
}
@@ -593,7 +612,28 @@ static struct timeval pcapfile_get_timeval(
hdr = (libtrace_pcapfile_pkt_hdr_t*)packet->header; ts.tv_sec = swapl(packet->trace,hdr->ts_sec);
- ts.tv_usec = swapl(packet->trace,hdr->ts_usec);
+ if (trace_in_nanoseconds(packet->header)) + ts.tv_usec = swapl(packet->trace, hdr->ts_usec) / 1000; + else + ts.tv_usec = swapl(packet->trace,hdr->ts_usec); + return ts; +} + +static struct timespec pcapfile_get_timespec( + const libtrace_packet_t *packet) +{ + libtrace_pcapfile_pkt_hdr_t *hdr; + pcapfile_header_t *header = &(DATA(packet->trace)->header); + struct timespec ts; + + assert(packet->header); + + hdr = (libtrace_pcapfile_pkt_hdr_t*)packet->header; + ts.tv_sec = swapl(packet->trace,hdr->ts_sec); + if (trace_in_nanoseconds(header)) + ts.tv_nsec = swapl(packet->trace, hdr->ts_usec); + else + ts.tv_nsec = swapl(packet->trace, hdr->ts_usec) * 1000;
return ts;
}
@@ -715,7 +755,7 @@ static struct libtrace_format_t pcapfile = {
NULL, /* set_direction */ NULL, /* get_erf_timestamp */ pcapfile_get_timeval, /* get_timeval */
- NULL, /* get_timespec */
+ pcapfile_get_timespec, /* get_timespec */
NULL, /* get_seconds */ NULL, /* seek_erf */ NULL, /* seek_timeval */
Attachments (1)
Change History (3)
Changed 7 years ago by rjs51
comment:1 Changed 7 years ago by rjs51
- Owner changed from salcock to rjs51
comment:2 Changed 7 years ago by rjs51
- Resolution set to fixed
- Status changed from new to closed
Applied r1852