diff options
author | Guy Harris <guy@alum.mit.edu> | 2010-07-30 02:30:50 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2010-07-30 02:30:50 +0000 |
commit | 11b9ed0426b00dc822d4ab755821f7029b2d821d (patch) | |
tree | d02aa5f227d6806ed9d8c668ce15087b89566796 /wiretap | |
parent | 9a7e8cdddfab04ae270843ce3e310289b3428ad6 (diff) |
Define WTAP_ENCAP_IEEE802_15_4_NOFCS, for use in file formats that don't
include the FCS, and use it for the Daintree SNA file format. While
we're at it, explicitly check to make sure the purported packet length
gives it at least one byte of packet data, and fix some print formats to
use %u for unsigned values.
svn path=/trunk/; revision=33678
Diffstat (limited to 'wiretap')
-rw-r--r-- | wiretap/daintree-sna.c | 24 | ||||
-rw-r--r-- | wiretap/wtap.c | 5 | ||||
-rw-r--r-- | wiretap/wtap.h | 3 |
3 files changed, 21 insertions, 11 deletions
diff --git a/wiretap/daintree-sna.c b/wiretap/daintree-sna.c index c86d6891d0..a064557027 100644 --- a/wiretap/daintree-sna.c +++ b/wiretap/daintree-sna.c @@ -126,7 +126,7 @@ int daintree_sna_open(wtap *wth, int *err _U_, gchar **err_info _U_) /* set up for file type */ wth->file_type = WTAP_FILE_DAINTREE_SNA; - wth->file_encap = WTAP_ENCAP_IEEE802_15_4; + wth->file_encap = WTAP_ENCAP_IEEE802_15_4_NOFCS; wth->tsprecision = WTAP_FILE_TSPREC_USEC; return 1; /* it's a Daintree file */ @@ -153,12 +153,20 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset /* parse one line of capture data */ if (sscanf(readLine, "%*s %" G_GINT64_MODIFIER "u.%d %u %" READDATA_MAX_FIELD_SIZE "s", - &seconds, &wth->phdr.ts.nsecs, - &wth->phdr.len, readData) != 4) { - *err = WTAP_ERR_BAD_RECORD; - *err_info = g_strdup("daintree_sna: invalid read record"); - return FALSE; + &seconds, &wth->phdr.ts.nsecs, &wth->phdr.len, readData) != 4) { + *err = WTAP_ERR_BAD_RECORD; + *err_info = g_strdup("daintree_sna: invalid read record"); + return FALSE; + } + + /* Daintree doesn't store the FCS, but pads end of packet with 0xffff, which we toss */ + if (wth->phdr.len <= FCS_LENGTH) { + *err = WTAP_ERR_BAD_RECORD; + *err_info = g_strdup_printf("daintree_sna: packet length <= %u bytes, no frame data present", + FCS_LENGTH); + return FALSE; } + wth->phdr.len -= FCS_LENGTH; wth->phdr.ts.secs = (time_t) seconds; wth->phdr.ts.nsecs *= 1000; /* convert mS to nS */ @@ -167,13 +175,11 @@ daintree_sna_read(wtap *wth, int *err, gchar **err_info _U_, gint64 *data_offset * packet length field, write data to frame buffer */ if ((wth->phdr.caplen = daintree_sna_hex_char(readData, err)) > FCS_LENGTH) { if (wth->phdr.caplen <= wth->phdr.len) { - /* Daintree doesn't store the FCS, but pads end of packet with 0xffff, which we toss */ - wth->phdr.caplen -= FCS_LENGTH; buffer_assure_space(wth->frame_buffer, wth->phdr.caplen); memcpy(buffer_start_ptr(wth->frame_buffer), readData, wth->phdr.caplen); } else { *err = WTAP_ERR_BAD_RECORD; - *err_info = g_strdup_printf("daintree_sna: capture length (%d) > packet length (%d)", + *err_info = g_strdup_printf("daintree_sna: capture length (%u) > packet length (%u)", wth->phdr.caplen, wth->phdr.len); return FALSE; } diff --git a/wiretap/wtap.c b/wiretap/wtap.c index 1ac731a123..6ce9f32d16 100644 --- a/wiretap/wtap.c +++ b/wiretap/wtap.c @@ -473,7 +473,10 @@ static struct encap_type_info encap_table_base[] = { { "SocketCAN", "socketcan" }, /* WTAP_ENCAP_IEEE802_11_NETMON_RADIO */ - { "IEEE 802.11 plus Network Monitor radio header", "ieee-802-11-netmon" } + { "IEEE 802.11 plus Network Monitor radio header", "ieee-802-11-netmon" }, + + /* WTAP_ENCAP_IEEE802_15_4_NOFCS */ + { "IEEE 802.15.4 Wireless PAN with FCS not present", "wpan-nofcs" }, }; gint wtap_num_encap_types = sizeof(encap_table_base) / sizeof(struct encap_type_info); diff --git a/wiretap/wtap.h b/wiretap/wtap.h index c726a99e0d..3a9261a1f3 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -215,7 +215,8 @@ extern "C" { #define WTAP_ENCAP_JPEG_JFIF 123 #define WTAP_ENCAP_IPNET 124 #define WTAP_ENCAP_SOCKETCAN 125 -#define WTAP_ENCAP_IEEE802_11_NETMON_RADIO 126 +#define WTAP_ENCAP_IEEE802_11_NETMON_RADIO 126 +#define WTAP_ENCAP_IEEE802_15_4_NOFCS 127 #define WTAP_NUM_ENCAP_TYPES wtap_get_num_encap_types() |