diff options
author | morriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7> | 2009-10-01 19:19:58 +0000 |
---|---|---|
committer | morriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7> | 2009-10-01 19:19:58 +0000 |
commit | 9ad07043f54932cc6ab92bd2a82277e95efe1b57 (patch) | |
tree | 250368f9ae484a2b70b772716c72ac460c0d7b36 /epan/dissectors/packet-aim.c | |
parent | c4b212401fd248f9266f471ba7e4834e7231fee3 (diff) |
From Gregor Jasny via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4065 :
Expose the FNAC family and subtype via a hf_ value so you can filter for
specific messages.
From me:
Re-arrange the code a bit: put dissect_aim() at the bottom near the
registration functions. Remove unnecessary forward declarations.
Reindent a bunch.
Remove a couple check_col() calls; leave one in since it protects several
other calls.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@30243 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan/dissectors/packet-aim.c')
-rw-r--r-- | epan/dissectors/packet-aim.c | 1046 |
1 files changed, 547 insertions, 499 deletions
diff --git a/epan/dissectors/packet-aim.c b/epan/dissectors/packet-aim.c index a648316090..d04927de77 100644 --- a/epan/dissectors/packet-aim.c +++ b/epan/dissectors/packet-aim.c @@ -380,23 +380,6 @@ static const value_string aim_ssi_result_codes[] = { { 0, NULL } }; - -static int dissect_aim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree); -static guint get_aim_pdu_len(packet_info *pinfo, tvbuff_t *tvb, int offset); -static void dissect_aim_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree); - -static void dissect_aim_newconn(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *tree); -static void dissect_aim_snac(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree, proto_tree *root_tree); -static void dissect_aim_flap_err(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree); -static void dissect_aim_keep_alive(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree); -static void dissect_aim_close_conn(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree); -static void dissect_aim_unknown_channel(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree); - static dissector_table_t subdissector_table; /* Initialize the protocol and registered fields */ @@ -478,102 +461,9 @@ static gint ett_aim_string08_array = -1; /* desegmentation of AIM over TCP */ static gboolean aim_desegment = TRUE; -/* Code to actually dissect the packets */ -static int dissect_aim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) -{ -/* check, if this is really an AIM packet, they start with 0x2a */ -/* XXX - I've seen some stuff starting with 0x5a followed by 0x2a */ - - if(tvb_length(tvb) >= 1 && tvb_get_guint8(tvb, 0) != 0x2a) { - /* Not an instant messenger packet, just happened to use the same port */ - /* XXX - if desegmentation disabled, this might be a continuation - packet, not a non-AIM packet */ - return 0; - } - tcp_dissect_pdus(tvb, pinfo, tree, aim_desegment, 6, get_aim_pdu_len, - dissect_aim_pdu); - return tvb_length(tvb); -} - -static guint get_aim_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset) -{ - guint16 plen; - - /* - * Get the length of the AIM packet. - */ - plen = tvb_get_ntohs(tvb, offset + 4); - - /* - * That length doesn't include the length of the header itself; add that in. - */ - return plen + 6; -} - -static void dissect_aim_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) -{ - /* Header fields */ - unsigned char hdr_channel; /* channel ID */ - unsigned short hdr_sequence_no; /* Internal frame sequence number, not needed */ - unsigned short hdr_data_field_length; /* length of data within frame */ - - int offset=0; - -/* Set up structures we will need to add the protocol subtree and manage it */ - proto_item *ti; - proto_tree *aim_tree = NULL; - -/* Make entries in Protocol column and Info column on summary display */ - col_set_str(pinfo->cinfo, COL_PROTOCOL, "AIM"); - - col_set_str(pinfo->cinfo, COL_INFO, "AOL Instant Messenger"); - - /* get relevant header information */ - offset += 1; /* XXX - put the identifier into the tree? */ - hdr_channel = tvb_get_guint8(tvb, offset); - offset += 1; - hdr_sequence_no = tvb_get_ntohs(tvb, offset); - offset += 2; - hdr_data_field_length = tvb_get_ntohs(tvb, offset); - offset += 2; - -/* In the interest of speed, if "tree" is NULL, don't do any work not - necessary to generate protocol tree items. */ - if (tree) { - ti = proto_tree_add_item(tree, proto_aim, tvb, 0, -1, FALSE); - aim_tree = proto_item_add_subtree(ti, ett_aim); - proto_tree_add_uint(aim_tree, hf_aim_cmd_start, tvb, 0, 1, '*'); - proto_tree_add_item(aim_tree, hf_aim_channel, tvb, 1, 1, FALSE); - proto_tree_add_uint(aim_tree, hf_aim_seqno, tvb, 2, 2, hdr_sequence_no); - proto_tree_add_uint(aim_tree, hf_aim_data_len, tvb, 4, 2, hdr_data_field_length); - - } - - switch(hdr_channel) - { - case CHANNEL_NEW_CONN: - dissect_aim_newconn(tvb, pinfo, offset, aim_tree); - break; - case CHANNEL_SNAC_DATA: - dissect_aim_snac(tvb, pinfo, offset, aim_tree, tree); - break; - case CHANNEL_FLAP_ERR: - dissect_aim_flap_err(tvb, pinfo, offset, aim_tree); - break; - case CHANNEL_CLOSE_CONN: - dissect_aim_close_conn(tvb, pinfo, offset, aim_tree); - break; - case CHANNEL_KEEP_ALIVE: - dissect_aim_keep_alive(tvb, pinfo, offset, aim_tree); - break; - default: - dissect_aim_unknown_channel(tvb, pinfo, offset, aim_tree); - break; - } - -} -const aim_subtype *aim_get_subtype( guint16 famnum, guint16 subtype ) +const aim_subtype +*aim_get_subtype( guint16 famnum, guint16 subtype ) { GList *gl = families; while(gl) { @@ -591,7 +481,8 @@ const aim_subtype *aim_get_subtype( guint16 famnum, guint16 subtype ) } -const aim_family *aim_get_family( guint16 famnum ) +const aim_family +*aim_get_family( guint16 famnum ) { GList *gl = families; while(gl) { @@ -603,20 +494,24 @@ const aim_family *aim_get_family( guint16 famnum ) return NULL; } -int aim_get_buddyname( guchar *name, tvbuff_t *tvb, int len_offset, int name_offset) +int +aim_get_buddyname( guchar *name, tvbuff_t *tvb, int len_offset, int name_offset) { - guint8 buddyname_length; + guint8 buddyname_length; + + buddyname_length = tvb_get_guint8(tvb, len_offset); - buddyname_length = tvb_get_guint8(tvb, len_offset); + if(buddyname_length > MAX_BUDDYNAME_LENGTH ) + buddyname_length = MAX_BUDDYNAME_LENGTH; - if(buddyname_length > MAX_BUDDYNAME_LENGTH ) buddyname_length = MAX_BUDDYNAME_LENGTH; - tvb_get_nstringz0(tvb, name_offset, buddyname_length + 1, name); + tvb_get_nstringz0(tvb, name_offset, buddyname_length + 1, name); - return buddyname_length; + return buddyname_length; } -void aim_get_message( guchar *msg, tvbuff_t *tvb, int msg_offset, int msg_length) +void +aim_get_message( guchar *msg, tvbuff_t *tvb, int msg_offset, int msg_length) { int i,j,c; int bracket = FALSE; @@ -625,7 +520,6 @@ void aim_get_message( guchar *msg, tvbuff_t *tvb, int msg_offset, int msg_length int new_length = msg_length; - /* make sure nothing bigger than 1000 bytes is printed */ if( msg_length > 999 ) return; @@ -693,7 +587,8 @@ void aim_get_message( guchar *msg, tvbuff_t *tvb, int msg_offset, int msg_length } } -void aim_init_family(int proto, int ett, guint16 family, const aim_subtype *subtypes) +void +aim_init_family(int proto, int ett, guint16 family, const aim_subtype *subtypes) { aim_family *fam = g_new(aim_family, 1); fam->proto = find_protocol_by_id(proto); @@ -706,323 +601,341 @@ void aim_init_family(int proto, int ett, guint16 family, const aim_subtype *subt fam->ett = ett; } -static void dissect_aim_newconn(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree) +static void +dissect_aim_newconn(tvbuff_t *tvb, packet_info *pinfo, int offset, + proto_tree *tree) { - col_set_str(pinfo->cinfo, COL_INFO, "New Connection"); + col_set_str(pinfo->cinfo, COL_INFO, "New Connection"); - if (tvb_length_remaining(tvb, offset) > 0) { - proto_tree_add_item(tree, hf_aim_version, tvb, offset, 4, FALSE); - offset+=4; - offset = dissect_aim_tlv_sequence(tvb, pinfo, offset, tree, client_tlvs); - } + if (tvb_length_remaining(tvb, offset) > 0) { + proto_tree_add_item(tree, hf_aim_version, tvb, offset, 4, FALSE); + offset+=4; + offset = dissect_aim_tlv_sequence(tvb, pinfo, offset, tree, client_tlvs); + } - if (tvb_length_remaining(tvb, offset) > 0) - proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE); + if (tvb_length_remaining(tvb, offset) > 0) + proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE); } -int dissect_aim_snac_error(tvbuff_t *tvb, packet_info *pinfo, - proto_tree *aim_tree) +int +dissect_aim_snac_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *aim_tree) { - const char *name; + const char *name; - if ((name = match_strval(tvb_get_ntohs(tvb, 0), aim_snac_errors)) != NULL) { - if (check_col(pinfo->cinfo, COL_INFO)) + if ((name = match_strval(tvb_get_ntohs(tvb, 0), aim_snac_errors)) != NULL) { col_add_str(pinfo->cinfo, COL_INFO, name); - } + } - proto_tree_add_item (aim_tree, hf_aim_snac_error, - tvb, 0, 2, FALSE); - - return dissect_aim_tlv_sequence(tvb, pinfo, 2, aim_tree, client_tlvs); + proto_tree_add_item (aim_tree, hf_aim_snac_error, tvb, 0, 2, FALSE); + + return dissect_aim_tlv_sequence(tvb, pinfo, 2, aim_tree, client_tlvs); } -int dissect_aim_ssi_result(tvbuff_t *tvb, packet_info *pinfo, - proto_tree *aim_tree) +int +dissect_aim_ssi_result(tvbuff_t *tvb, packet_info *pinfo, proto_tree *aim_tree) { - const char *name; + const char *name; - if ((name = match_strval(tvb_get_ntohs(tvb, 0), aim_ssi_result_codes)) != NULL) { - if (check_col(pinfo->cinfo, COL_INFO)) + if ((name = match_strval(tvb_get_ntohs(tvb, 0), aim_ssi_result_codes)) != NULL) { col_add_str(pinfo->cinfo, COL_INFO, name); - } + } - proto_tree_add_item (aim_tree, hf_aim_ssi_result_code, - tvb, 0, 2, FALSE); + proto_tree_add_item (aim_tree, hf_aim_ssi_result_code, tvb, 0, 2, FALSE); - return 2; + return 2; } -int dissect_aim_userinfo(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree) +int +dissect_aim_userinfo(tvbuff_t *tvb, packet_info *pinfo, + int offset, proto_tree *tree) { - offset = dissect_aim_buddyname(tvb, pinfo, offset, tree); + offset = dissect_aim_buddyname(tvb, pinfo, offset, tree); - proto_tree_add_item(tree, hf_aim_userinfo_warninglevel, tvb, offset, 2, FALSE); - offset += 2; + proto_tree_add_item(tree, hf_aim_userinfo_warninglevel, tvb, offset, 2, FALSE); + offset += 2; - return dissect_aim_tlv_list(tvb, pinfo, offset, tree, onlinebuddy_tlvs); + return dissect_aim_tlv_list(tvb, pinfo, offset, tree, onlinebuddy_tlvs); } -static int dissect_aim_fnac_flags(tvbuff_t *tvb, int offset, int len, proto_item *ti, guint16 flags) +static int +dissect_aim_fnac_flags(tvbuff_t *tvb, int offset, int len, proto_item *ti, + guint16 flags) { proto_tree *entry = proto_item_add_subtree(ti, ett_aim_fnac_flags); proto_tree_add_boolean(entry, hf_aim_fnac_flag_next_is_related, tvb, offset, len, flags); proto_tree_add_boolean(entry, hf_aim_fnac_flag_contains_version, tvb, offset, len, flags); + return offset + len; } -static void dissect_aim_snac(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *aim_tree, proto_tree *root_tree) +static void +dissect_aim_snac(tvbuff_t *tvb, packet_info *pinfo, int offset, + proto_tree *aim_tree, proto_tree *root_tree) { - guint16 family_id; - guint16 subtype_id; - guint16 flags; - guint32 id; - proto_item *ti1; - struct aiminfo aiminfo; - proto_tree *aim_tree_fnac = NULL; - tvbuff_t *subtvb; - int orig_offset; - const aim_subtype *subtype; - proto_tree *family_tree = NULL; - const aim_family *family; - void* pd_save; + guint16 family_id; + guint16 subtype_id; + guint16 flags; + guint32 id; + proto_item *ti1; + struct aiminfo aiminfo; + proto_tree *aim_tree_fnac = NULL; + tvbuff_t *subtvb; + int orig_offset; + const aim_subtype *subtype; + proto_tree *family_tree = NULL; + const aim_family *family; + void* pd_save; + + orig_offset = offset; + family_id = tvb_get_ntohs(tvb, offset); + family = aim_get_family(family_id); + offset += 2; + subtype_id = tvb_get_ntohs(tvb, offset); + subtype = aim_get_subtype(family_id, subtype_id); + offset += 2; + flags = tvb_get_ntohs(tvb, offset); + offset += 2; + id = tvb_get_ntohl(tvb, offset); + offset += 4; - orig_offset = offset; - family_id = tvb_get_ntohs(tvb, offset); - family = aim_get_family(family_id); - offset += 2; - subtype_id = tvb_get_ntohs(tvb, offset); - subtype = aim_get_subtype(family_id, subtype_id); - offset += 2; - flags = tvb_get_ntohs(tvb, offset); - offset += 2; - id = tvb_get_ntohl(tvb, offset); - offset += 4; - - - if( aim_tree ) + + if( aim_tree ) { - offset = orig_offset; - ti1 = proto_tree_add_text(aim_tree, tvb, 6, 10, "FNAC: Family: %s (0x%04x), Subtype: %s (0x%04x)", - family?family->name:"Unknown", family_id, - (subtype && subtype->name)?subtype->name:"Unknown", subtype_id); - aim_tree_fnac = proto_item_add_subtree(ti1, ett_aim_fnac); + offset = orig_offset; + ti1 = proto_tree_add_text(aim_tree, tvb, 6, 10, + "FNAC: Family: %s (0x%04x), Subtype: %s (0x%04x)", + family ? family->name : "Unknown", family_id, + (subtype && subtype->name) ? subtype->name : "Unknown", subtype_id); + aim_tree_fnac = proto_item_add_subtree(ti1, ett_aim_fnac); + + proto_tree_add_uint_format_value (aim_tree_fnac, hf_aim_fnac_family, + tvb, offset, 2, family_id, "%s (0x%04x)", + family ? family->name : "Unknown", family_id); + offset += 2; - proto_tree_add_text (aim_tree_fnac, - tvb, offset, 2, "Family: %s (0x%04x)", family?family->name:"Unknown", family_id); - offset += 2; + proto_tree_add_uint_format_value (aim_tree_fnac, hf_aim_fnac_subtype, + tvb, offset, 2, subtype_id, "%s (0x%04x)", + (subtype && subtype->name) ? subtype->name : "Unknown", subtype_id); - proto_tree_add_text (aim_tree_fnac, - tvb, offset, 2, "Subtype: %s (0x%04x)", (subtype && subtype->name)?subtype->name:"Unknown", subtype_id); - offset += 2; + offset += 2; - ti1 = proto_tree_add_uint(aim_tree_fnac, hf_aim_fnac_flags, tvb, offset, - 2, flags); + ti1 = proto_tree_add_uint(aim_tree_fnac, hf_aim_fnac_flags, tvb, offset, + 2, flags); - offset = dissect_aim_fnac_flags(tvb, offset, 2, ti1, flags); + offset = dissect_aim_fnac_flags(tvb, offset, 2, ti1, flags); - proto_tree_add_uint(aim_tree_fnac, hf_aim_fnac_id, tvb, offset, - 4, id); - offset += 4; + proto_tree_add_uint(aim_tree_fnac, hf_aim_fnac_id, tvb, offset, + 4, id); + offset += 4; } - - if(flags & FNAC_FLAG_CONTAINS_VERSION) { - guint16 len = tvb_get_ntohs(tvb, offset); + + if(flags & FNAC_FLAG_CONTAINS_VERSION) + { + guint16 len = tvb_get_ntohs(tvb, offset); int oldoffset; offset+=2; oldoffset = offset; - + while(offset < oldoffset + len) { - offset = dissect_aim_tlv(tvb, pinfo, offset, aim_tree, fnac_tlvs); + offset = dissect_aim_tlv(tvb, pinfo, offset, aim_tree, fnac_tlvs); } - } + } - subtvb = tvb_new_subset_remaining(tvb, offset); - aiminfo.tcpinfo = pinfo->private_data; - aiminfo.family = family_id; - aiminfo.subtype = subtype_id; - pd_save = pinfo->private_data; - pinfo->private_data = &aiminfo; + subtvb = tvb_new_subset_remaining(tvb, offset); + aiminfo.tcpinfo = pinfo->private_data; + aiminfo.family = family_id; + aiminfo.subtype = subtype_id; + pd_save = pinfo->private_data; + pinfo->private_data = &aiminfo; - if (check_col(pinfo->cinfo, COL_PROTOCOL) && family) { - col_set_str(pinfo->cinfo, COL_PROTOCOL, family->name); - } - - if (check_col(pinfo->cinfo, COL_INFO)) { - if(subtype && family) { + col_set_str(pinfo->cinfo, COL_PROTOCOL, family->name); + + if (check_col(pinfo->cinfo, COL_INFO)) + { + if(subtype && family) + { col_set_str(pinfo->cinfo, COL_INFO, family->name); col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", subtype->name); } else { - col_set_str(pinfo->cinfo, COL_INFO, "SNAC data"); - - if(family) col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", family->name); - else col_append_fstr(pinfo->cinfo, COL_INFO, ", Family: 0x%04x", family_id); + col_set_str(pinfo->cinfo, COL_INFO, "SNAC data"); + + if(family) + col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", family->name); + else + col_append_fstr(pinfo->cinfo, COL_INFO, ", Family: 0x%04x", family_id); col_append_fstr(pinfo->cinfo, COL_INFO, ", Subtype: 0x%04x", subtype_id); } - } + } - if(aim_tree && family) - { - proto_item *ti = proto_tree_add_item(root_tree, family->proto_id, subtvb, 0, -1, FALSE); + if(aim_tree && family) + { + proto_item *ti = proto_tree_add_item(root_tree, family->proto_id, subtvb, 0, -1, FALSE); family_tree = proto_item_add_subtree(ti, family->ett); - if(subtype) proto_item_append_text(ti, ", %s", subtype->name); - } + if(subtype) + proto_item_append_text(ti, ", %s", subtype->name); + } - if(tvb_length_remaining(tvb, offset) > 0 && subtype && subtype->dissector) { - subtype->dissector(subtvb, pinfo, family_tree); - } - pinfo->private_data = pd_save; + if(tvb_length_remaining(tvb, offset) > 0 && subtype && subtype->dissector) + { + subtype->dissector(subtvb, pinfo, family_tree); + } + + pinfo->private_data = pd_save; } -static void dissect_aim_flap_err(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree) +static void +dissect_aim_flap_err(tvbuff_t *tvb, packet_info *pinfo, int offset, + proto_tree *tree) { - col_set_str(pinfo->cinfo, COL_INFO, "FLAP error"); + col_set_str(pinfo->cinfo, COL_INFO, "FLAP error"); - /* Show the undissected payload */ - if (tvb_length_remaining(tvb, offset) > 0) - proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE); + /* Show the undissected payload */ + if (tvb_length_remaining(tvb, offset) > 0) + proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE); } -static void dissect_aim_keep_alive(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree) +static void +dissect_aim_keep_alive(tvbuff_t *tvb, packet_info *pinfo, int offset, + proto_tree *tree) { - col_set_str(pinfo->cinfo, COL_INFO, "Keep Alive"); + col_set_str(pinfo->cinfo, COL_INFO, "Keep Alive"); - /* Show the undissected payload */ - if (tvb_length_remaining(tvb, offset) > 0) - proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE); + /* Show the undissected payload */ + if (tvb_length_remaining(tvb, offset) > 0) + proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE); } -static void dissect_aim_close_conn(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree) +static void +dissect_aim_close_conn(tvbuff_t *tvb, packet_info *pinfo, int offset, + proto_tree *tree) { - col_set_str(pinfo->cinfo, COL_INFO, "Close Connection"); - - offset = dissect_aim_tlv_sequence(tvb, pinfo, offset, tree, client_tlvs); + col_set_str(pinfo->cinfo, COL_INFO, "Close Connection"); + + offset = dissect_aim_tlv_sequence(tvb, pinfo, offset, tree, client_tlvs); } -static void dissect_aim_unknown_channel(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree) +static void +dissect_aim_unknown_channel(tvbuff_t *tvb, packet_info *pinfo, int offset, + proto_tree *tree) { - col_set_str(pinfo->cinfo, COL_INFO, "Unknown Channel"); + col_set_str(pinfo->cinfo, COL_INFO, "Unknown Channel"); - /* Show the undissected payload */ - if (tvb_length_remaining(tvb, offset) > 0) - proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE); + /* Show the undissected payload */ + if (tvb_length_remaining(tvb, offset) > 0) + proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE); } -int dissect_aim_buddyname(tvbuff_t *tvb, packet_info *pinfo _U_, int offset, - proto_tree *tree) +int +dissect_aim_buddyname(tvbuff_t *tvb, packet_info *pinfo _U_, int offset, + proto_tree *tree) { - guint8 buddyname_length = 0; - proto_item *ti = NULL; - proto_tree *buddy_tree = NULL; - - buddyname_length = tvb_get_guint8(tvb, offset); - offset++; - - if(tree) { - ti = proto_tree_add_text(tree, tvb, offset-1, 1+buddyname_length, - "Buddy: %s", - tvb_format_text(tvb, offset, buddyname_length)); - buddy_tree = proto_item_add_subtree(ti, ett_aim_buddyname); - proto_tree_add_item(buddy_tree, hf_aim_buddyname_len, tvb, offset-1, 1, FALSE); - proto_tree_add_item(buddy_tree, hf_aim_buddyname, tvb, offset, buddyname_length, FALSE); - } + guint8 buddyname_length = 0; + proto_item *ti = NULL; + proto_tree *buddy_tree = NULL; - return offset+buddyname_length; + buddyname_length = tvb_get_guint8(tvb, offset); + offset++; + + if(tree) + { + ti = proto_tree_add_text(tree, tvb, offset-1, 1+buddyname_length, + "Buddy: %s", + tvb_format_text(tvb, offset, buddyname_length)); + buddy_tree = proto_item_add_subtree(ti, ett_aim_buddyname); + proto_tree_add_item(buddy_tree, hf_aim_buddyname_len, tvb, offset-1, 1, FALSE); + proto_tree_add_item(buddy_tree, hf_aim_buddyname, tvb, offset, buddyname_length, FALSE); + } + + return offset+buddyname_length; } typedef struct _aim_client_capability { const char *name; - e_uuid_t clsid; + e_uuid_t clsid; } aim_client_capability; static const aim_client_capability known_client_caps[] = { - { "Send File", + { "Send File", {0x09461343, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Recv File", { 0x09461348, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, - + { "Short Caps", - {0x09460000, 0x4c7f, 0x11d1, + {0x09460000, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Secure IM", - {0x09460001, 0x4c7f, 0x11d1, + {0x09460001, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "XHTML IM", - {0x09460002, 0x4c7f, 0x11d1, + {0x09460002, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Video Chat", - {0x09460100, 0x4c7f, 0x11d1, + {0x09460100, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Live Video", - {0x09460101, 0x4c7f, 0x11d1, + {0x09460101, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Camera", - {0x09460102, 0x4c7f, 0x11d1, + {0x09460102, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Microphone", - {0x09460103, 0x4c7f, 0x11d1, + {0x09460103, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Live Audio", - {0x09460104, 0x4c7f, 0x11d1, + {0x09460104, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "iChatAV info", - {0x09460105, 0x4c7f, 0x11d1, + {0x09460105, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x45, 0x53, 0x54, 0x00}}}, { "Host Status Text Aware", - {0x0946010A, 0x4c7f, 0x11d1, + {0x0946010A, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x45, 0x53, 0x54, 0x00}}}, { "Realtime IM", - {0x0946010B, 0x4c7f, 0x11d1, + {0x0946010B, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x45, 0x53, 0x54, 0x00}}}, { "Smart Caps", - {0x094601FF, 0x4c7f, 0x11d1, + {0x094601FF, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x45, 0x53, 0x54, 0x00}}}, { "Hiptop", - {0x09461323, 0x4c7f, 0x11d1, + {0x09461323, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Voice Chat", - {0x09461341, 0x4c7f, 0x11d1, + {0x09461341, 0x4c7f, 0x11d1, { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "File Transfer", - {0x09461343, 0x4c7f, 0x11d1, + {0x09461343, 0x4c7f, 0x11d1, {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Direct ICQ Communication", - {0x09461344, 0x4c7f, 0x11d1, + {0x09461344, 0x4c7f, 0x11d1, {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Direct ICBM", - {0x09461345, 0x4c7f, 0x11d1, + {0x09461345, 0x4c7f, 0x11d1, {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Buddy Icon", - {0x09461346, 0x4c7f, 0x11d1, + {0x09461346, 0x4c7f, 0x11d1, {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "Add-Ins", @@ -1040,7 +953,7 @@ static const aim_client_capability known_client_caps[] = { { "Games", {0x0946134a, 0x4c7f, 0x11d1, {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, - + { "Games", {0x0946134a, 0x4c7f, 0x11d1, {0x22, 0x82, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, @@ -1062,14 +975,14 @@ static const aim_client_capability known_client_caps[] = { {0x88, 0x6f, 0xea, 0x35, 0x95, 0xfd, 0xb6, 0xdf}}}, { "Chat", - {0x748f2420, 0x6287, 0x11d1, + {0x748f2420, 0x6287, 0x11d1, {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}}, { "ICQ Rich Text Format Messages", {0x97b12751, 0x243c, 0x4334, {0xad, 0x22, 0xd6, 0xab, 0xf7, 0x3f, 0x14, 0x92}}}, - { "AP User", + { "AP User", {0xaa4a32b5, 0xf884, 0x48c6, {0xa3, 0xd7, 0x8c, 0x50, 0x97, 0x19, 0xfd, 0x5b}}}, @@ -1080,11 +993,12 @@ static const aim_client_capability known_client_caps[] = { { NULL, {0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } } } }; -static const aim_client_capability *aim_find_capability ( e_uuid_t clsid) +static const +aim_client_capability *aim_find_capability (e_uuid_t clsid) { int i; - for(i = 0; known_client_caps[i].name; i++) + for(i = 0; known_client_caps[i].name; i++) { const aim_client_capability *caps = &(known_client_caps[i]); @@ -1095,7 +1009,8 @@ static const aim_client_capability *aim_find_capability ( e_uuid_t clsid) return NULL; } -int dissect_aim_capability(proto_tree *entry, tvbuff_t *tvb, int offset) +int +dissect_aim_capability(proto_tree *entry, tvbuff_t *tvb, int offset) { const aim_client_capability *caps = NULL; e_uuid_t clsid; @@ -1107,18 +1022,19 @@ int dissect_aim_capability(proto_tree *entry, tvbuff_t *tvb, int offset) caps = aim_find_capability(clsid); - proto_tree_add_text(entry, tvb, offset, 16, - "%s {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", - caps?caps->name:"Unknown", clsid.Data1, clsid.Data2, - clsid.Data3, clsid.Data4[0], clsid.Data4[1], clsid.Data4[2], - clsid.Data4[3], clsid.Data4[4], clsid.Data4[5], clsid.Data4[6], - clsid.Data4[7] + proto_tree_add_text(entry, tvb, offset, 16, + "%s {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + caps?caps->name:"Unknown", clsid.Data1, clsid.Data2, + clsid.Data3, clsid.Data4[0], clsid.Data4[1], clsid.Data4[2], + clsid.Data4[3], clsid.Data4[4], clsid.Data4[5], clsid.Data4[6], + clsid.Data4[7] ); return offset+16; } -int dissect_aim_tlv_value_client_capabilities(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +int +dissect_aim_tlv_value_client_capabilities(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) { int offset = 0; proto_tree *entry; @@ -1126,7 +1042,7 @@ int dissect_aim_tlv_value_client_capabilities(proto_item *ti _U_, guint16 valuei proto_item_set_text(ti, "Client Capabilities List"); entry = proto_item_add_subtree(ti, ett_aim_client_capabilities); - + while (tvb_length_remaining(tvb, offset) > 0) { offset = dissect_aim_capability(entry, tvb, offset); } @@ -1134,13 +1050,15 @@ int dissect_aim_tlv_value_client_capabilities(proto_item *ti _U_, guint16 valuei return tvb_length(tvb); } -int dissect_aim_tlv_value_time(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +int +dissect_aim_tlv_value_time(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) { /* FIXME */ return tvb_length(tvb); } -int dissect_aim_userclass(tvbuff_t *tvb, int offset, int len, proto_item *ti, guint32 flags) +int +dissect_aim_userclass(tvbuff_t *tvb, int offset, int len, proto_item *ti, guint32 flags) { proto_tree *entry; @@ -1165,28 +1083,32 @@ int dissect_aim_userclass(tvbuff_t *tvb, int offset, int len, proto_item *ti, gu proto_tree_add_boolean(entry, hf_aim_userclass_unknown20000, tvb, offset, len, flags); proto_tree_add_boolean(entry, hf_aim_userclass_no_knock_knock, tvb, offset, len, flags); proto_tree_add_boolean(entry, hf_aim_userclass_forward_mobile, tvb, offset, len, flags); + return offset+len; } -int dissect_aim_tlv_value_userclass(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +int +dissect_aim_tlv_value_userclass(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) { guint16 value16 = tvb_get_ntohs(tvb, 0); proto_item_set_text(ti, "Value: 0x%04x", value16); return dissect_aim_userclass(tvb, 0, 2, ti, value16); } -static int dissect_aim_tlv_value_userstatus(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +static int +dissect_aim_tlv_value_userstatus(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) { /* FIXME */ return tvb_length(tvb); } -static int dissect_aim_tlv_value_dcinfo(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +static int +dissect_aim_tlv_value_dcinfo(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) { int offset = 0; - + proto_tree *dctree = proto_item_add_subtree(ti, ett_aim_dcinfo); - + proto_tree_add_item(dctree, hf_aim_dcinfo_ip , tvb, offset, 4, FALSE); offset+=4; proto_tree_add_item(dctree, hf_aim_dcinfo_tcpport, tvb, offset, 4, FALSE); offset+=4; proto_tree_add_item(dctree, hf_aim_dcinfo_type, tvb, offset, 1, FALSE); offset+=1; @@ -1202,134 +1124,151 @@ static int dissect_aim_tlv_value_dcinfo(proto_item *ti, guint16 valueid _U_, tvb return offset; } -int dissect_aim_tlv_value_string (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +int +dissect_aim_tlv_value_string (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) { - guint8 *buf; - gint string_len; + guint8 *buf; + gint string_len; + + string_len = tvb_length(tvb); + buf = tvb_get_ephemeral_string(tvb, 0, string_len); + proto_item_set_text(ti, "Value: %s", format_text(buf, string_len)); - string_len = tvb_length(tvb); - buf = tvb_get_ephemeral_string(tvb, 0, string_len); - proto_item_set_text(ti, "Value: %s", format_text(buf, string_len)); - return string_len; + return string_len; } -int dissect_aim_tlv_value_string08_array (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +int +dissect_aim_tlv_value_string08_array (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) { - proto_tree *entry; - gint offset=0; + proto_tree *entry; + gint offset=0; - entry = proto_item_add_subtree(ti, ett_aim_string08_array); + entry = proto_item_add_subtree(ti, ett_aim_string08_array); - while (tvb_length_remaining(tvb, offset) > 1) - { - guint8 string_len = tvb_get_guint8(tvb, offset++); - guint8 *buf = tvb_get_ephemeral_string(tvb, offset, string_len); - proto_tree_add_text(entry, tvb, offset, string_len, "%s", format_text(buf, string_len)); - offset += string_len; - } + while (tvb_length_remaining(tvb, offset) > 1) + { + guint8 string_len = tvb_get_guint8(tvb, offset++); + guint8 *buf = tvb_get_ephemeral_string(tvb, offset, string_len); + proto_tree_add_text(entry, tvb, offset, string_len, "%s", + format_text(buf, string_len)); + offset += string_len; + } - return offset; + return offset; } -int dissect_aim_tlv_value_bytes (proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb _U_, packet_info *pinfo _U_) +int +dissect_aim_tlv_value_bytes (proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb _U_, packet_info *pinfo _U_) { - return tvb_length(tvb); + return tvb_length(tvb); } -int dissect_aim_tlv_value_uint8 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_){ - guint8 value8 = tvb_get_guint8(tvb, 0); - proto_item_set_text(ti, "Value: %d", value8); - return 1; +int +dissect_aim_tlv_value_uint8 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +{ + guint8 value8 = tvb_get_guint8(tvb, 0); + proto_item_set_text(ti, "Value: %d", value8); + return 1; } -int dissect_aim_tlv_value_uint16 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_){ - guint16 value16 = tvb_get_ntohs(tvb, 0); - proto_item_set_text(ti, "Value: %d", value16); - return 2; +int +dissect_aim_tlv_value_uint16 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +{ + guint16 value16 = tvb_get_ntohs(tvb, 0); + proto_item_set_text(ti, "Value: %d", value16); + return 2; } -int dissect_aim_tlv_value_ipv4 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_){ - guint32 ipv4_address = tvb_get_ipv4(tvb, 0); - proto_item_set_text(ti, "Value: %s", ip_to_str((guint8 *)&ipv4_address)); - return 4; +int +dissect_aim_tlv_value_ipv4 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +{ + guint32 ipv4_address = tvb_get_ipv4(tvb, 0); + proto_item_set_text(ti, "Value: %s", ip_to_str((guint8 *)&ipv4_address)); + return 4; } -int dissect_aim_tlv_value_uint32 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_){ - guint32 value32 = tvb_get_ntohl(tvb, 0); - proto_item_set_text(ti, "Value: %d", value32); - return 4; +int +dissect_aim_tlv_value_uint32 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +{ + guint32 value32 = tvb_get_ntohl(tvb, 0); + proto_item_set_text(ti, "Value: %d", value32); + return 4; } -int dissect_aim_tlv_value_messageblock (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_){ - proto_tree *entry; - guint8 *buf; - guint16 featurelen; - guint16 blocklen; - int offset=0; - - /* Setup a new subtree */ - entry = proto_item_add_subtree(ti, ett_aim_messageblock); - - /* Features descriptor */ - proto_tree_add_item(entry, hf_aim_messageblock_featuresdes, tvb, offset, 2, - FALSE); - offset += 2; - - /* Features Length */ - featurelen = tvb_get_ntohs(tvb, offset); - proto_tree_add_item(entry, hf_aim_messageblock_featureslen, tvb, offset, 2, - FALSE); - offset += 2; - - /* Features (should be expanded further @@@@@@@ ) */ - proto_tree_add_item(entry, hf_aim_messageblock_features, tvb, offset, - featurelen, FALSE); - offset += featurelen; - - /* There can be multiple messages in this message block */ - while (tvb_length_remaining(tvb, offset) > 0) { - /* Info field */ - proto_tree_add_item(entry, hf_aim_messageblock_info, tvb, offset, 2, - FALSE); - offset += 2; - - /* Block length (includes charset and charsubset) */ - blocklen = tvb_get_ntohs(tvb, offset); - if (blocklen <= 4) { - proto_tree_add_text(entry, tvb, offset, 2, "Invalid block length: %d", - blocklen); - break; - } - proto_tree_add_item(entry, hf_aim_messageblock_len, tvb, offset, 2, - FALSE); - offset += 2; - - /* Character set */ - proto_tree_add_item(entry, hf_aim_messageblock_charset, tvb, offset, 2, - FALSE); - offset += 2; - - /* Character subset */ - proto_tree_add_item(entry, hf_aim_messageblock_charsubset, tvb, offset, 2, - FALSE); - offset += 2; - - /* The actual message */ - buf = tvb_get_ephemeral_string(tvb, offset, blocklen - 4 ); - proto_item_set_text(ti, "Message: %s", - format_text(buf, blocklen - 4)); - proto_tree_add_item(entry, hf_aim_messageblock_message, tvb, offset, - blocklen-4, - FALSE); - offset += tvb_length_remaining(tvb, offset); - } +int +dissect_aim_tlv_value_messageblock (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_) +{ + proto_tree *entry; + guint8 *buf; + guint16 featurelen; + guint16 blocklen; + int offset=0; + + /* Setup a new subtree */ + entry = proto_item_add_subtree(ti, ett_aim_messageblock); + + /* Features descriptor */ + proto_tree_add_item(entry, hf_aim_messageblock_featuresdes, tvb, offset, + 2, FALSE); + offset += 2; + + /* Features Length */ + featurelen = tvb_get_ntohs(tvb, offset); + proto_tree_add_item(entry, hf_aim_messageblock_featureslen, tvb, offset, + 2, FALSE); + offset += 2; + + /* Features (should be expanded further @@@@@@@ ) */ + proto_tree_add_item(entry, hf_aim_messageblock_features, tvb, offset, + featurelen, FALSE); + offset += featurelen; + + /* There can be multiple messages in this message block */ + while (tvb_length_remaining(tvb, offset) > 0) { + /* Info field */ + proto_tree_add_item(entry, hf_aim_messageblock_info, tvb, + offset, 2, FALSE); + offset += 2; + + /* Block length (includes charset and charsubset) */ + blocklen = tvb_get_ntohs(tvb, offset); + if (blocklen <= 4) + { + proto_tree_add_text(entry, tvb, offset, 2, + "Invalid block length: %d", blocklen); + break; + } + proto_tree_add_item(entry, hf_aim_messageblock_len, tvb, offset, + 2, FALSE); + offset += 2; + + /* Character set */ + proto_tree_add_item(entry, hf_aim_messageblock_charset, tvb, + offset, 2, FALSE); + offset += 2; + + /* Character subset */ + proto_tree_add_item(entry, hf_aim_messageblock_charsubset, tvb, + offset, 2, FALSE); + offset += 2; + + /* The actual message */ + buf = tvb_get_ephemeral_string(tvb, offset, blocklen - 4); + proto_item_set_text(ti, "Message: %s", + format_text(buf, blocklen - 4)); + proto_tree_add_item(entry, hf_aim_messageblock_message, tvb, + offset, blocklen-4, FALSE); + + offset += tvb_length_remaining(tvb, offset); + } - return offset; + return offset; } /* Dissect a TLV value */ -int dissect_aim_tlv(tvbuff_t *tvb, packet_info *pinfo _U_, - int offset, proto_tree *tree, const aim_tlv *tlv) +int +dissect_aim_tlv(tvbuff_t *tvb, packet_info *pinfo _U_, int offset, + proto_tree *tree, const aim_tlv *tlv) { guint16 valueid; guint16 length; @@ -1357,8 +1296,8 @@ int dissect_aim_tlv(tvbuff_t *tvb, packet_info *pinfo _U_, i++; } - /* At this point, we are either pointing at the correct record, or - we didn't find the record, and are pointing at the last item in the + /* At this point, we are either pointing at the correct record, or + we didn't find the record, and are pointing at the last item in the list */ length = tvb_get_ntohs(tvb, offset); @@ -1372,7 +1311,7 @@ int dissect_aim_tlv(tvbuff_t *tvb, packet_info *pinfo _U_, desc = tmp[i].desc; else desc = "Unknown"; - + ti1 = proto_tree_add_text(tree, tvb, offset, length + 4, "TLV: %s", desc); tlv_tree = proto_item_add_subtree(ti1, ett_aim_tlv); @@ -1380,17 +1319,17 @@ int dissect_aim_tlv(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree_add_text(tlv_tree, tvb, offset, 2, "Value ID: %s (0x%04x)", desc, valueid); offset += 2; - + proto_tree_add_text(tlv_tree, tvb, offset, 2, "Length: %d", length); offset += 2; ti1 = proto_tree_add_text(tlv_tree, tvb, offset, length, "Value"); - + if (tmp[i].dissector) { tmp[i].dissector(ti1, valueid, tvb_new_subset(tvb, offset, length, length), pinfo); - } + } offset += length; } @@ -1399,29 +1338,137 @@ int dissect_aim_tlv(tvbuff_t *tvb, packet_info *pinfo _U_, return offset; } -int dissect_aim_tlv_sequence(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree, const aim_tlv *tlv_table) +int +dissect_aim_tlv_sequence(tvbuff_t *tvb, packet_info *pinfo, int offset, + proto_tree *tree, const aim_tlv *tlv_table) { while (tvb_length_remaining(tvb, offset) > 0) { offset = dissect_aim_tlv(tvb, pinfo, offset, tree, tlv_table); } + return offset; } -int dissect_aim_tlv_list(tvbuff_t *tvb, packet_info *pinfo, - int offset, proto_tree *tree, const aim_tlv *tlv_table) +int +dissect_aim_tlv_list(tvbuff_t *tvb, packet_info *pinfo, int offset, + proto_tree *tree, const aim_tlv *tlv_table) { - guint16 i, tlv_count = tvb_get_ntohs(tvb, offset); + guint16 i, tlv_count = tvb_get_ntohs(tvb, offset); - proto_tree_add_item(tree, hf_aim_tlvcount, tvb, offset, 2, FALSE); - offset += 2; + proto_tree_add_item(tree, hf_aim_tlvcount, tvb, offset, 2, FALSE); + offset += 2; - for(i = 0; i < tlv_count; i++) { - offset = dissect_aim_tlv(tvb, pinfo, offset, tree, tlv_table); - } - return offset; + for(i = 0; i < tlv_count; i++) { + offset = dissect_aim_tlv(tvb, pinfo, offset, tree, tlv_table); + } + + return offset; } +static guint +get_aim_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset) +{ + guint16 plen; + + /* + * Get the length of the AIM packet. + */ + plen = tvb_get_ntohs(tvb, offset + 4); + + /* + * That length doesn't include the length of the header itself; add that in. + */ + return plen + 6; +} + +static void +dissect_aim_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + /* Header fields */ + unsigned char hdr_channel; /* channel ID */ + unsigned short hdr_sequence_no; /* Internal frame sequence number, not needed */ + unsigned short hdr_data_field_length; /* length of data within frame */ + + int offset=0; + +/* Set up structures we will need to add the protocol subtree and manage it */ + proto_item *ti; + proto_tree *aim_tree = NULL; + +/* Make entries in Protocol column and Info column on summary display */ + col_set_str(pinfo->cinfo, COL_PROTOCOL, "AIM"); + + col_set_str(pinfo->cinfo, COL_INFO, "AOL Instant Messenger"); + + /* get relevant header information */ + offset += 1; /* XXX - put the identifier into the tree? */ + hdr_channel = tvb_get_guint8(tvb, offset); + offset += 1; + hdr_sequence_no = tvb_get_ntohs(tvb, offset); + offset += 2; + hdr_data_field_length = tvb_get_ntohs(tvb, offset); + offset += 2; + +/* In the interest of speed, if "tree" is NULL, don't do any work not + necessary to generate protocol tree items. */ + if (tree) { + ti = proto_tree_add_item(tree, proto_aim, tvb, 0, -1, FALSE); + aim_tree = proto_item_add_subtree(ti, ett_aim); + proto_tree_add_uint(aim_tree, hf_aim_cmd_start, tvb, 0, 1, '*'); + proto_tree_add_item(aim_tree, hf_aim_channel, tvb, 1, 1, FALSE); + proto_tree_add_uint(aim_tree, hf_aim_seqno, tvb, 2, 2, hdr_sequence_no); + proto_tree_add_uint(aim_tree, hf_aim_data_len, tvb, 4, 2, hdr_data_field_length); + + } + + switch(hdr_channel) + { + case CHANNEL_NEW_CONN: + dissect_aim_newconn(tvb, pinfo, offset, aim_tree); + break; + case CHANNEL_SNAC_DATA: + dissect_aim_snac(tvb, pinfo, offset, aim_tree, tree); + break; + case CHANNEL_FLAP_ERR: + dissect_aim_flap_err(tvb, pinfo, offset, aim_tree); + break; + case CHANNEL_CLOSE_CONN: + dissect_aim_close_conn(tvb, pinfo, offset, aim_tree); + break; + case CHANNEL_KEEP_ALIVE: + dissect_aim_keep_alive(tvb, pinfo, offset, aim_tree); + break; + default: + dissect_aim_unknown_channel(tvb, pinfo, offset, aim_tree); + break; + } + +} + +/* Code to actually dissect the packets */ +static int +dissect_aim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + /* check, if this is really an AIM packet, they start with 0x2a */ + /* XXX - I've seen some stuff starting with 0x5a followed by 0x2a */ + + if(tvb_length(tvb) >= 1 && tvb_get_guint8(tvb, 0) != 0x2a) + { + /* Not an instant messenger packet, just happened to use the + * same port + * + * XXX - if desegmentation disabled, this might be a continuation + * packet, not a non-AIM packet + */ + return 0; + } + + tcp_dissect_pdus(tvb, pinfo, tree, aim_desegment, 6, get_aim_pdu_len, + dissect_aim_pdu); + return tvb_length(tvb); +} + + /* Register the protocol with Wireshark */ void proto_register_aim(void) @@ -1429,56 +1476,56 @@ proto_register_aim(void) /* Setup list of header fields */ static hf_register_info hf[] = { - { &hf_aim_cmd_start, - { "Command Start", "aim.cmd_start", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_channel, - { "Channel ID", "aim.channel", FT_UINT8, BASE_HEX, VALS(aim_flap_channels), 0x0, NULL, HFILL } - }, - { &hf_aim_seqno, - { "Sequence Number", "aim.seqno", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } - }, + { &hf_aim_cmd_start, + { "Command Start", "aim.cmd_start", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_channel, + { "Channel ID", "aim.channel", FT_UINT8, BASE_HEX, VALS(aim_flap_channels), 0x0, NULL, HFILL } + }, + { &hf_aim_seqno, + { "Sequence Number", "aim.seqno", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } + }, { &hf_aim_version, - { "Protocol Version", "aim.version", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }, + { "Protocol Version", "aim.version", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }, + }, + { &hf_aim_data_len, + { "Data Field Length", "aim.datalen", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_data, + { "Data", "aim.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_signon_challenge_len, + { "Signon challenge length", "aim.signon.challengelen", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_signon_challenge, + { "Signon challenge", "aim.signon.challenge", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_fnac_family, + { "FNAC Family ID", "aim.fnac.family", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_fnac_subtype, + { "FNAC Subtype ID", "aim.fnac.subtype", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_fnac_flags, + { "FNAC Flags", "aim.fnac.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_fnac_id, + { "FNAC ID", "aim.fnac.id", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_infotype, + { "Infotype", "aim.infotype", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_buddyname_len, + { "Buddyname len", "aim.buddynamelen", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_buddyname, + { "Buddy Name", "aim.buddyname", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } + }, + { &hf_aim_tlvcount, + { "TLV Count", "aim.tlvcount", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }, }, - { &hf_aim_data_len, - { "Data Field Length", "aim.datalen", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_data, - { "Data", "aim.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_signon_challenge_len, - { "Signon challenge length", "aim.signon.challengelen", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_signon_challenge, - { "Signon challenge", "aim.signon.challenge", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_fnac_family, - { "FNAC Family ID", "aim.fnac.family", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_fnac_subtype, - { "FNAC Subtype ID", "aim.fnac.subtype", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_fnac_flags, - { "FNAC Flags", "aim.fnac.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_fnac_id, - { "FNAC ID", "aim.fnac.id", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_infotype, - { "Infotype", "aim.infotype", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_buddyname_len, - { "Buddyname len", "aim.buddynamelen", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_buddyname, - { "Buddy Name", "aim.buddyname", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } - }, - { &hf_aim_tlvcount, - { "TLV Count", "aim.tlvcount", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }, - }, { &hf_aim_snac_error, - { "SNAC Error", "aim.snac.error", FT_UINT16, BASE_HEX, VALS(aim_snac_errors), 0x0, NULL, HFILL }, + { "SNAC Error", "aim.snac.error", FT_UINT16, BASE_HEX, VALS(aim_snac_errors), 0x0, NULL, HFILL }, }, { &hf_aim_userclass_unconfirmed, { "AOL Unconfirmed account flag", "aim.userclass.unconfirmed", FT_BOOLEAN, 32, TFS(&tfs_set_notset), CLASS_UNCONFIRMED, NULL, HFILL }, @@ -1549,28 +1596,28 @@ proto_register_aim(void) { &hf_aim_userinfo_warninglevel, { "Warning Level", "aim.userinfo.warninglevel", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }, }, - { &hf_aim_messageblock_featuresdes, + { &hf_aim_messageblock_featuresdes, { "Features", "aim.messageblock.featuresdes", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }, }, - { &hf_aim_messageblock_featureslen, + { &hf_aim_messageblock_featureslen, { "Features Length", "aim.messageblock.featureslen", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }, }, - { &hf_aim_messageblock_features, + { &hf_aim_messageblock_features, { "Features", "aim.messageblock.features", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }, }, - { &hf_aim_messageblock_info, + { &hf_aim_messageblock_info, { "Block info", "aim.messageblock.info", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }, }, - { &hf_aim_messageblock_len, + { &hf_aim_messageblock_len, { "Block length", "aim.messageblock.length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }, }, - { &hf_aim_messageblock_charset, + { &hf_aim_messageblock_charset, { "Block Character set", "aim.messageblock.charset", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }, }, - { &hf_aim_messageblock_charsubset, + { &hf_aim_messageblock_charsubset, { "Block Character subset", "aim.messageblock.charsubset", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }, }, - { &hf_aim_messageblock_message, + { &hf_aim_messageblock_message, { "Message", "aim.messageblock.message", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }, }, { &hf_aim_dcinfo_ip, @@ -1629,16 +1676,17 @@ proto_register_aim(void) /* Register the protocol name and description */ proto_aim = proto_register_protocol("AOL Instant Messenger", "AIM", "aim"); -/* Required function calls to register the header fields and subtrees used */ + /* Required function calls to register the header fields and subtrees used */ proto_register_field_array(proto_aim, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); aim_module = prefs_register_protocol(proto_aim, NULL); + prefs_register_bool_preference(aim_module, "desegment", - "Reassemble AIM messages spanning multiple TCP segments", - "Whether the AIM dissector should reassemble messages spanning multiple TCP segments." - " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.", - &aim_desegment); + "Reassemble AIM messages spanning multiple TCP segments", + "Whether the AIM dissector should reassemble messages spanning multiple TCP segments." + " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.", + &aim_desegment); subdissector_table = register_dissector_table("aim.family", "Family ID", FT_UINT16, BASE_HEX); } |