aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-01-13 00:10:48 -0800
committerGuy Harris <guy@alum.mit.edu>2016-01-13 08:11:19 +0000
commit24324a026382eb9ac6b3d1e176443729cdcdc2b1 (patch)
treeaae459de213e38b5ca2075dcd633bd944e06f49b /wiretap
parent5539dba1df313816491bb28718433d4d81162aa3 (diff)
Clean up handling of the data before the Ethernet packet in ERF files.
The data before the Ethernet packet isn't a 16-bit little-endian integer, it's two bytes, one byte of offset and one byte of padding. Change-Id: I327b88f058dda184b79d3c2c6cf0dea52c0d28b1 Reviewed-on: https://code.wireshark.org/review/13254 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/erf.c20
-rw-r--r--wiretap/erf.h4
-rw-r--r--wiretap/pcap-common.c17
-rw-r--r--wiretap/wtap.h5
4 files changed, 32 insertions, 14 deletions
diff --git a/wiretap/erf.c b/wiretap/erf.c
index bb41f3c145..8daa0c3c9d 100644
--- a/wiretap/erf.c
+++ b/wiretap/erf.c
@@ -92,7 +92,7 @@ extern wtap_open_return_val erf_open(wtap *wth, int *err, gchar **err_info)
erf_timestamp_t prevts,ts;
erf_header_t header;
guint32 mc_hdr;
- guint16 eth_hdr;
+ struct erf_eth_hdr eth_hdr;
guint32 packet_size;
guint16 rlen;
guint64 erf_ext_header;
@@ -338,12 +338,12 @@ static gboolean erf_read_header(FILE_T fh,
guint32 *packet_size)
{
union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
- guint32 mc_hdr;
- guint32 aal2_hdr;
guint8 erf_exhdr[8];
guint64 erf_exhdr_sw;
guint8 type = 0;
- guint16 eth_hdr;
+ guint32 mc_hdr;
+ guint32 aal2_hdr;
+ struct wtap_erf_eth_hdr eth_hdr;
guint32 skiplen = 0;
int i = 0;
int max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
@@ -454,7 +454,12 @@ static gboolean erf_read_header(FILE_T fh,
*bytes_read += (guint32)sizeof(eth_hdr);
*packet_size -= (guint32)sizeof(eth_hdr);
skiplen += (guint32)sizeof(eth_hdr);
- pseudo_header->erf.subhdr.eth_hdr = g_ntohs(eth_hdr);
+ pseudo_header->erf.subhdr.eth_hdr = eth_hdr;
+ {
+ guint8 bytes[2];
+ memcpy(bytes, &eth_hdr, 2);
+ fprintf(stderr, "offset %u, pad %u\n", bytes[0], bytes[1]);
+ }
break;
case ERF_TYPE_MC_HDLC:
@@ -526,8 +531,7 @@ static int wtap_wtap_encap_to_erf_encap(int encap)
static gboolean erf_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header, int * err)
{
guint8 erf_hdr[sizeof(struct erf_mc_phdr)];
- guint8 erf_subhdr[((sizeof(struct erf_mc_hdr) > sizeof(struct erf_eth_hdr))?
- sizeof(struct erf_mc_hdr) : sizeof(struct erf_eth_hdr))];
+ guint8 erf_subhdr[sizeof(union erf_subhdr)];
guint8 ehdr[8*MAX_ERF_EHDR];
size_t size = 0;
size_t subhdr_size = 0;
@@ -564,7 +568,7 @@ static gboolean erf_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pse
case ERF_TYPE_COLOR_ETH:
case ERF_TYPE_DSM_COLOR_ETH:
case ERF_TYPE_COLOR_HASH_ETH:
- phtons(&erf_subhdr[0], pseudo_header->erf.subhdr.eth_hdr);
+ memcpy(&erf_subhdr[0], &pseudo_header->erf.subhdr.eth_hdr, sizeof pseudo_header->erf.subhdr.eth_hdr);
subhdr_size += (int)sizeof(struct erf_eth_hdr);
break;
default:
diff --git a/wiretap/erf.h b/wiretap/erf.h
index 894235c7ad..870db96140 100644
--- a/wiretap/erf.h
+++ b/wiretap/erf.h
@@ -120,11 +120,13 @@ typedef struct erf_aal2_hdr {
} erf_aal2_header_t;
typedef struct erf_eth_hdr {
- guint16 eth;
+ guint8 offset;
+ guint8 pad;
} erf_eth_header_t;
union erf_subhdr {
struct erf_mc_hdr mc_hdr;
+ struct erf_aal2_hdr aal2_hdr;
struct erf_eth_hdr eth_hdr;
};
diff --git a/wiretap/pcap-common.c b/wiretap/pcap-common.c
index 02be511875..3df298f6f5 100644
--- a/wiretap/pcap-common.c
+++ b/wiretap/pcap-common.c
@@ -1485,7 +1485,6 @@ pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
case ERF_TYPE_MC_ATM:
case ERF_TYPE_MC_RAW_CHANNEL:
case ERF_TYPE_MC_AAL5:
- case ERF_TYPE_MC_AAL2:
case ERF_TYPE_COLOR_MC_HDLC_POS:
/* Extract the Multi Channel header to include it in the pseudo header part */
if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_mc_header_t), err, err_info))
@@ -1493,13 +1492,20 @@ pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
pseudo_header->erf.subhdr.mc_hdr = pntoh32(&erf_subhdr[0]);
*psize = sizeof(erf_mc_header_t);
break;
+ case ERF_TYPE_MC_AAL2:
+ /* Extract the AAL2 header to include it in the pseudo header part */
+ if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_aal2_header_t), err, err_info))
+ return FALSE;
+ pseudo_header->erf.subhdr.aal2_hdr = pntoh32(&erf_subhdr[0]);
+ *psize = sizeof(erf_aal2_header_t);
+ break;
case ERF_TYPE_ETH:
case ERF_TYPE_COLOR_ETH:
case ERF_TYPE_DSM_COLOR_ETH:
/* Extract the Ethernet additional header to include it in the pseudo header part */
if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_eth_header_t), err, err_info))
return FALSE;
- pseudo_header->erf.subhdr.eth_hdr = pntoh16(&erf_subhdr[0]);
+ memcpy(&pseudo_header->erf.subhdr.eth_hdr, erf_subhdr, sizeof pseudo_header->erf.subhdr.eth_hdr);
*psize = sizeof(erf_eth_header_t);
break;
default:
@@ -2116,15 +2122,18 @@ pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pse
case ERF_TYPE_MC_ATM:
case ERF_TYPE_MC_RAW_CHANNEL:
case ERF_TYPE_MC_AAL5:
- case ERF_TYPE_MC_AAL2:
case ERF_TYPE_COLOR_MC_HDLC_POS:
phtonl(&erf_hdr[16], pseudo_header->erf.subhdr.mc_hdr);
size += (int)sizeof(struct erf_mc_hdr);
break;
+ case ERF_TYPE_MC_AAL2:
+ phtonl(&erf_hdr[16], pseudo_header->erf.subhdr.aal2_hdr);
+ size += (int)sizeof(struct erf_aal2_hdr);
+ break;
case ERF_TYPE_ETH:
case ERF_TYPE_COLOR_ETH:
case ERF_TYPE_DSM_COLOR_ETH:
- phtons(&erf_hdr[16], pseudo_header->erf.subhdr.eth_hdr);
+ memcpy(&erf_hdr[16], &pseudo_header->erf.subhdr.eth_hdr, sizeof pseudo_header->erf.subhdr.eth_hdr);
size += (int)sizeof(struct erf_eth_hdr);
break;
default:
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 39707abc15..c34547d491 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -938,7 +938,10 @@ struct erf_mc_phdr {
struct erf_ehdr ehdr_list[MAX_ERF_EHDR];
union
{
- guint16 eth_hdr;
+ struct wtap_erf_eth_hdr {
+ guint8 offset;
+ guint8 pad;
+ } eth_hdr;
guint32 mc_hdr;
guint32 aal2_hdr;
} subhdr;