diff --git a/plugins/agentx/packet-agentx.c b/plugins/agentx/packet-agentx.c index af38ade523..049cfd1d74 100644 --- a/plugins/agentx/packet-agentx.c +++ b/plugins/agentx/packet-agentx.c @@ -290,16 +290,21 @@ static const value_string resp_errors[] = { #define PDU_HDR_LEN 20 #define PADDING(x) ((((x) + 3) >> 2) << 2) -#define NORHL(FLAGS,VAR) VAR = (FLAGS & NETWORK_BYTE_ORDER) ? VAR : g_htonl(VAR) -#define NORHS(FLAGS,VAR) VAR = (FLAGS & NETWORK_BYTE_ORDER) ? VAR : g_htons(VAR) +#define NORLEL(flags,var,tvb,offset) \ + var = (flags & NETWORK_BYTE_ORDER) ? \ + tvb_get_ntohl(tvb, offset) : \ + tvb_get_letohl(tvb, offset) +#define NORLES(flags,var,tvb,offset) \ + var = (flags & NETWORK_BYTE_ORDER) ? \ + tvb_get_ntohs(tvb, offset) : \ + tvb_get_letohs(tvb, offset) static int dissect_octet_string(tvbuff_t *tvb, proto_tree *tree, int offset, char flags) { guint32 n_oct, p_noct; char context[1024]; - n_oct = tvb_get_ntohl(tvb, offset); - NORHL(flags,n_oct); + NORLEL(flags, n_oct, tvb, offset); p_noct = PADDING(n_oct); tvb_get_nstringz(tvb, offset + 4, n_oct, context); @@ -327,7 +332,6 @@ static int convert_oid_to_str(guint32 *oid, int len, char* str, int slen, char p } for(i=0; i < len; i++) { - printf("->%d<-\n",oid[i]); tlen += sprintf(str+tlen,".%d",oid[i]); } return tlen; @@ -353,8 +357,7 @@ static int dissect_object_id(tvbuff_t *tvb, proto_tree *tree, int offset, char f tvb_get_guint8(tvb, offset + 3); for(i=0; i offset) { @@ -531,8 +520,7 @@ static void dissect_getbulk_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int l { proto_item* item; proto_tree* subtree; - guint16 non_repeaters; - guint16 max_repetitions; + gboolean little_endian = !(flags & NETWORK_BYTE_ORDER); item = proto_tree_add_text(tree, tvb, offset, len, "GetBulk-PDU"); subtree = proto_item_add_subtree(item, ett_getbulk); @@ -542,14 +530,8 @@ static void dissect_getbulk_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int l offset += dissect_octet_string(tvb, subtree, offset, flags); } - non_repeaters = tvb_get_ntohs(tvb, offset); - max_repetitions = tvb_get_ntohs(tvb, offset + 2); - - NORHS(flags,non_repeaters); - NORHS(flags,max_repetitions); - - proto_tree_add_uint(subtree, hf_gbulk_nrepeat, tvb, offset, 2, non_repeaters); - proto_tree_add_uint(subtree, hf_gbulk_mrepeat, tvb, offset + 2, 2, max_repetitions); + proto_tree_add_item(subtree, hf_gbulk_nrepeat, tvb, offset, 2, little_endian); + proto_tree_add_item(subtree, hf_gbulk_mrepeat, tvb, offset + 2, 2, little_endian); offset+=4; while(len >= offset) { @@ -600,10 +582,7 @@ static void dissect_register_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int { proto_item* item; proto_tree* subtree; - guint8 timeout; - guint8 priority; - guint8 range_subid; - guint32 upper_bound; + gboolean little_endian = !(flags & NETWORK_BYTE_ORDER); item = proto_tree_add_text(tree, tvb, offset, len, "Register-PDU"); subtree = proto_item_add_subtree(item, ett_register); @@ -613,14 +592,9 @@ static void dissect_register_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int offset += dissect_octet_string(tvb, subtree, offset, flags); } - timeout = tvb_get_guint8(tvb, offset); - priority = tvb_get_guint8(tvb, offset+1); - range_subid = tvb_get_guint8(tvb, offset+2); - tvb_get_guint8(tvb, offset + 4); - - proto_tree_add_uint(subtree, hf_reg_timeout, tvb, offset, 1, timeout); - proto_tree_add_uint(subtree, hf_reg_prio, tvb, offset+1, 1, priority); - proto_tree_add_uint(subtree, hf_reg_rsid, tvb, offset+2, 1, range_subid); + proto_tree_add_item(subtree, hf_reg_timeout, tvb, offset, 1, FALSE); + proto_tree_add_item(subtree, hf_reg_prio, tvb, offset+1, 1, FALSE); + proto_tree_add_item(subtree, hf_reg_rsid, tvb, offset+2, 1, FALSE); offset+=4; /* Region */ @@ -628,11 +602,8 @@ static void dissect_register_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int offset += dissect_object_id(tvb, subtree, offset, flags); if(len > offset) { - /* Upper bound (opt) */ - upper_bound = tvb_get_ntohl(tvb, offset); - NORHL(flags,upper_bound); - - proto_tree_add_uint(subtree, hf_reg_ubound, tvb, offset, 4, upper_bound); + /* Upper bound (opt) */ + proto_tree_add_item(subtree, hf_reg_ubound, tvb, offset, 4, little_endian); offset += 4; } } @@ -642,10 +613,7 @@ static void dissect_unregister_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,in { proto_item* item; proto_tree* subtree; - guint8 timeout; - guint8 priority; - guint8 range_subid; - guint32 upper_bound; + gboolean little_endian = !(flags & NETWORK_BYTE_ORDER); item = proto_tree_add_text(tree, tvb, offset, len, "Unregister-PDU"); subtree = proto_item_add_subtree(item, ett_unregister); @@ -655,25 +623,17 @@ static void dissect_unregister_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,in offset += dissect_octet_string(tvb, subtree, offset, flags); } - timeout = tvb_get_guint8(tvb, offset); - priority = tvb_get_guint8(tvb, offset+1); - range_subid = tvb_get_guint8(tvb, offset+2); - tvb_get_guint8(tvb, offset + 4); - - proto_tree_add_uint(subtree, hf_unreg_timeout, tvb, offset, 1, timeout); - proto_tree_add_uint(subtree, hf_unreg_prio, tvb, offset+1, 1, priority); - proto_tree_add_uint(subtree, hf_unreg_rsid, tvb, offset+2, 1, range_subid); + proto_tree_add_item(subtree, hf_unreg_timeout, tvb, offset, 1, FALSE); + proto_tree_add_item(subtree, hf_unreg_prio, tvb, offset+1, 1, FALSE); + proto_tree_add_item(subtree, hf_unreg_rsid, tvb, offset+2, 1, FALSE); offset+=4; /* Region */ offset += dissect_object_id(tvb, subtree, offset, flags); if(len > offset) { - /* Upper bound (opt) */ - upper_bound = tvb_get_ntohl(tvb, offset); - NORHL(flags,upper_bound); - - proto_tree_add_uint(subtree, hf_unreg_ubound, tvb, offset, 4, upper_bound); + /* Upper bound (opt) */ + proto_tree_add_item(subtree, hf_unreg_ubound, tvb, offset, 4, little_endian); offset += 4; } } @@ -802,13 +762,15 @@ static void dissect_rem_caps_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int static guint get_agentx_pdu_len(tvbuff_t *tvb, int offset) { + guint8 flags; guint32 plen; /* * Get the payload length. */ - plen = tvb_get_ntohl(tvb, offset+16); - + flags = tvb_get_guint8(tvb, offset + 2); + NORLEL(flags, plen, tvb, offset + 16); + /* * Arbitrarily limit it to 2^24, so we don't have to worry about * overflow. @@ -840,18 +802,12 @@ static void dissect_agentx_pdu(tvbuff_t *tvb, packet_info *pinfo, type = tvb_get_guint8(tvb,1); offset+=1; flags = tvb_get_guint8(tvb,2); offset+=1; /* skip reserved byte */ - tvb_get_guint8(tvb,3); offset+=1; - - session_id = tvb_get_ntohl(tvb, 4); offset+=4; - trans_id = tvb_get_ntohl(tvb, 8); offset+=4; - packet_id = tvb_get_ntohl(tvb, 12); offset+=4; - payload_len = tvb_get_ntohl(tvb, 16); offset+=4; - - NORHL(flags,session_id); - NORHL(flags,trans_id); - NORHL(flags,packet_id); - NORHL(flags,payload_len); + offset+=1; + NORLEL(flags, session_id, tvb, 4); offset+=4; + NORLEL(flags, trans_id, tvb, 8); offset+=4; + NORLEL(flags, packet_id, tvb, 12); offset+=4; + NORLEL(flags, payload_len, tvb, 16); offset+=4; if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, "AgentX");