2 * Routines for yahoo messenger packet dissection
3 * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
5 * $Id: packet-yhoo.c,v 1.13 2001/01/09 06:31:45 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-tftp.c
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 # include <netinet/in.h>
45 #include "packet-yhoo.h"
47 static int proto_yhoo = -1;
48 static int hf_yhoo_version = -1;
49 static int hf_yhoo_len = -1;
50 static int hf_yhoo_service = -1;
51 static int hf_yhoo_connection_id = -1;
52 static int hf_yhoo_magic_id = -1;
53 static int hf_yhoo_unknown1 = -1;
54 static int hf_yhoo_msgtype = -1;
55 static int hf_yhoo_nick1 = -1;
56 static int hf_yhoo_nick2 = -1;
57 static int hf_yhoo_content = -1;
59 static gint ett_yhoo = -1;
61 #define TCP_PORT_YHOO 5050
63 static const value_string yhoo_service_vals[] = {
64 {YAHOO_SERVICE_LOGON, "Pager Logon"},
65 {YAHOO_SERVICE_LOGOFF, "Pager Logoff"},
66 {YAHOO_SERVICE_ISAWAY, "Is Away"},
67 {YAHOO_SERVICE_ISBACK, "Is Back"},
68 {YAHOO_SERVICE_IDLE, "Idle"},
69 {YAHOO_SERVICE_MESSAGE, "Message"},
70 {YAHOO_SERVICE_IDACT, "Activate Identity"},
71 {YAHOO_SERVICE_IDDEACT, "Deactivate Identity"},
72 {YAHOO_SERVICE_MAILSTAT, "Mail Status"},
73 {YAHOO_SERVICE_USERSTAT, "User Status"},
74 {YAHOO_SERVICE_NEWMAIL, "New Mail"},
75 {YAHOO_SERVICE_CHATINVITE, "Chat Invitation"},
76 {YAHOO_SERVICE_CALENDAR, "Calendar Reminder"},
77 {YAHOO_SERVICE_NEWPERSONALMAIL, "New Personals Mail"},
78 {YAHOO_SERVICE_NEWCONTACT, "New Friend"},
79 {YAHOO_SERVICE_GROUPRENAME, "Group Renamed"},
80 {YAHOO_SERVICE_ADDIDENT, "Add Identity"},
81 {YAHOO_SERVICE_ADDIGNORE, "Add Ignore"},
82 {YAHOO_SERVICE_PING, "Ping"},
83 {YAHOO_SERVICE_SYSMESSAGE, "System Message"},
84 {YAHOO_SERVICE_CONFINVITE, "Conference Invitation"},
85 {YAHOO_SERVICE_CONFLOGON, "Conference Logon"},
86 {YAHOO_SERVICE_CONFDECLINE, "Conference Decline"},
87 {YAHOO_SERVICE_CONFLOGOFF, "Conference Logoff"},
88 {YAHOO_SERVICE_CONFMSG, "Conference Message"},
89 {YAHOO_SERVICE_CONFADDINVITE, "Conference Additional Invitation"},
90 {YAHOO_SERVICE_CHATLOGON, "Chat Logon"},
91 {YAHOO_SERVICE_CHATLOGOFF, "Chat Logoff"},
92 {YAHOO_SERVICE_CHATMSG, "Chat Message"},
93 {YAHOO_SERVICE_FILETRANSFER, "File Transfer"},
94 {YAHOO_SERVICE_PASSTHROUGH2, "Passthrough 2"},
98 static const value_string yhoo_msgtype_vals[] = {
99 {YAHOO_MSGTYPE_NONE, "None"},
100 {YAHOO_MSGTYPE_NORMAL, "Normal"},
101 {YAHOO_MSGTYPE_BOUNCE, "Bounce"},
102 {YAHOO_MSGTYPE_STATUS, "Status Update"},
103 {YAHOO_MSGTYPE_OFFLINE, "Request Offline"},
108 dissect_yhoo(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
110 proto_tree *yhoo_tree, *ti;
111 struct yahoo_rawpacket *pkt;
113 if (!proto_is_protocol_enabled(proto_yhoo)) {
117 if (pi.srcport != TCP_PORT_YHOO && pi.destport != TCP_PORT_YHOO) {
118 /* Not the Yahoo port - not a Yahoo Messenger packet. */
122 /* get at least a full packet structure */
123 if ( !BYTES_ARE_IN_FRAME(offset, sizeof(struct yahoo_rawpacket)) ) {
124 /* Not enough data captured; maybe it is a Yahoo
125 Messenger packet, but it contains too little data to
130 if (memcmp(&pd[offset], "YPNS", 4) != 0 &&
131 memcmp(&pd[offset], "YHOO", 4) != 0) {
132 /* Not a Yahoo Messenger packet. */
136 pkt = (struct yahoo_rawpacket *) &pd[offset];
138 if (check_col(fd, COL_PROTOCOL))
139 col_set_str(fd, COL_PROTOCOL, "YHOO");
141 if (check_col(fd, COL_INFO))
142 col_add_fstr(fd, COL_INFO,
144 ( strncmp(pkt->version, "YPNS", 4) == 0 ) ? "Request" : "Response",
145 val_to_str(pletohl(pkt->service),
146 yhoo_service_vals, "Unknown Service: %u")
150 ti = proto_tree_add_item(tree, proto_yhoo, NullTVB, offset, END_OF_FRAME, FALSE);
151 yhoo_tree = proto_item_add_subtree(ti, ett_yhoo);
153 proto_tree_add_string(yhoo_tree, hf_yhoo_version, NullTVB,
154 offset, 8, pkt->version);
155 proto_tree_add_uint(yhoo_tree, hf_yhoo_len, NullTVB,
156 offset+8, 4, pletohl(pkt->len));
157 proto_tree_add_uint(yhoo_tree, hf_yhoo_service, NullTVB,
158 offset+12, 4, pletohl(pkt->service));
159 proto_tree_add_uint(yhoo_tree, hf_yhoo_connection_id, NullTVB,
160 offset+16, 4, pletohl(pkt->connection_id));
161 proto_tree_add_uint(yhoo_tree, hf_yhoo_magic_id, NullTVB,
162 offset+20, 4, pletohl(pkt->magic_id));
163 proto_tree_add_uint(yhoo_tree, hf_yhoo_unknown1, NullTVB,
164 offset+24, 4, pletohl(pkt->unknown1));
165 proto_tree_add_uint(yhoo_tree, hf_yhoo_msgtype, NullTVB,
166 offset+28, 4, pletohl(pkt->msgtype));
167 proto_tree_add_string(yhoo_tree, hf_yhoo_nick1, NullTVB,
168 offset+32, 36, pkt->nick1);
169 proto_tree_add_string(yhoo_tree, hf_yhoo_nick2, NullTVB,
170 offset+68, 36, pkt->nick2);
171 proto_tree_add_string(yhoo_tree, hf_yhoo_content, NullTVB,
172 offset+104, END_OF_FRAME, pkt->content);
179 proto_register_yhoo(void)
181 static hf_register_info hf[] = {
182 { &hf_yhoo_service, {
183 "Service Type", "yhoo.service", FT_UINT32, BASE_DEC,
184 VALS(yhoo_service_vals), 0, "Service Type" }},
185 { &hf_yhoo_msgtype, {
186 "Message Type", "yhoo.msgtype", FT_UINT32, BASE_DEC,
187 VALS(yhoo_msgtype_vals), 0, "Message Type Flags" }},
188 { &hf_yhoo_connection_id, {
189 "Connection ID", "yhoo.connection_id", FT_UINT32, BASE_HEX,
190 NULL, 0, "Connection ID" }},
191 { &hf_yhoo_magic_id, {
192 "Magic ID", "yhoo.magic_id", FT_UINT32, BASE_HEX,
193 NULL, 0, "Magic ID" }},
194 { &hf_yhoo_unknown1, {
195 "Unknown 1", "yhoo.unknown1", FT_UINT32, BASE_HEX,
196 NULL, 0, "Unknown 1" }},
198 "Packet Length", "yhoo.len", FT_UINT32, BASE_DEC,
199 NULL, 0, "Packet Length" }},
201 "Real Nick (nick1)", "yhoo.nick1", FT_STRING, 0,
202 NULL, 0, "Real Nick (nick1)" }},
204 "Active Nick (nick2)", "yhoo.nick2", FT_STRING, 0,
205 NULL, 0, "Active Nick (nick2)" }},
206 { &hf_yhoo_content, {
207 "Content", "yhoo.content", FT_STRING, 0,
208 NULL, 0, "Data portion of the packet" }},
209 { &hf_yhoo_version, {
210 "Version", "yhoo.version", FT_STRING, 0,
211 NULL, 0, "Packet version identifier" }},
213 static gint *ett[] = {
217 proto_yhoo = proto_register_protocol("Yahoo Messenger Protocol",
220 proto_register_field_array(proto_yhoo, hf, array_length(hf));
222 proto_register_subtree_array(ett, array_length(ett));
226 proto_reg_handoff_yhoo(void)
228 old_heur_dissector_add("tcp", dissect_yhoo, proto_yhoo);