2 * Routines for yahoo messenger packet dissection
3 * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
5 * $Id: packet-yhoo.c,v 1.26 2003/03/01 00:09:00 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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.
36 #include <epan/packet.h>
38 static int proto_yhoo = -1;
39 static int hf_yhoo_version = -1;
40 static int hf_yhoo_len = -1;
41 static int hf_yhoo_service = -1;
42 static int hf_yhoo_connection_id = -1;
43 static int hf_yhoo_magic_id = -1;
44 static int hf_yhoo_unknown1 = -1;
45 static int hf_yhoo_msgtype = -1;
46 static int hf_yhoo_nick1 = -1;
47 static int hf_yhoo_nick2 = -1;
48 static int hf_yhoo_content = -1;
50 static gint ett_yhoo = -1;
52 #define TCP_PORT_YHOO 5050
54 /* This is from yahoolib.h from gtkyahoo */
56 /* Service constants */
57 #define YAHOO_SERVICE_LOGON 1
58 #define YAHOO_SERVICE_LOGOFF 2
59 #define YAHOO_SERVICE_ISAWAY 3
60 #define YAHOO_SERVICE_ISBACK 4
61 #define YAHOO_SERVICE_IDLE 5
62 #define YAHOO_SERVICE_MESSAGE 6
63 #define YAHOO_SERVICE_IDACT 7
64 #define YAHOO_SERVICE_IDDEACT 8
65 #define YAHOO_SERVICE_MAILSTAT 9
66 #define YAHOO_SERVICE_USERSTAT 10
67 #define YAHOO_SERVICE_NEWMAIL 11
68 #define YAHOO_SERVICE_CHATINVITE 12
69 #define YAHOO_SERVICE_CALENDAR 13
70 #define YAHOO_SERVICE_NEWPERSONALMAIL 14
71 #define YAHOO_SERVICE_NEWCONTACT 15
72 #define YAHOO_SERVICE_ADDIDENT 16
73 #define YAHOO_SERVICE_ADDIGNORE 17
74 #define YAHOO_SERVICE_PING 18
75 #define YAHOO_SERVICE_GROUPRENAME 19
76 #define YAHOO_SERVICE_SYSMESSAGE 20
77 #define YAHOO_SERVICE_PASSTHROUGH2 22
78 #define YAHOO_SERVICE_CONFINVITE 24
79 #define YAHOO_SERVICE_CONFLOGON 25
80 #define YAHOO_SERVICE_CONFDECLINE 26
81 #define YAHOO_SERVICE_CONFLOGOFF 27
82 #define YAHOO_SERVICE_CONFADDINVITE 28
83 #define YAHOO_SERVICE_CONFMSG 29
84 #define YAHOO_SERVICE_CHATLOGON 30
85 #define YAHOO_SERVICE_CHATLOGOFF 31
86 #define YAHOO_SERVICE_CHATMSG 32
87 #define YAHOO_SERVICE_FILETRANSFER 70
90 #define YAHOO_MSGTYPE_NONE 0
91 #define YAHOO_MSGTYPE_NORMAL 1
92 #define YAHOO_MSGTYPE_BOUNCE 2
93 #define YAHOO_MSGTYPE_STATUS 4
94 #define YAHOO_MSGTYPE_OFFLINE 1515563606 /* yuck! */
96 struct yahoo_rawpacket
98 char version[8]; /* 7 chars and trailing null */
99 unsigned char len[4]; /* length - little endian */
100 unsigned char service[4]; /* service - little endian */
101 unsigned char connection_id[4]; /* connection number - little endian */
102 unsigned char magic_id[4]; /* magic number used for http session */
103 unsigned char unknown1[4];
104 unsigned char msgtype[4];
107 char content[1]; /* was zero, had problems with aix xlc */
110 static const value_string yhoo_service_vals[] = {
111 {YAHOO_SERVICE_LOGON, "Pager Logon"},
112 {YAHOO_SERVICE_LOGOFF, "Pager Logoff"},
113 {YAHOO_SERVICE_ISAWAY, "Is Away"},
114 {YAHOO_SERVICE_ISBACK, "Is Back"},
115 {YAHOO_SERVICE_IDLE, "Idle"},
116 {YAHOO_SERVICE_MESSAGE, "Message"},
117 {YAHOO_SERVICE_IDACT, "Activate Identity"},
118 {YAHOO_SERVICE_IDDEACT, "Deactivate Identity"},
119 {YAHOO_SERVICE_MAILSTAT, "Mail Status"},
120 {YAHOO_SERVICE_USERSTAT, "User Status"},
121 {YAHOO_SERVICE_NEWMAIL, "New Mail"},
122 {YAHOO_SERVICE_CHATINVITE, "Chat Invitation"},
123 {YAHOO_SERVICE_CALENDAR, "Calendar Reminder"},
124 {YAHOO_SERVICE_NEWPERSONALMAIL, "New Personals Mail"},
125 {YAHOO_SERVICE_NEWCONTACT, "New Friend"},
126 {YAHOO_SERVICE_GROUPRENAME, "Group Renamed"},
127 {YAHOO_SERVICE_ADDIDENT, "Add Identity"},
128 {YAHOO_SERVICE_ADDIGNORE, "Add Ignore"},
129 {YAHOO_SERVICE_PING, "Ping"},
130 {YAHOO_SERVICE_SYSMESSAGE, "System Message"},
131 {YAHOO_SERVICE_CONFINVITE, "Conference Invitation"},
132 {YAHOO_SERVICE_CONFLOGON, "Conference Logon"},
133 {YAHOO_SERVICE_CONFDECLINE, "Conference Decline"},
134 {YAHOO_SERVICE_CONFLOGOFF, "Conference Logoff"},
135 {YAHOO_SERVICE_CONFMSG, "Conference Message"},
136 {YAHOO_SERVICE_CONFADDINVITE, "Conference Additional Invitation"},
137 {YAHOO_SERVICE_CHATLOGON, "Chat Logon"},
138 {YAHOO_SERVICE_CHATLOGOFF, "Chat Logoff"},
139 {YAHOO_SERVICE_CHATMSG, "Chat Message"},
140 {YAHOO_SERVICE_FILETRANSFER, "File Transfer"},
141 {YAHOO_SERVICE_PASSTHROUGH2, "Passthrough 2"},
145 static const value_string yhoo_msgtype_vals[] = {
146 {YAHOO_MSGTYPE_NONE, "None"},
147 {YAHOO_MSGTYPE_NORMAL, "Normal"},
148 {YAHOO_MSGTYPE_BOUNCE, "Bounce"},
149 {YAHOO_MSGTYPE_STATUS, "Status Update"},
150 {YAHOO_MSGTYPE_OFFLINE, "Request Offline"},
155 dissect_yhoo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
157 proto_tree *yhoo_tree, *ti;
160 if (pinfo->srcport != TCP_PORT_YHOO && pinfo->destport != TCP_PORT_YHOO) {
161 /* Not the Yahoo port - not a Yahoo Messenger packet. */
165 /* get at least a full packet structure */
166 if ( !tvb_bytes_exist(tvb, 0, sizeof(struct yahoo_rawpacket)) ) {
167 /* Not enough data captured; maybe it is a Yahoo
168 Messenger packet, but it contains too little data to
173 if (memcmp(tvb_get_ptr(tvb, offset, 4), "YPNS", 4) != 0 &&
174 memcmp(tvb_get_ptr(tvb, offset, 4), "YHOO", 4) != 0) {
175 /* Not a Yahoo Messenger packet. */
179 if (check_col(pinfo->cinfo, COL_PROTOCOL))
180 col_set_str(pinfo->cinfo, COL_PROTOCOL, "YHOO");
183 if (check_col(pinfo->cinfo, COL_INFO)) {
184 col_add_fstr(pinfo->cinfo, COL_INFO,
186 ( strncmp(tvb_get_ptr(tvb, offset + 0, 4), "YPNS", 4) == 0 ) ? "Request" : "Response",
187 val_to_str(tvb_get_letohl(tvb, offset + 12),
188 yhoo_service_vals, "Unknown Service: %u")
193 ti = proto_tree_add_item(tree, proto_yhoo, tvb, offset, -1,
195 yhoo_tree = proto_item_add_subtree(ti, ett_yhoo);
197 proto_tree_add_item(yhoo_tree, hf_yhoo_version, tvb,
201 proto_tree_add_item(yhoo_tree, hf_yhoo_len, tvb,
205 proto_tree_add_item(yhoo_tree, hf_yhoo_service, tvb,
209 proto_tree_add_item(yhoo_tree, hf_yhoo_connection_id, tvb,
213 proto_tree_add_item(yhoo_tree, hf_yhoo_magic_id, tvb,
217 proto_tree_add_item(yhoo_tree, hf_yhoo_unknown1, tvb,
221 proto_tree_add_item(yhoo_tree, hf_yhoo_msgtype, tvb,
225 proto_tree_add_item(yhoo_tree, hf_yhoo_nick1, tvb,
229 proto_tree_add_item(yhoo_tree, hf_yhoo_nick2, tvb,
233 proto_tree_add_item(yhoo_tree, hf_yhoo_content, tvb, -1,
241 proto_register_yhoo(void)
243 static hf_register_info hf[] = {
244 { &hf_yhoo_service, {
245 "Service Type", "yhoo.service", FT_UINT32, BASE_DEC,
246 VALS(yhoo_service_vals), 0, "Service Type", HFILL }},
247 { &hf_yhoo_msgtype, {
248 "Message Type", "yhoo.msgtype", FT_UINT32, BASE_DEC,
249 VALS(yhoo_msgtype_vals), 0, "Message Type Flags", HFILL }},
250 { &hf_yhoo_connection_id, {
251 "Connection ID", "yhoo.connection_id", FT_UINT32, BASE_HEX,
252 NULL, 0, "Connection ID", HFILL }},
253 { &hf_yhoo_magic_id, {
254 "Magic ID", "yhoo.magic_id", FT_UINT32, BASE_HEX,
255 NULL, 0, "Magic ID", HFILL }},
256 { &hf_yhoo_unknown1, {
257 "Unknown 1", "yhoo.unknown1", FT_UINT32, BASE_HEX,
258 NULL, 0, "Unknown 1", HFILL }},
260 "Packet Length", "yhoo.len", FT_UINT32, BASE_DEC,
261 NULL, 0, "Packet Length", HFILL }},
263 "Real Nick (nick1)", "yhoo.nick1", FT_STRING, 0,
264 NULL, 0, "Real Nick (nick1)", HFILL }},
266 "Active Nick (nick2)", "yhoo.nick2", FT_STRING, 0,
267 NULL, 0, "Active Nick (nick2)", HFILL }},
268 { &hf_yhoo_content, {
269 "Content", "yhoo.content", FT_STRING, 0,
270 NULL, 0, "Data portion of the packet", HFILL }},
271 { &hf_yhoo_version, {
272 "Version", "yhoo.version", FT_STRING, 0,
273 NULL, 0, "Packet version identifier", HFILL }},
275 static gint *ett[] = {
279 proto_yhoo = proto_register_protocol("Yahoo Messenger Protocol",
282 proto_register_field_array(proto_yhoo, hf, array_length(hf));
284 proto_register_subtree_array(ett, array_length(ett));
288 proto_reg_handoff_yhoo(void)
291 * DO NOT register for port 5050, as that's used by the
292 * old and new Yahoo messenger protocols.
294 * Just register as a heuristic TCP dissector, and reject stuff
295 * not to or from that port.
297 heur_dissector_add("tcp", dissect_yhoo, proto_yhoo);