diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-01-13 00:10:48 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-01-13 08:11:19 +0000 |
commit | 24324a026382eb9ac6b3d1e176443729cdcdc2b1 (patch) | |
tree | aae459de213e38b5ca2075dcd633bd944e06f49b | |
parent | 5539dba1df313816491bb28718433d4d81162aa3 (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>
-rw-r--r-- | epan/dissectors/packet-erf.c | 25 | ||||
-rw-r--r-- | wiretap/erf.c | 20 | ||||
-rw-r--r-- | wiretap/erf.h | 4 | ||||
-rw-r--r-- | wiretap/pcap-common.c | 17 | ||||
-rw-r--r-- | wiretap/wtap.h | 5 |
5 files changed, 42 insertions, 29 deletions
diff --git a/epan/dissectors/packet-erf.c b/epan/dissectors/packet-erf.c index 1d6075ae0f..8baf3888ff 100644 --- a/epan/dissectors/packet-erf.c +++ b/epan/dissectors/packet-erf.c @@ -41,11 +41,6 @@ void proto_reg_handoff_erf(void); #define EXT_HDR_TYPE_CHANNELISED 12 #define EXT_HDR_TYPE_SIGNATURE 14 -struct erf_eth_hdrx { - guint8 byte0; - guint8 byte1; -}; - #define DECHAN_MAX_LINE_RATE 5 #define DECHAN_MAX_VC_SIZE 5 #define DECHAN_MAX_AUG_INDEX 4 @@ -214,7 +209,7 @@ static int hf_erf_aal2_res1 = -1; /* ERF Ethernet header/pad */ static int hf_erf_eth = -1; static int hf_erf_eth_off = -1; -static int hf_erf_eth_res1 = -1; +static int hf_erf_eth_pad = -1; /* Initialize the subtree pointers */ static gint ett_erf = -1; @@ -990,15 +985,16 @@ dissect_eth_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if (tree) { proto_item *eth_item; proto_tree *eth_tree; - struct erf_eth_hdrx *eth_hdr; + guint8 eth_offset, eth_pad; eth_item = proto_tree_add_item(tree, hf_erf_eth, tvb, 0, 0, ENC_NA); eth_tree = proto_item_add_subtree(eth_item, ett_erf_eth); - eth_hdr = (struct erf_eth_hdrx *) (&pinfo->pseudo_header->erf.subhdr.eth_hdr); + eth_offset = pinfo->pseudo_header->erf.subhdr.eth_hdr.offset; + eth_pad = pinfo->pseudo_header->erf.subhdr.eth_hdr.pad; - proto_tree_add_uint(eth_tree, hf_erf_eth_off, tvb, 0, 0, eth_hdr->byte0); - proto_tree_add_uint(eth_tree, hf_erf_eth_res1, tvb, 0, 0, eth_hdr->byte1); + proto_tree_add_uint(eth_tree, hf_erf_eth_off, tvb, 0, 0, eth_offset); + proto_tree_add_uint(eth_tree, hf_erf_eth_pad, tvb, 0, 0, eth_pad); } } @@ -1811,11 +1807,10 @@ proto_register_erf(void) FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL } }, { &hf_erf_eth_off, { "Offset", "erf.eth.off", - FT_UINT8, BASE_DEC, NULL, ETH_OFF_MASK, NULL, HFILL } }, - { &hf_erf_eth_res1, - { "Reserved", "erf.eth.res1", - FT_UINT8, BASE_HEX, NULL, ETH_RES1_MASK, NULL, HFILL } }, - + FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } }, + { &hf_erf_eth_pad, + { "Padding", "erf.eth.pad", + FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } }, }; static gint *ett[] = { 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, ð_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; |