diff options
author | Anders Broman <anders.broman@ericsson.com> | 2007-10-15 18:39:58 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2007-10-15 18:39:58 +0000 |
commit | 721796617d2f4353eef25b1e08945951917c4e65 (patch) | |
tree | cf6c57fe8c03dc5f58ca67697fef27d91d116380 | |
parent | 4644ce72634f90e866519faf0a06aca2f7adee12 (diff) | |
download | wireshark-721796617d2f4353eef25b1e08945951917c4e65.tar.gz wireshark-721796617d2f4353eef25b1e08945951917c4e65.tar.bz2 wireshark-721796617d2f4353eef25b1e08945951917c4e65.zip |
From Peter Johansson:
addressing the compilation problems
svn path=/trunk/; revision=23188
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | plugins/ethercat/packet-ams.c | 64 | ||||
-rw-r--r-- | plugins/ethercat/packet-ams.h | 201 | ||||
-rw-r--r-- | plugins/ethercat/packet-ecatmb.h | 56 | ||||
-rw-r--r-- | plugins/ethercat/packet-ethercat-datagram.c | 44 | ||||
-rw-r--r-- | plugins/ethercat/packet-ethercat-datagram.h | 19 | ||||
-rw-r--r-- | plugins/ethercat/packet-ethercat-frame.c | 19 | ||||
-rw-r--r-- | plugins/ethercat/packet-ethercat-frame.h | 17 | ||||
-rw-r--r-- | plugins/ethercat/packet-ioraw.c | 4 | ||||
-rw-r--r-- | plugins/ethercat/packet-ioraw.h | 6 | ||||
-rw-r--r-- | plugins/ethercat/packet-nv.c | 45 | ||||
-rw-r--r-- | plugins/ethercat/packet-nv.h | 13 |
13 files changed, 195 insertions, 295 deletions
diff --git a/Makefile.am b/Makefile.am index bd869b36ca..c4f1a86057 100644 --- a/Makefile.am +++ b/Makefile.am @@ -228,6 +228,7 @@ plugin_ldadd = \ -dlopen plugins/ciscosm/ciscosm.la \ -dlopen plugins/docsis/docsis.la \ -dlopen plugins/enttec/enttec.la \ + -dlopen plugins/ethercat/ethercat.la \ -dlopen plugins/giop/cosnaming.la \ -dlopen plugins/giop/coseventcomm.la \ -dlopen plugins/gryphon/gryphon.la \ diff --git a/configure.in b/configure.in index 7047fe7dd1..03d9a76cd1 100644 --- a/configure.in +++ b/configure.in @@ -1565,6 +1565,7 @@ AC_OUTPUT( plugins/ciscosm/Makefile plugins/docsis/Makefile plugins/enttec/Makefile + plugins/ethercat/Makefile plugins/giop/Makefile plugins/gryphon/Makefile plugins/irda/Makefile diff --git a/plugins/ethercat/packet-ams.c b/plugins/ethercat/packet-ams.c index 725e68b93e..7a2e7ff40d 100644 --- a/plugins/ethercat/packet-ams.c +++ b/plugins/ethercat/packet-ams.c @@ -378,12 +378,12 @@ static const value_string AdsErrorMode[] = static void NetIdFormater(tvbuff_t *tvb, guint offset, char *szText, gint nMax) { - g_snprintf ( szText, nMax, "%d.%d.%d.%d.%d.%d", tvb_get_guint8(tvb, offset++), - tvb_get_guint8(tvb, offset++), - tvb_get_guint8(tvb, offset++), - tvb_get_guint8(tvb, offset++), - tvb_get_guint8(tvb, offset++), - tvb_get_guint8(tvb, offset) + g_snprintf ( szText, nMax, "%d.%d.%d.%d.%d.%d", tvb_get_guint8(tvb, offset), + tvb_get_guint8(tvb, offset+1), + tvb_get_guint8(tvb, offset+2), + tvb_get_guint8(tvb, offset+3), + tvb_get_guint8(tvb, offset+4), + tvb_get_guint8(tvb, offset+5) ); } @@ -410,14 +410,14 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( pinfo->ethertype != 0x88a4 ) { - if( sizeof(TcpAdsParserHDR) > ams_length ) + if( TcpAdsParserHDR_Len > ams_length ) return; - ams_length -= sizeof(TcpAdsParserHDR); + ams_length -= TcpAdsParserHDR_Len; - offset = sizeof(TcpAdsParserHDR); + offset = TcpAdsParserHDR_Len; } - if( ams_length < sizeof(AmsHead) ) + if( ams_length < AmsHead_Len ) return; if (tree) @@ -426,15 +426,15 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) ams_tree = proto_item_add_subtree(ti, ett_ams); NetIdFormater(tvb, offset, szText, nMax); - proto_tree_add_string(ams_tree, hf_ams_targetnetid, tvb, offset, sizeof(AmsNetId), szText); - offset += sizeof(AmsNetId); + proto_tree_add_string(ams_tree, hf_ams_targetnetid, tvb, offset, AmsNetId_Len, szText); + offset += AmsNetId_Len; proto_tree_add_item(ams_tree, hf_ams_targetport, tvb, offset, sizeof(guint16), TRUE); offset += sizeof(guint16); NetIdFormater(tvb, offset, szText, nMax); - proto_tree_add_string(ams_tree, hf_ams_sendernetid, tvb, offset, sizeof(AmsNetId), szText); - offset += sizeof(AmsNetId); + proto_tree_add_string(ams_tree, hf_ams_sendernetid, tvb, offset, AmsNetId_Len, szText); + offset += AmsNetId_Len; proto_tree_add_item(ams_tree, hf_ams_senderport, tvb, offset, sizeof(guint16), TRUE); offset += sizeof(guint16); @@ -468,7 +468,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } else { - offset+=sizeof(AmsHead); + offset+=AmsHead_Len; } if ( (stateflags & AMSCMDSF_ADSCMD) != 0 ) @@ -487,7 +487,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsreadrequest, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsReadReq) ) + if( ams_length-offset >= TAdsReadReq_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsreadrequest); proto_tree_add_item(ams_adstree, hf_ams_adsindexgroup, tvb, offset, sizeof(guint32), TRUE); @@ -510,7 +510,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adswriterequest, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsWriteReq) - sizeof(guint16) ) + if( ams_length-offset >= TAdsWriteReq_Len - sizeof(guint16) ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adswriterequest); proto_tree_add_item(ams_adstree, hf_ams_adsindexgroup, tvb, offset, 4, TRUE); @@ -535,7 +535,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsreadwriterequest, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsReadWriteReq) - sizeof(guint16)) + if( ams_length-offset >= TAdsReadWriteReq_Len - sizeof(guint16)) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsreadwriterequest); proto_tree_add_item(ams_adstree, hf_ams_adsindexgroup, tvb, offset, sizeof(guint32), TRUE); @@ -563,7 +563,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsreadstaterequest, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsReadStateReq) ) + if( ams_length-offset >= TAdsReadStateReq_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsreadstaterequest); proto_tree_add_item(ams_adstree, hf_ams_adsinvokeid, tvb, offset, sizeof(guint32), TRUE); @@ -579,7 +579,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adswritectrlrequest, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsWriteControlReq) - sizeof(guint16) ) + if( ams_length-offset >= TAdsWriteControlReq_Len - sizeof(guint16) ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adswritectrlrequest); proto_tree_add_item(ams_adstree, hf_ams_adsstate, tvb, offset, 2, TRUE); @@ -604,7 +604,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsreaddinforequest, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsReadDeviceInfoReq) ) + if( ams_length-offset >= TAdsReadDeviceInfoReq_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsreaddinforequest); proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, sizeof(guint32), TRUE); @@ -620,7 +620,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsadddnrequest, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsAddDeviceNotificationReq) ) + if( ams_length-offset >= TAdsAddDeviceNotificationReq_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsadddnrequest); proto_tree_add_item(ams_adstree, hf_ams_adsindexgroup, tvb, offset, sizeof(guint32), TRUE); @@ -652,7 +652,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsdeldnrequest, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsDelDeviceNotificationReq) ) + if( ams_length-offset >= TAdsDelDeviceNotificationReq_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsdeldnrequest); proto_tree_add_item(ams_adstree, hf_ams_adsnotificationhandle, tvb, offset, sizeof(guint32), TRUE); @@ -671,7 +671,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) guint32 nStamps;*/ aitem = proto_tree_add_item(ams_tree, hf_ams_adsdnrequest, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsDeviceNotificationReq) - sizeof(AdsNotificationSample) ) + if( ams_length-offset >= TAdsDeviceNotificationReq_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsdnrequest); proto_tree_add_item(ams_adstree, hf_ams_adscblength, tvb, offset, sizeof(guint32), TRUE); @@ -702,7 +702,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsreadresponse, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsReadRes) - sizeof(guint16) ) + if( ams_length-offset >= TAdsReadRes_Len - sizeof(guint16) ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsreadresponse); proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, sizeof(guint32), TRUE); @@ -724,7 +724,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adswriteresponse, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsWriteRes) ) + if( ams_length-offset >= TAdsWriteRes_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adswriteresponse); proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, sizeof(guint32), TRUE); @@ -740,7 +740,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsreadwriteresponse, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsReadWriteRes) - sizeof(guint16) ) + if( ams_length-offset >= TAdsReadWriteRes_Len - sizeof(guint16) ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsreadwriteresponse); proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, sizeof(guint32), TRUE); @@ -762,7 +762,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsreadstateresponse, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsReadStateRes) ) + if( ams_length-offset >= TAdsReadStateRes_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsreadstateresponse); proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, sizeof(guint32), TRUE); @@ -784,7 +784,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adswritectrlresponse, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsWriteControlRes) ) + if( ams_length-offset >= TAdsWriteControlRes_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adswritectrlresponse); proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, sizeof(guint32), TRUE); @@ -800,7 +800,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsreaddinforesponse, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsReadDeviceInfoRes) ) + if( ams_length-offset >= TAdsReadDeviceInfoRes_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsreaddinforesponse); proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, sizeof(guint32), TRUE); @@ -824,7 +824,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsadddnresponse, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsAddDeviceNotificationRes) ) + if( ams_length-offset >= TAdsAddDeviceNotificationRes_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsadddnresponse); proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, sizeof(guint32), TRUE); @@ -843,7 +843,7 @@ static void dissect_ams(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if( tree ) { aitem = proto_tree_add_item(ams_tree, hf_ams_adsdeldnresponse, tvb, offset, ams_length-offset, TRUE); - if( ams_length-offset >= sizeof(TAdsDelDeviceNotificationRes) ) + if( ams_length-offset >= TAdsDelDeviceNotificationRes_Len ) { ams_adstree = proto_item_add_subtree(aitem, ett_ams_adsdeldnresponse); proto_tree_add_item(ams_adstree, hf_ams_adsresult, tvb, offset, sizeof(guint32), TRUE); diff --git a/plugins/ethercat/packet-ams.h b/plugins/ethercat/packet-ams.h index 77ef980125..d1a6effdf6 100644 --- a/plugins/ethercat/packet-ams.h +++ b/plugins/ethercat/packet-ams.h @@ -671,20 +671,17 @@ typedef enum #define MACHINEIDENTRYDONTCARE 0xFF #define AMS_NETIDLEN 23 -/* Ensure the same data layout for all platforms */ -#pragma pack(push, 1) - typedef struct AmsNetId_ { guint8 b[6]; -} AmsNetId, *PAmsNetId; - +} AmsNetId; +#define AmsNetId_Len sizeof(AmsNetId) typedef struct AmsAddr_ { AmsNetId netId; guint16 port; -} AmsAddr, *PAmsAddr; +} AmsAddr; typedef union ErrCodeUnion { @@ -712,7 +709,8 @@ typedef struct ErrCodeUnion anErrCodeUnion; UserUnion aUserUnion; -} AmsHead, *PAmsHead; +} AmsHead; +#define AmsHead_Len sizeof(AmsHead) /* State flags */ @@ -735,9 +733,6 @@ typedef struct AmsHead head; } AmsCmd, *PAmsCmd; -#define SIZEOF_AmsCmd(p) (sizeof(AmsHead) + ((PAmsCmd)p)->head.cbData) - -#pragma pack(pop) /* ADS */ @@ -844,8 +839,6 @@ typedef struct #define ADSIGRP_ECAT_VOE 0xF430 -#define ADS_NOTIFICATIONBLOCKSIZE (sizeof(AdsNotificationBlock)-1) - typedef enum nAdsState { ADSSTATE_INVALID =0, @@ -985,100 +978,55 @@ typedef enum nAdsTransMode #define ANYSIZE_ARRAY 1 #endif -#ifndef UNALIGNED - #define UNALIGNED -#endif - /* ADS AMS command */ -/* Ensure the same data layout for all platforms */ -#pragma pack(push, 1) - -typedef struct -{ - AmsHead head; - guint16 firstDataWord; -} AdsAmsCmd, *PAdsAmsCmd; - -typedef struct -{ - guint8 version; - guint8 revision; - guint16 build; -} AdsVersion, *PAdsVersion; - -typedef struct -{ - guint32 hNotification; - guint32 cbSampleSize; - guint8 data[ANYSIZE_ARRAY]; -} AdsNotificationSample, *PAdsNotificationSample; - -typedef struct -{ - gint64 nTimeStamp; - guint32 nSamples; - AdsNotificationSample tSample[ANYSIZE_ARRAY]; -} AdsStampHeader, *PAdsStampHeader; - - -typedef struct -{ - guint32 nStamps; - AdsStampHeader tStamp[ANYSIZE_ARRAY]; -} AdsNotificationStream, *PAdsNotificationStream; - - -typedef struct +/*typedef struct { guint32 hNotification; - gint64 nTimeStamp; guint32 cbSampleSize; guint8 data[ANYSIZE_ARRAY]; -} AdsNotificationHeader, *PAdsNotificationHeader; - -typedef struct -{ - guint32 cbLength; - ADSTRANSMODE nTransMode; - guint32 nMaxDelay; - guint32 nCycleTime; - guint8 nCmpMax[sizeof(double)]; - guint8 nCmpMin[sizeof(double)]; -} AdsNotificationAttrib, *PAdsNotificationAttrib; +} AdsNotificationSample, *PAdsNotificationSample;*/ +#define AdsNotificationSample_Min_Len 4 typedef struct { guint32 invokeId; -} TAdsReadDeviceInfoReq, *PTAdsReadDeviceInfoReq, TAdsReadDeviceInfoInd, *PTAdsReadDeviceInfoInd; +} TAdsReadDeviceInfoReq; -typedef struct +#define TAdsReadDeviceInfoReq_Len sizeof(TAdsReadDeviceInfoReq) + +/*typedef struct { guint16 adsState; guint16 deviceState; guint32 cbLength; guint16 firstDataWord; -} TAdsWriteControlReq, *PTAdsWriteControlReq, TAdsWriteControlInd, *PTAdsWriteControlInd; +} TAdsWriteControlReq, TAdsWriteControlInd;*/ +#define TAdsWriteControlReq_Len 10 typedef struct { guint32 invokeId; -} TAdsReadStateReq, *PTAdsReadStateReq, TAdsReadStateInd, *PTAdsReadStateInd; +} TAdsReadStateReq; +#define TAdsReadStateReq_Len sizeof(TAdsReadStateReq) typedef struct { guint32 indexGroup; guint32 indexOffset; guint32 cbLength; -} TAdsReadReq, *PTAdsReadReq, TAdsReadInd, *PTAdsReadInd; +} TAdsReadReq; +#define TAdsReadReq_Len sizeof(TAdsReadReq) -typedef struct +/*typedef struct { guint32 indexGroup; guint32 indexOffset; guint32 cbLength; guint16 firstDataWord; -} TAdsWriteReq, *PTAdsWriteReq, TAdsWriteInd, *PTAdsWriteInd; +} TAdsWriteReq;*/ +#define TAdsWriteReq_Len 14 +/* typedef struct { guint32 indexGroup; @@ -1086,126 +1034,119 @@ typedef struct guint32 cbReadLength; guint32 cbWriteLength; guint16 firstDataWord; -} TAdsReadWriteReq, *PTAdsReadWriteReq, TAdsReadWriteInd, *PTAdsReadWriteInd; +} TAdsReadWriteReq;*/ +#define TAdsReadWriteReq_Len 18 + +typedef struct +{ + guint32 cbLength; + guint32 nTransMode; + guint32 nMaxDelay; + guint32 nCycleTime; + guint8 nCmpMax[sizeof(double)]; + guint8 nCmpMin[sizeof(double)]; +} AdsNotificationAttrib; typedef struct { guint32 indexGroup; guint32 indexOffset; AdsNotificationAttrib noteAttrib; -} TAdsAddDeviceNotificationReq, *PTAdsAddDeviceNotificationReq, - TAdsAddDeviceNotificationInd, *PTAdsAddDeviceNotificationInd; +} TAdsAddDeviceNotificationReq; +#define TAdsAddDeviceNotificationReq_Len sizeof(TAdsAddDeviceNotificationReq) typedef struct { guint32 hNotification; -} TAdsDelDeviceNotificationReq, *PTAdsDelDeviceNotificationReq, - TAdsDelDeviceNotificationInd, *PTAdsDelDeviceNotificationInd; +} TAdsDelDeviceNotificationReq; +#define TAdsDelDeviceNotificationReq_Len sizeof(TAdsDelDeviceNotificationReq) typedef struct { - guint32 cbLength; - AdsNotificationStream noteBlocks; -} TAdsDeviceNotificationReq, *PTAdsDeviceNotificationReq, - TAdsDeviceNotificationInd, *PTAdsDeviceNotificationInd; - + guint32 cbLength; + guint32 nStamps; +} TAdsDeviceNotificationReq; +#define TAdsDeviceNotificationReq_Len sizeof(TAdsDeviceNotificationReq) typedef struct { guint32 result; -} TAdsCon, *PTAdsCon, TAdsRes, *PTAdsRes; +} TAdsRes; +#define TAdsRes_Len sizeof(TAdsRes) + +typedef struct +{ + guint8 version; + guint8 revision; + guint16 build; +} AdsVersion, *PAdsVersion; typedef struct { guint32 result; AdsVersion version; char sName[ADS_FIXEDNAMESIZE]; -} TAdsReadDeviceInfoRes, *PTAdsReadDeviceInfoRes, TAdsReadDeviceInfoCon, *PTAdsReadDeviceInfoCon; +} TAdsReadDeviceInfoRes; +#define TAdsReadDeviceInfoRes_Len sizeof(TAdsReadDeviceInfoRes) typedef struct { guint32 result; -} TAdsWriteControlRes, *PTAdsWriteControlRes, TAdsWriteControlCon, *PTAdsWriteControlCon; +} TAdsWriteControlRes; +#define TAdsWriteControlRes_Len sizeof(TAdsWriteControlRes) typedef struct { guint32 result; guint16 adsState; guint16 deviceState; -} TAdsReadStateRes, *PTAdsReadStateRes, TAdsReadStateCon, *PTAdsReadStateCon; +} TAdsReadStateRes; +#define TAdsReadStateRes_Len sizeof(TAdsReadStateRes) typedef struct { guint32 result; guint32 cbLength; guint16 firstDataWord; -} TAdsReadRes, *PTAdsReadRes, TAdsReadCon, *PTAdsReadCon; +} TAdsReadRes; +#define TAdsReadRes_Len sizeof(TAdsReadRes) typedef struct { guint32 result; guint32 cbLength; guint16 firstDataWord; -} TAdsReadWriteRes, *PTAdsReadWriteRes, TAdsReadWriteCon, *PTAdsReadWriteCon; +} TAdsReadWriteRes; +#define TAdsReadWriteRes_Len sizeof(TAdsReadWriteRes) typedef struct { guint32 result; -} TAdsWriteRes, *PTAdsWriteRes, TAdsWriteCon, *PTAdsWriteCon; +} TAdsWriteRes; +#define TAdsWriteRes_Len sizeof(TAdsWriteRes) typedef struct { guint32 result; guint32 handle; -} TAdsAddDeviceNotificationRes, *PTAdsAddDeviceNotificationRes, - TAdsAddDeviceNotificationCon, *PTAdsAddDeviceNotificationCon; +} TAdsAddDeviceNotificationRes; +#define TAdsAddDeviceNotificationRes_Len sizeof(TAdsAddDeviceNotificationRes) typedef struct { guint32 result; -} TAdsDelDeviceNotificationRes, *PTAdsDelDeviceNotificationRes, - TAdsDelDeviceNotificationCon, *PTAdsDelDeviceNotificationCon; +} TAdsDelDeviceNotificationRes; +#define TAdsDelDeviceNotificationRes_Len sizeof(TAdsDelDeviceNotificationRes) /* structure for decoding the header -----------------------------------------*/ -typedef struct +/*typedef struct { guint16 reserved; - guint16 cbLength[2]; + guint32 cbLength; } TcpAdsParserHDR; -typedef TcpAdsParserHDR UNALIGNED *PTcpAdsParserHDR; - -typedef union tAdsUnion -{ - TAdsReadReq readReq; - TAdsReadRes readRes; - TAdsWriteReq writeReq; - TAdsWriteRes writeRes; - TAdsReadWriteReq rwReq; - TAdsReadWriteRes rwRes; - TAdsReadDeviceInfoReq infoReq; - TAdsReadDeviceInfoRes infoRes; - TAdsWriteControlReq writeCtrlReq; - TAdsWriteControlRes writeCtrlRes; - TAdsReadStateReq readStateReq; - TAdsReadStateRes readStateRes; - TAdsAddDeviceNotificationReq addDnReq; - TAdsAddDeviceNotificationRes addDnRes; - TAdsDelDeviceNotificationReq delDnReq; - TAdsDelDeviceNotificationRes delDnRes; - TAdsDeviceNotificationReq dnReq; - TAdsReadDeviceInfoReq readDInfoReq; - TAdsReadDeviceInfoRes readDInfoRes; -} AdsUnion; - -typedef struct _AdsParser -{ - AmsHead ams; - - AdsUnion anAdsUnion; -} AdsParserHDR; -typedef AdsParserHDR UNALIGNED *PAdsParserHDR; +typedef TcpAdsParserHDR;*/ +#define TcpAdsParserHDR_Len 6 -#pragma pack(pop) #endif diff --git a/plugins/ethercat/packet-ecatmb.h b/plugins/ethercat/packet-ecatmb.h index 4b163c12c9..c2061564be 100644 --- a/plugins/ethercat/packet-ecatmb.h +++ b/plugins/ethercat/packet-ecatmb.h @@ -26,7 +26,6 @@ #define _PACKET_ECATMAILBOX_H_ /* Ensure the same data layout for all platforms */ -#pragma pack(push, 1) typedef struct TETHERNET_ADDRESS { @@ -80,25 +79,8 @@ typedef struct TETHERCAT_MBOX_HEADER #define EOE_RESULT_NO_IP_SUPPORT 0x0201 #define EOE_RESULT_NO_MACFILTERMASK_SUPPORT 0x0401 -static char* EoEResultText(guint16 result) -{ - switch (result) - { - case EOE_RESULT_NOERROR: - return "No error"; - case EOE_RESULT_UNSPECIFIED_ERROR: - return "Unspecified error"; - case EOE_RESULT_UNSUPPORTED_TYPE: - return "Unsupported type"; - case EOE_RESULT_NO_IP_SUPPORT: - return "No IP support"; - case EOE_RESULT_NO_MACFILTERMASK_SUPPORT: - return "No MAC filter support"; - } - return ""; -} - -typedef struct TETHERCAT_EOE_INIT + +/*typedef struct TETHERCAT_EOE_INIT { guint32 ContainsMacAddr :1; guint32 ContainsIpAddr :1; @@ -113,8 +95,8 @@ typedef struct TETHERCAT_EOE_INIT guint32 DefaultGateway; guint32 DnsServer; char DnsName[32]; -} ETHERCAT_EOE_INIT, *PETHERCAT_EOE_INIT; -#define ETHERCAT_EOE_INIT_LEN sizeof(ETHERCAT_EOE_INIT) +} ETHERCAT_EOE_INIT, *PETHERCAT_EOE_INIT;*/ +#define ETHERCAT_EOE_INIT_LEN 58 /*sizeof(ETHERCAT_EOE_INIT)*/ typedef union tEoeMacFilterOptionsUnion { @@ -135,13 +117,13 @@ typedef struct TETHERCAT_EOE_MACFILTER EoeMacFilterOptionsUnion anEoeMacFilterOptionsUnion; ETHERNET_ADDRESS MacFilter[16]; ETHERNET_ADDRESS MacFilterMask[4]; -} ETHERCAT_EOE_MACFILTER, *PETHERCAT_EOE_MACFILTER; +} ETHERCAT_EOE_MACFILTER; #define ETHERCAT_EOE_MACFILTER_LEN sizeof(ETHERCAT_EOE_MACFILTER) typedef struct TETHERCAT_EOE_TIMESTAMP { guint32 TimeStamp; /* 32 bit time stamp */ -} ETHERCAT_EOE_TIMESTAMP, *PETHERCAT_EOE_TIMESTAMP; +} ETHERCAT_EOE_TIMESTAMP; #define ETHERCAT_EOE_TIMESTAMP_LEN sizeof(ETHERCAT_EOE_TIMESTAMP) typedef union tEoeHeaderDataUnion @@ -170,7 +152,6 @@ typedef union tEoeHeaderInfoUnion guint16 Info; } EoeHeaderInfoUnion; - typedef struct TETHERCAT_EOE_HEADER { EoeHeaderInfoUnion anEoeHeaderInfoUnion; @@ -201,8 +182,6 @@ typedef union TETHERCAT_COE_HEADER } ETHERCAT_COE_HEADER, *PETHERCAT_COE_HEADER; #define ETHERCAT_COE_HEADER_LEN sizeof(ETHERCAT_COE_HEADER) -#pragma pack(pop) -/*ETHERCAT_SDO_HEADER not naturally aligned -> can't use pragma pack 1*/ typedef union tSdoHeaderUnion { @@ -278,8 +257,6 @@ typedef struct TETHERCAT_SDO_HEADER #define ETHERCAT_SDO_HEADER_LEN 8 /* sizeof(ETHERCAT_SDO_HEADER)*/ -#pragma pack(push,1) - #define SDO_CCS_DOWNLOAD_SEGMENT 0 #define SDO_CCS_INITIATE_DOWNLOAD 1 #define SDO_CCS_INITIATE_UPLOAD 2 @@ -326,7 +303,7 @@ typedef struct TETHERCAT_SDO_INFO_LIST { guint16 Index[1]; } Res; -} ETHERCAT_SDO_INFO_LIST, *PETHERCAT_SDO_INFO_LIST; +} ETHERCAT_SDO_INFO_LIST; typedef struct TETHERCAT_SDO_INFO_OBJ { @@ -338,7 +315,7 @@ typedef struct TETHERCAT_SDO_INFO_OBJ guint8 ObjCode; /* defined in DS 301 (Table 37)*/ char Name[1]; /* rest of mailbox data*/ } Res; -} ETHERCAT_SDO_INFO_OBJ, *PETHERCAT_SDO_INFO_OBJ; +} ETHERCAT_SDO_INFO_OBJ; typedef struct TETHERCAT_SDO_INFO_ENTRY { @@ -352,13 +329,13 @@ typedef struct TETHERCAT_SDO_INFO_ENTRY guint16 BitLen; guint16 ObjAccess; /* bit0 = read; bit1 = write; bit2 = const. bit3 = 'PRE-OP'; bit4 = 'SAFE-OP'; bit5 = 'OP'.*/ } Res; -} ETHERCAT_SDO_INFO_ENTRY, *PETHERCAT_SDO_INFO_ENTRY; +} ETHERCAT_SDO_INFO_ENTRY; typedef struct TETHERCAT_SDO_INFO_ERROR { guint32 ErrorCode; char ErrorText[1]; /* rest of mailbox data */ -} ETHERCAT_SDO_INFO_ERROR, *PETHERCAT_SDO_INFO_ERROR; +} ETHERCAT_SDO_INFO_ERROR; typedef union tSdoInfoUnion { @@ -387,9 +364,7 @@ typedef struct TETHERCAT_SDO_INFO_HEADER SdoInfoUnion anSdoInfoUnion; } ETHERCAT_SDO_INFO_HEADER, *PETHERCAT_SDO_INFO_HEADER; -#define ETHERCAT_SDO_INFO_LISTREQ_LEN offsetof(ETHERCAT_SDO_INFO_HEADER, anSdoInfoUnion.List.Res) -#define ETHERCAT_SDO_INFO_OBJREQ_LEN offsetof(ETHERCAT_SDO_INFO_HEADER, anSdoInfoUnionObj.Res) -#define ETHERCAT_SDO_INFO_ENTRYREQ_LEN offsetof(ETHERCAT_SDO_INFO_HEADER, anSdoInfoUnionEntry.Res) +#define ETHERCAT_SDO_INFO_LISTREQ_LEN 6 /*offsetof(ETHERCAT_SDO_INFO_HEADER, anSdoInfoUnion.List.Res)*/ /* FoE (File Access over EtherCAT)*/ #define ECAT_FOE_OPMODE_RRQ 1 @@ -410,9 +385,6 @@ typedef struct TETHERCAT_SDO_INFO_HEADER #define ECAT_FOE_ERRCODE_BOOTSTRAPONLY 8 #define ECAT_FOE_ERRCODE_NOTINBOOTSTRAP 9 -#pragma pack(pop) -/*ETHERCAT_FOE_HEADER is not naturally aligned --> can't use pragma pack 1*/ - typedef union tFoeHeaderDataUnion { guint32 FileLength; /* (RRQ, WRQ) = 0 if unknown */ @@ -444,8 +416,6 @@ typedef struct TETHERCAT_FOE_HEADER } ETHERCAT_FOE_HEADER, *PETHERCAT_FOE_HEADER; #define ETHERCAT_FOE_HEADER_LEN 6 /*sizeof(ETHERCAT_FOE_HEADER)*/ -#pragma pack(push,1) - typedef struct { guint16 Cmd; @@ -507,10 +477,6 @@ typedef struct TETHERCAT_SOE_HEADER } ETHERCAT_SOE_HEADER, *PETHERCAT_SOE_HEADER; #define ETHERCAT_SOE_HEADER_LEN sizeof(ETHERCAT_SOE_HEADER) - - -#pragma pack(pop) - extern void init_mbx_header(PETHERCAT_MBOX_HEADER pMbox, tvbuff_t *tvb, gint offset); #endif diff --git a/plugins/ethercat/packet-ethercat-datagram.c b/plugins/ethercat/packet-ethercat-datagram.c index 7f8e3517b8..0714e5ee17 100644 --- a/plugins/ethercat/packet-ethercat-datagram.c +++ b/plugins/ethercat/packet-ethercat-datagram.c @@ -257,8 +257,8 @@ static void init_EcParserHDR(EcParserHDR* pHdr, tvbuff_t *tvb, gint offset) { pHdr->cmd = tvb_get_guint8(tvb, offset++); pHdr->idx = tvb_get_guint8(tvb, offset++); - pHdr->adp = tvb_get_letohs(tvb, offset); offset+=sizeof(guint16); - pHdr->ado = tvb_get_letohs(tvb, offset); offset+=sizeof(guint16); + pHdr->anAddrUnion.adp = tvb_get_letohs(tvb, offset); offset+=sizeof(guint16); + pHdr->anAddrUnion.ado = tvb_get_letohs(tvb, offset); offset+=sizeof(guint16); pHdr->len = tvb_get_letohs(tvb, offset); offset+=sizeof(guint16); pHdr->intr = tvb_get_letohs(tvb, offset); } @@ -327,7 +327,7 @@ static void EcSummaryFormater(guint32 datalength, tvbuff_t *tvb, gint offset, ch guint16 len = ecFirst.len&0x07ff; guint16 cnt = get_wc(&ecFirst, tvb, offset); g_snprintf ( szText, nMax, "'%s', Len: %d, Adp 0x%x, Ado 0x%x, Wc %d ", - convertEcCmdToText(ecFirst.cmd), len, ecFirst.adp, ecFirst.ado, cnt ); + convertEcCmdToText(ecFirst.cmd), len, ecFirst.anAddrUnion.adp, ecFirst.anAddrUnion.ado, cnt ); } else if ( nSub == 2 ) { @@ -373,13 +373,13 @@ static void EcSubFormater(tvbuff_t *tvb, gint offset, char *szText, gint nMax) case EC_CMD_TYPE_ARMW: case EC_CMD_TYPE_FRMW: g_snprintf ( szText, nMax, "Sub Frame: Cmd: '%s' (%d), Len: %d, Adp 0x%x, Ado 0x%x, Cnt %d", - convertEcCmdToText(ecParser.cmd), ecParser.cmd, len, ecParser.adp, ecParser.ado, cnt); + convertEcCmdToText(ecParser.cmd), ecParser.cmd, len, ecParser.anAddrUnion.adp, ecParser.anAddrUnion.ado, cnt); break; case EC_CMD_TYPE_LRD: case EC_CMD_TYPE_LWR: case EC_CMD_TYPE_LRW: g_snprintf ( szText, nMax, "Sub Frame: Cmd: '%s' (%d), Len: %d, Addr 0x%x, Cnt %d", - convertEcCmdToText(ecParser.cmd), ecParser.cmd, len, *(guint32*)&ecParser.adp, cnt); + convertEcCmdToText(ecParser.cmd), ecParser.cmd, len, ecParser.anAddrUnion.addr, cnt); break; case EC_CMD_TYPE_EXT: g_snprintf ( szText, nMax, "Sub Frame: Cmd: 'EXT' (%d), Len: %d", ecParser.cmd, len); @@ -405,8 +405,6 @@ static void dissect_ecat_datagram(tvbuff_t *tvb, packet_info *pinfo, proto_tree int nMax = sizeof(szText)-1; guint b; - guint ecat_length = tvb_reported_length(tvb); - guint32 ecLength=0; guint subCount = 0; @@ -454,9 +452,9 @@ static void dissect_ecat_datagram(tvbuff_t *tvb, packet_info *pinfo, proto_tree subsize = get_cmd_len(&ecHdr); len = ecHdr.len&0x7fff; - if ( len >= sizeof(ETHERCAT_MBOX_HEADER) && + if ( len >= sizeof(ETHERCAT_MBOX_HEADER_LEN) && (ecHdr.cmd==EC_CMD_TYPE_FPWR || ecHdr.cmd==EC_CMD_TYPE_FPRD || ecHdr.cmd==EC_CMD_TYPE_APWR || ecHdr.cmd==EC_CMD_TYPE_APRD) && - ecHdr.ado>=0x1000 + ecHdr.anAddrUnion.ado>=0x1000 ) { ETHERCAT_MBOX_HEADER mbox; @@ -469,7 +467,7 @@ static void dissect_ecat_datagram(tvbuff_t *tvb, packet_info *pinfo, proto_tree case ETHERCAT_MBOX_TYPE_FOE: case ETHERCAT_MBOX_TYPE_COE: case ETHERCAT_MBOX_TYPE_SOE: - if ( /*pMBox->Length > 0 &&*/ mbox.Length <= 1500 /*&& pMBox->Length+sizeof(ETHERCAT_MBOX_HEADER) >= len*/ ) + if ( /*pMBox->Length > 0 &&*/ mbox.Length <= 1500 /*&& pMBox->Length+sizeof(ETHERCAT_MBOX_HEADER_LEN) >= len*/ ) { bMBox = TRUE; } @@ -503,23 +501,23 @@ static void dissect_ecat_datagram(tvbuff_t *tvb, packet_info *pinfo, proto_tree case 10: case 11: case 12: - aitem = proto_tree_add_item(ecat_header_tree, hf_ecat_lad, tvb, suboffset, sizeof(ecHdr.adp)+sizeof(ecHdr.ado), TRUE); + aitem = proto_tree_add_item(ecat_header_tree, hf_ecat_lad, tvb, suboffset, sizeof(ecHdr.anAddrUnion.adp)+sizeof(ecHdr.anAddrUnion.ado), TRUE); if( subCount < 10 ) - aitem = proto_tree_add_item_hidden(ecat_header_tree, hf_ecat_sub_lad[subCount], tvb, suboffset, sizeof(ecHdr.adp)+sizeof(ecHdr.ado), TRUE); + aitem = proto_tree_add_item_hidden(ecat_header_tree, hf_ecat_sub_lad[subCount], tvb, suboffset, sizeof(ecHdr.anAddrUnion.adp)+sizeof(ecHdr.anAddrUnion.ado), TRUE); - suboffset += (sizeof(ecHdr.adp)+sizeof(ecHdr.ado)); + suboffset += (sizeof(ecHdr.anAddrUnion.adp)+sizeof(ecHdr.anAddrUnion.ado)); break; default: - aitem = proto_tree_add_item(ecat_header_tree, hf_ecat_adp, tvb, suboffset, sizeof(ecHdr.adp), TRUE); + aitem = proto_tree_add_item(ecat_header_tree, hf_ecat_adp, tvb, suboffset, sizeof(ecHdr.anAddrUnion.adp), TRUE); if( subCount < 10 ) - aitem = proto_tree_add_item_hidden(ecat_header_tree, hf_ecat_sub_adp[subCount], tvb, suboffset, sizeof(ecHdr.adp), TRUE); + aitem = proto_tree_add_item_hidden(ecat_header_tree, hf_ecat_sub_adp[subCount], tvb, suboffset, sizeof(ecHdr.anAddrUnion.adp), TRUE); - suboffset+= sizeof(ecHdr.adp); - aitem = proto_tree_add_item(ecat_header_tree, hf_ecat_ado, tvb, suboffset, sizeof(ecHdr.ado), TRUE); + suboffset+= sizeof(ecHdr.anAddrUnion.adp); + aitem = proto_tree_add_item(ecat_header_tree, hf_ecat_ado, tvb, suboffset, sizeof(ecHdr.anAddrUnion.ado), TRUE); if( subCount < 10 ) - aitem = proto_tree_add_item_hidden(ecat_header_tree, hf_ecat_sub_ado[subCount], tvb, suboffset, sizeof(ecHdr.ado), TRUE); + aitem = proto_tree_add_item_hidden(ecat_header_tree, hf_ecat_sub_ado[subCount], tvb, suboffset, sizeof(ecHdr.anAddrUnion.ado), TRUE); - suboffset+= sizeof(ecHdr.ado); + suboffset+= sizeof(ecHdr.anAddrUnion.ado); } aitem = proto_tree_add_uint(ecat_header_tree, hf_ecat_len, tvb, suboffset, sizeof(ecHdr.len), ecHdr.len&0x07FF); @@ -536,7 +534,7 @@ static void dissect_ecat_datagram(tvbuff_t *tvb, packet_info *pinfo, proto_tree suboffset+=EcParserHDR_Len; } - if ( ecHdr.cmd>=1 && ecHdr.cmd<=9 && ecHdr.ado>=0x600 && ecHdr.ado<0x700 && (ecHdr.ado%16)==0 && (len%16)==0 ) + if ( ecHdr.cmd>=1 && ecHdr.cmd<=9 && ecHdr.anAddrUnion.ado>=0x600 && ecHdr.anAddrUnion.ado<0x700 && (ecHdr.anAddrUnion.ado%16)==0 && (len%16)==0 ) { if( tree ) { @@ -605,7 +603,7 @@ static void dissect_ecat_datagram(tvbuff_t *tvb, packet_info *pinfo, proto_tree } } } - else if ( ecHdr.cmd>=1 && ecHdr.cmd<=9 && ecHdr.ado>=0x800 && ecHdr.ado<0x880 && (ecHdr.ado%8)==0 && (len%8)==0 ) + else if ( ecHdr.cmd>=1 && ecHdr.cmd<=9 && ecHdr.anAddrUnion.ado>=0x800 && ecHdr.anAddrUnion.ado<0x880 && (ecHdr.anAddrUnion.ado%8)==0 && (len%8)==0 ) { if( tree ) { @@ -639,7 +637,7 @@ static void dissect_ecat_datagram(tvbuff_t *tvb, packet_info *pinfo, proto_tree } } } - else if ( (ecHdr.cmd == 1 || ecHdr.cmd == 4) && ecHdr.ado == 0x900 && ecHdr.len >= 16 ) + else if ( (ecHdr.cmd == 1 || ecHdr.cmd == 4) && ecHdr.anAddrUnion.ado == 0x900 && ecHdr.len >= 16 ) { if (tree) { @@ -1549,7 +1547,7 @@ void proto_register_ecat(void) &ett_ecat_dc }; - proto_ecat_datagram = proto_register_protocol("EtherCAT Datagram", + proto_ecat_datagram = proto_register_protocol("EtherCAT datagram", "ECAT","ecat"); proto_register_field_array(proto_ecat_datagram,hf,array_length(hf)); proto_register_subtree_array(ett,array_length(ett)); diff --git a/plugins/ethercat/packet-ethercat-datagram.h b/plugins/ethercat/packet-ethercat-datagram.h index 6a29eeb59f..202c9ad97a 100644 --- a/plugins/ethercat/packet-ethercat-datagram.h +++ b/plugins/ethercat/packet-ethercat-datagram.h @@ -26,22 +26,25 @@ #define _PACKET_ETHERCAT_DATAGRAM_ /* structure for decoding the header -----------------------------------------*/ - -/* Ensure the same data layout for all platforms */ -#pragma pack(push, 1) +typedef union +{ + struct + { + guint16 adp; + guint16 ado; + }; + guint32 addr; +} EcParserAddrUnion; typedef struct _EcParser { guint8 cmd; guint8 idx; - guint16 adp; - guint16 ado; + EcParserAddrUnion anAddrUnion; guint16 len; guint16 intr; } EcParserHDR, *PEcParserHDR; -#define EcParserHDR_Len sizeof(EcParserHDR) - -#pragma pack(pop) +#define EcParserHDR_Len 10/*sizeof(EcParserHDR)*/ #endif /* _PACKET_ETHERCAT_DATAGRAM_ */ diff --git a/plugins/ethercat/packet-ethercat-frame.c b/plugins/ethercat/packet-ethercat-frame.c index 75747c003d..74b36741f5 100644 --- a/plugins/ethercat/packet-ethercat-frame.c +++ b/plugins/ethercat/packet-ethercat-frame.c @@ -76,8 +76,7 @@ static void dissect_ethercat_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree proto_item *ti; proto_tree *ethercat_frame_tree; gint offset = 0; - guint16 hdr_val; - guint16 protocol; + EtherCATFrameParserHDR hdr; if (check_col(pinfo->cinfo, COL_PROTOCOL)) { @@ -91,27 +90,25 @@ static void dissect_ethercat_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree if (tree) { - ti = proto_tree_add_item(tree, proto_ethercat_frame, tvb, offset, sizeof(EtherCATFrameParserHDR), TRUE); + ti = proto_tree_add_item(tree, proto_ethercat_frame, tvb, offset, EtherCATFrameParserHDR_Len, TRUE); ethercat_frame_tree = proto_item_add_subtree(ti, ett_ethercat_frame); - proto_tree_add_item(ethercat_frame_tree, hf_ethercat_frame_length, tvb, offset, sizeof(EtherCATFrameParserHDR), TRUE); - proto_tree_add_item(ethercat_frame_tree, hf_ethercat_frame_type, tvb, offset, sizeof(EtherCATFrameParserHDR), TRUE); + proto_tree_add_item(ethercat_frame_tree, hf_ethercat_frame_length, tvb, offset, EtherCATFrameParserHDR_Len, TRUE); + proto_tree_add_item(ethercat_frame_tree, hf_ethercat_frame_type, tvb, offset, EtherCATFrameParserHDR_Len, TRUE); } - hdr_val = tvb_get_letohs(tvb, offset); - protocol = ((PEtherCATFrameParserHDR)(&hdr_val))->protocol; - - offset = sizeof(EtherCATFrameParserHDR); + hdr.hdr = tvb_get_letohs(tvb, offset); + offset = EtherCATFrameParserHDR_Len; /* The Ethercat frame header has now been processed, allow sub dissectors to handle the rest of the PDU. */ next_tvb = tvb_new_subset (tvb, offset, -1, -1); - if (!dissector_try_port (ethercat_frame_dissector_table, protocol, + if (!dissector_try_port (ethercat_frame_dissector_table, hdr.protocol, next_tvb, pinfo, tree)) { if (check_col (pinfo->cinfo, COL_PROTOCOL)) { - col_add_fstr (pinfo->cinfo, COL_PROTOCOL, "0x%04x", protocol); + col_add_fstr (pinfo->cinfo, COL_PROTOCOL, "0x%04x", hdr.protocol); } /* No sub dissector wanted to handle this payload, decode it as general data instead. */ diff --git a/plugins/ethercat/packet-ethercat-frame.h b/plugins/ethercat/packet-ethercat-frame.h index b43bc66329..1e4346e745 100644 --- a/plugins/ethercat/packet-ethercat-frame.h +++ b/plugins/ethercat/packet-ethercat-frame.h @@ -25,18 +25,19 @@ #ifndef _PACKET_ETHERCAT_FRAME_H #define _PACKET_ETHERCAT_FRAME_H -/* Ensure the same data layout for all platforms */ -#pragma pack(push, 1) - /* structure for decoding the header -----------------------------------------*/ -typedef struct _EtherCATFrameParser +typedef union _EtherCATFrameParser { - guint16 length : 11; - guint16 reserved : 1; - guint16 protocol : 4; + struct + { + guint16 length : 11; + guint16 reserved : 1; + guint16 protocol : 4; + }; + guint16 hdr; } EtherCATFrameParserHDR; typedef EtherCATFrameParserHDR *PEtherCATFrameParserHDR; -#pragma pack(pop) +#define EtherCATFrameParserHDR_Len sizeof(EtherCATFrameParserHDR) #endif diff --git a/plugins/ethercat/packet-ioraw.c b/plugins/ethercat/packet-ioraw.c index 07327e0134..db1f618d06 100644 --- a/plugins/ethercat/packet-ioraw.c +++ b/plugins/ethercat/packet-ioraw.c @@ -89,8 +89,8 @@ static void dissect_ioraw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) ioraw_tree = proto_item_add_subtree(ti, ett_ioraw); proto_item_append_text(ti,": %s",szText); - proto_tree_add_item(ioraw_tree, hf_ioraw_header, tvb, offset, sizeof(IoRawParserHDR), TRUE); - offset+=sizeof(IoRawParserHDR); + proto_tree_add_item(ioraw_tree, hf_ioraw_header, tvb, offset, IoRawParserHDR_Len, TRUE); + offset+=IoRawParserHDR_Len; proto_tree_add_item(ioraw_tree, hf_ioraw_data, tvb, offset, ioraw_length - offset, TRUE); } diff --git a/plugins/ethercat/packet-ioraw.h b/plugins/ethercat/packet-ioraw.h index a689430d7e..47f1ce14e0 100644 --- a/plugins/ethercat/packet-ioraw.h +++ b/plugins/ethercat/packet-ioraw.h @@ -25,15 +25,11 @@ #ifndef _PACKET_IORAW_H_ #define _PACKET_IORAW_H_ -/* Ensure the same data layout for all platforms */ -#pragma pack(push, 1) - /* headers are only used for size and offset calculation*/ typedef struct _IoRawParser { guint32 head; } IoRawParserHDR, *PIoRawParserHDR; - -#pragma pack(pop) +#define IoRawParserHDR_Len sizeof(IoRawParserHDR) #endif /* _PACKET_IORAW_H_*/ diff --git a/plugins/ethercat/packet-nv.c b/plugins/ethercat/packet-nv.c index 4b89ec5a74..d6de013636 100644 --- a/plugins/ethercat/packet-nv.c +++ b/plugins/ethercat/packet-nv.c @@ -71,36 +71,36 @@ static int hf_nv_data = -1; /*nv*/ static void NvSummaryFormater(tvbuff_t *tvb, gint offset, char *szText, int nMax) { - guint32 pubOffset = offset+offsetof(NvParserHDR, Publisher); + guint32 nvOffset = offset; g_snprintf ( szText, nMax, "Network Vars from %d.%d.%d.%d.%d.%d - %d Var(s)", - tvb_get_guint8(tvb, pubOffset), - tvb_get_guint8(tvb, pubOffset+1), - tvb_get_guint8(tvb, pubOffset+2), - tvb_get_guint8(tvb, pubOffset+3), - tvb_get_guint8(tvb, pubOffset+4), - tvb_get_guint8(tvb, pubOffset+5), - tvb_get_letohs(tvb, offset+offsetof(NvParserHDR, CountNV))); + tvb_get_guint8(tvb, nvOffset), + tvb_get_guint8(tvb, nvOffset+1), + tvb_get_guint8(tvb, nvOffset+2), + tvb_get_guint8(tvb, nvOffset+3), + tvb_get_guint8(tvb, nvOffset+4), + tvb_get_guint8(tvb, nvOffset+5), + tvb_get_letohs(tvb, nvOffset+6)); } static void NvPublisherFormater(tvbuff_t *tvb, gint offset, char *szText, int nMax) { - guint32 pubOffset = offset+offsetof(NvParserHDR, Publisher); + guint32 nvOffset = offset; g_snprintf ( szText, nMax, "Publisher %d.%d.%d.%d.%d.%d", - tvb_get_guint8(tvb, pubOffset), - tvb_get_guint8(tvb, pubOffset+1), - tvb_get_guint8(tvb, pubOffset+2), - tvb_get_guint8(tvb, pubOffset+3), - tvb_get_guint8(tvb, pubOffset+4), - tvb_get_guint8(tvb, pubOffset+5)); + tvb_get_guint8(tvb, nvOffset), + tvb_get_guint8(tvb, nvOffset+1), + tvb_get_guint8(tvb, nvOffset+2), + tvb_get_guint8(tvb, nvOffset+3), + tvb_get_guint8(tvb, nvOffset+4), + tvb_get_guint8(tvb, nvOffset+5)); } static void NvVarHeaderFormater(tvbuff_t *tvb, gint offset, char *szText, int nMax) { g_snprintf ( szText, nMax, "Variable - Id = %d, Length = %d", - tvb_get_letohs(tvb, offset+offsetof(ETYPE_88A4_NV_DATA_HEADER, Id)), - tvb_get_letohs(tvb, offset+offsetof(ETYPE_88A4_NV_DATA_HEADER, Length))); + tvb_get_letohs(tvb, offset), + tvb_get_letohs(tvb, offset+4)); } static void dissect_nv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) @@ -111,7 +111,6 @@ static void dissect_nv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) char szText[200]; int nMax = sizeof(szText)-1; - guint nv_length = tvb_reported_length(tvb); gint i; if (check_col(pinfo->cinfo, COL_PROTOCOL)) @@ -132,7 +131,7 @@ static void dissect_nv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) nv_tree = proto_item_add_subtree(ti, ett_nv); proto_item_append_text(ti,": %s",szText); - ti = proto_tree_add_item(nv_tree, hf_nv_header, tvb, offset, sizeof(NvParserHDR), TRUE); + ti = proto_tree_add_item(nv_tree, hf_nv_header, tvb, offset, NvParserHDR_Len, TRUE); nv_header_tree = proto_item_add_subtree(ti, ett_nv_header); @@ -146,18 +145,18 @@ static void dissect_nv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) offset+=sizeof(guint16); ti= proto_tree_add_item(nv_header_tree, hf_nv_cycleindex, tvb, offset, sizeof(guint16), TRUE); - offset = sizeof(NvParserHDR); + offset = NvParserHDR_Len; for ( i=0; i < nv_count; i++ ) { - guint16 var_length = tvb_get_letohs(tvb, offset+offsetof(ETYPE_88A4_NV_DATA_HEADER, Length)); + guint16 var_length = tvb_get_letohs(tvb, offset+4); - ti = proto_tree_add_item(nv_tree, hf_nv_variable, tvb, offset, sizeof(ETYPE_88A4_NV_DATA_HEADER)+var_length, TRUE); + ti = proto_tree_add_item(nv_tree, hf_nv_variable, tvb, offset, ETYPE_88A4_NV_DATA_HEADER_Len+var_length, TRUE); NvVarHeaderFormater(tvb, offset, szText, nMax); proto_item_set_text(ti, szText); nv_var_tree = proto_item_add_subtree(ti, ett_nv_var); - ti = proto_tree_add_item(nv_var_tree, hf_nv_varheader, tvb, offset, sizeof(ETYPE_88A4_NV_DATA_HEADER), TRUE); + ti = proto_tree_add_item(nv_var_tree, hf_nv_varheader, tvb, offset, ETYPE_88A4_NV_DATA_HEADER_Len, TRUE); nv_varheader_tree = proto_item_add_subtree(ti, ett_nv_varheader); ti = proto_tree_add_item(nv_varheader_tree, hf_nv_id, tvb, offset, sizeof(guint16), TRUE); diff --git a/plugins/ethercat/packet-nv.h b/plugins/ethercat/packet-nv.h index 2fb959fc02..02219ae4fd 100644 --- a/plugins/ethercat/packet-nv.h +++ b/plugins/ethercat/packet-nv.h @@ -27,25 +27,22 @@ #define _PACKET_NV_H_ /* Ensure the same data layout for all platforms*/ -#pragma pack(push, 1) - typedef struct _ETYPE_88A4_NV_DATA_HEADER { guint16 Id; guint16 Hash; guint16 Length; guint16 Quality; -} ETYPE_88A4_NV_DATA_HEADER, *PETYPE_88A4_NV_DATA_HEADER; - +} ETYPE_88A4_NV_DATA_HEADER; +#define ETYPE_88A4_NV_DATA_HEADER_Len sizeof(ETYPE_88A4_NV_DATA_HEADER) -typedef struct _ETYPE_88A4_NV_HEADER +typedef struct _NvParserHDR { guint8 Publisher[6]; guint16 CountNV; guint16 CycleIndex; guint16 Reserved; -} ETYPE_88A4_NV_HEADER, *PETYPE_88A4_NV_HEADER, NvParserHDR, *PNvParserHDR; - -#pragma pack(pop) +} NvParserHDR; +#define NvParserHDR_Len sizeof(NvParserHDR) #endif /* _PACKET_NV_H_*/ |