HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-ymsg.c
blobfbc071bc58f45664b00f46f3ee1a76ada8710b10
1 /* packet-ymsg.c
2 * Routines for Yahoo Messenger YMSG protocol packet version 13 dissection
3 * Copyright 2003, Wayne Parrott <wayne_p@pacific.net.au>
4 * Copied from packet-yhoo.c and updated
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include "config.h"
29 #include <glib.h>
30 #include <epan/packet.h>
32 #include "packet-tcp.h"
33 #include <epan/prefs.h>
35 static int proto_ymsg = -1;
36 static int hf_ymsg_version = -1;
37 static int hf_ymsg_vendor = -1;
38 static int hf_ymsg_len = -1;
39 static int hf_ymsg_service = -1;
40 static int hf_ymsg_status = -1;
41 static int hf_ymsg_session_id = -1;
43 static int hf_ymsg_content = -1;
44 static int hf_ymsg_content_line = -1;
45 static int hf_ymsg_content_line_key = -1;
46 static int hf_ymsg_content_line_value = -1;
48 static gint ett_ymsg = -1;
49 static gint ett_ymsg_content = -1;
50 static gint ett_ymsg_content_line = -1;
52 #define TCP_PORT_YMSG 23 /* XXX - this is Telnet! */
53 #define TCP_PORT_YMSG_2 25 /* And this is SMTP! */
54 #define TCP_PORT_YMSG_3 5050 /* This, however, is regular Yahoo Messenger */
56 /* desegmentation of YMSG over TCP */
57 static gboolean ymsg_desegment = TRUE;
60 * This is from yahoolib2.c from libyahoo2.
62 * See also
64 * http://libyahoo2.sourceforge.net/ymsg-9.txt
66 * and
68 * http://www.venkydude.com/articles/yahoo.htm
70 * and
72 * http://www.cse.iitb.ac.in/~varunk/YahooProtocol.htm
74 * and
76 * http://www.geocrawler.com/archives/3/4893/2002/1/0/7459037/
78 * and
80 * http://www.geocities.com/ziggycubbe/ym.html
83 /* Service constants */
84 enum yahoo_service { /* these are easier to see in hex */
85 YAHOO_SERVICE_LOGON = 1,
86 YAHOO_SERVICE_LOGOFF,
87 YAHOO_SERVICE_ISAWAY,
88 YAHOO_SERVICE_ISBACK,
89 YAHOO_SERVICE_IDLE, /* 5 (placemarker) */
90 YAHOO_SERVICE_MESSAGE,
91 YAHOO_SERVICE_IDACT,
92 YAHOO_SERVICE_IDDEACT,
93 YAHOO_SERVICE_MAILSTAT,
94 YAHOO_SERVICE_USERSTAT, /* 0xa */
95 YAHOO_SERVICE_NEWMAIL,
96 YAHOO_SERVICE_CHATINVITE,
97 YAHOO_SERVICE_CALENDAR,
98 YAHOO_SERVICE_NEWPERSONALMAIL,
99 YAHOO_SERVICE_NEWCONTACT,
100 YAHOO_SERVICE_ADDIDENT, /* 0x10 */
101 YAHOO_SERVICE_ADDIGNORE,
102 YAHOO_SERVICE_PING,
103 YAHOO_SERVICE_GOTGROUPRENAME, /* < 1, 36(old), 37(new) */
104 YAHOO_SERVICE_SYSMESSAGE = 0x14,
105 YAHOO_SERVICE_SKINNAME = 0x15,
106 YAHOO_SERVICE_PASSTHROUGH2 = 0x16,
107 YAHOO_SERVICE_CONFINVITE = 0x18,
108 YAHOO_SERVICE_CONFLOGON,
109 YAHOO_SERVICE_CONFDECLINE,
110 YAHOO_SERVICE_CONFLOGOFF,
111 YAHOO_SERVICE_CONFADDINVITE,
112 YAHOO_SERVICE_CONFMSG,
113 YAHOO_SERVICE_CHATLOGON,
114 YAHOO_SERVICE_CHATLOGOFF,
115 YAHOO_SERVICE_CHATMSG = 0x20,
116 YAHOO_SERVICE_GAMELOGON = 0x28,
117 YAHOO_SERVICE_GAMELOGOFF,
118 YAHOO_SERVICE_GAMEMSG = 0x2a,
119 YAHOO_SERVICE_FILETRANSFER = 0x46,
120 YAHOO_SERVICE_VOICECHAT = 0x4A,
121 YAHOO_SERVICE_NOTIFY,
122 YAHOO_SERVICE_VERIFY,
123 YAHOO_SERVICE_P2PFILEXFER,
124 YAHOO_SERVICE_PEERTOPEER = 0x4F, /* Checks if P2P possible */
125 YAHOO_SERVICE_WEBCAM,
126 YAHOO_SERVICE_AUTHRESP = 0x54,
127 YAHOO_SERVICE_LIST,
128 YAHOO_SERVICE_AUTH = 0x57,
129 YAHOO_SERVICE_AUTHBUDDY = 0x6d,
130 YAHOO_SERVICE_ADDBUDDY = 0x83,
131 YAHOO_SERVICE_REMBUDDY,
132 YAHOO_SERVICE_IGNORECONTACT, /* > 1, 7, 13 < 1, 66, 13, 0*/
133 YAHOO_SERVICE_REJECTCONTACT,
134 YAHOO_SERVICE_GROUPRENAME = 0x89, /* > 1, 65(new), 66(0), 67(old) */
135 YAHOO_SERVICE_KEEPALIVE = 0x8a,
136 YAHOO_SERVICE_CHATONLINE = 0x96, /* > 109(id), 1, 6(abcde) < 0,1*/
137 YAHOO_SERVICE_CHATGOTO,
138 YAHOO_SERVICE_CHATJOIN, /* > 1 104-room 129-1600326591 62-2 */
139 YAHOO_SERVICE_CHATLEAVE,
140 YAHOO_SERVICE_CHATEXIT = 0x9b,
141 YAHOO_SERVICE_CHATADDINVITE = 0x9d,
142 YAHOO_SERVICE_CHATLOGOUT = 0xa0,
143 YAHOO_SERVICE_CHATPING,
144 YAHOO_SERVICE_COMMENT = 0xa8,
145 YAHOO_SERVICE_GAME_INVITE = 0xb7,
146 YAHOO_SERVICE_STEALTH_PERM = 0xb9,
147 YAHOO_SERVICE_STEALTH_SESSION = 0xba,
148 YAHOO_SERVICE_AVATAR = 0xbc,
149 YAHOO_SERVICE_PICTURE_CHECKSUM = 0xbd,
150 YAHOO_SERVICE_PICTURE = 0xbe,
151 YAHOO_SERVICE_PICTURE_UPDATE = 0xc1,
152 YAHOO_SERVICE_PICTURE_UPLOAD = 0xc2,
153 YAHOO_SERVICE_YAB_UPDATE = 0xc4,
154 YAHOO_SERVICE_Y6_VISIBLE_TOGGLE = 0xc5, /* YMSG13, key 13: 2 = invisible, 1 = visible */
155 YAHOO_SERVICE_Y6_STATUS_UPDATE = 0xc6, /* YMSG13 */
156 YAHOO_SERVICE_PICTURE_STATUS = 0xc7, /* YMSG13, key 213: 0 = none, 1 = avatar, 2 = picture */
157 YAHOO_SERVICE_VERIFY_ID_EXISTS = 0xc8,
158 YAHOO_SERVICE_AUDIBLE = 0xd0,
159 YAHOO_SERVICE_Y7_PHOTO_SHARING = 0xd2,
160 YAHOO_SERVICE_Y7_CONTACT_DETAILS = 0xd3, /* YMSG13 */
161 YAHOO_SERVICE_Y7_CHAT_SESSION = 0xd4,
162 YAHOO_SERVICE_Y7_AUTHORIZATION = 0xd6, /* YMSG13 */
163 YAHOO_SERVICE_Y7_FILETRANSFER = 0xdc, /* YMSG13 */
164 YAHOO_SERVICE_Y7_FILETRANSFERINFO, /* YMSG13 */
165 YAHOO_SERVICE_Y7_FILETRANSFERACCEPT, /* YMSG13 */
166 YAHOO_SERVICE_Y7_MINGLE = 0xe1, /* YMSG13 */
167 YAHOO_SERVICE_Y7_CHANGE_GROUP = 0xe7, /* YMSG13 */
168 YAHOO_SERVICE_STATUS_15 = 0xf0,
169 YAHOO_SERVICE_LIST_15 = 0xf1,
170 YAHOO_SERVICE_WEBLOGIN = 0x0226,
171 YAHOO_SERVICE_SMS_MSG = 0x02ea
174 /* Message flags */
175 enum yahoo_status {
176 YAHOO_STATUS_AVAILABLE = 0,
177 YAHOO_STATUS_BRB,
178 YAHOO_STATUS_BUSY,
179 YAHOO_STATUS_NOTATHOME,
180 YAHOO_STATUS_NOTATDESK,
181 YAHOO_STATUS_NOTINOFFICE,
182 YAHOO_STATUS_ONPHONE,
183 YAHOO_STATUS_ONVACATION,
184 YAHOO_STATUS_OUTTOLUNCH,
185 YAHOO_STATUS_STEPPEDOUT,
186 YAHOO_STATUS_INVISIBLE = 12,
187 YAHOO_STATUS_CUSTOM = 99,
188 YAHOO_STATUS_IDLE = 999,
189 YAHOO_STATUS_WEBLOGIN = 0x5a55aa55,
190 YAHOO_STATUS_OFFLINE = 0x5a55aa56, /* don't ask */
191 YAHOO_STATUS_TYPING = 0x16,
192 YAHOO_STATUS_DISCONNECTED = -1 /* in ymsg 15. doesnt mean the normal sense of 'disconnected' */
195 enum ypacket_status {
196 YPACKET_STATUS_DISCONNECTED = -1,
197 YPACKET_STATUS_DEFAULT = 0,
198 YPACKET_STATUS_SERVERACK = 1,
199 YPACKET_STATUS_GAME = 0x2,
200 YPACKET_STATUS_AWAY = 0x4,
201 YPACKET_STATUS_CONTINUED = 0x5,
202 YPACKET_STATUS_INVISIBLE = 12,
203 YPACKET_STATUS_NOTIFY = 0x16, /* TYPING */
204 YPACKET_STATUS_WEBLOGIN = 0x5a55aa55,
205 YPACKET_STATUS_OFFLINE = 0x5a55aa56
208 /* The size of the below struct minus 6 bytes of content */
209 #define YAHOO_HEADER_SIZE 20
211 #if 0
212 struct yahoo_rawpacket
214 char ymsg[4]; /* Packet identification string (YMSG) */
215 unsigned char version[2]; /* 2 bytes, little endian */
216 unsigned char vendor[2]; /* 2 bytes, little endian */
217 unsigned char len[2]; /* length - little endian */
218 unsigned char service[2]; /* service - little endian */
219 unsigned char status[4]; /* Status - online, away etc.*/
220 unsigned char session_id[4]; /* Session ID */
221 char content[6]; /* 6 is the minimum size of the content */
223 #endif
225 static const value_string ymsg_service_vals[] = {
226 {YAHOO_SERVICE_LOGON, "Pager Logon"},
227 {YAHOO_SERVICE_LOGOFF, "Pager Logoff"},
228 {YAHOO_SERVICE_ISAWAY, "Is Away"},
229 {YAHOO_SERVICE_ISBACK, "Is Back"},
230 {YAHOO_SERVICE_IDLE, "Idle"},
231 {YAHOO_SERVICE_MESSAGE, "Message"},
232 {YAHOO_SERVICE_IDACT, "Activate Identity"},
233 {YAHOO_SERVICE_IDDEACT, "Deactivate Identity"},
234 {YAHOO_SERVICE_MAILSTAT, "Mail Status"},
235 {YAHOO_SERVICE_USERSTAT, "User Status"},
236 {YAHOO_SERVICE_NEWMAIL, "New Mail"},
237 {YAHOO_SERVICE_CHATINVITE, "Chat Invitation"},
238 {YAHOO_SERVICE_CALENDAR, "Calendar Reminder"},
239 {YAHOO_SERVICE_NEWPERSONALMAIL, "New Personals Mail"},
240 {YAHOO_SERVICE_NEWCONTACT, "New Friend"},
241 {YAHOO_SERVICE_ADDIDENT, "Add Identity"},
242 {YAHOO_SERVICE_ADDIGNORE, "Add Ignore"},
243 {YAHOO_SERVICE_PING, "Ping"},
244 {YAHOO_SERVICE_GOTGROUPRENAME, "Got Group Rename"},
245 {YAHOO_SERVICE_SYSMESSAGE, "System Message"},
246 {YAHOO_SERVICE_SKINNAME, "Skinname"},
247 {YAHOO_SERVICE_PASSTHROUGH2, "Passthrough 2"},
248 {YAHOO_SERVICE_CONFINVITE, "Conference Invitation"},
249 {YAHOO_SERVICE_CONFLOGON, "Conference Logon"},
250 {YAHOO_SERVICE_CONFDECLINE, "Conference Decline"},
251 {YAHOO_SERVICE_CONFLOGOFF, "Conference Logoff"},
252 {YAHOO_SERVICE_CONFADDINVITE, "Conference Additional Invitation"},
253 {YAHOO_SERVICE_CONFMSG, "Conference Message"},
254 {YAHOO_SERVICE_CHATLOGON, "Chat Logon"},
255 {YAHOO_SERVICE_CHATLOGOFF, "Chat Logoff"},
256 {YAHOO_SERVICE_CHATMSG, "Chat Message"},
257 {YAHOO_SERVICE_GAMELOGON, "Game Logon"},
258 {YAHOO_SERVICE_GAMELOGOFF, "Game Logoff"},
259 {YAHOO_SERVICE_GAMEMSG, "Game Message"},
260 {YAHOO_SERVICE_FILETRANSFER, "File Transfer"},
261 {YAHOO_SERVICE_VOICECHAT, "Voice Chat"},
262 {YAHOO_SERVICE_NOTIFY, "Notify"},
263 {YAHOO_SERVICE_VERIFY, "Verify"},
264 {YAHOO_SERVICE_P2PFILEXFER, "P2P File Transfer"},
265 {YAHOO_SERVICE_PEERTOPEER, "Peer To Peer"},
266 {YAHOO_SERVICE_WEBCAM, "WebCam"},
267 {YAHOO_SERVICE_AUTHRESP, "Authentication Response"},
268 {YAHOO_SERVICE_LIST, "List"},
269 {YAHOO_SERVICE_AUTH, "Authentication"},
270 {YAHOO_SERVICE_AUTHBUDDY, "Authorize Buddy"},
271 {YAHOO_SERVICE_ADDBUDDY, "Add Buddy"},
272 {YAHOO_SERVICE_REMBUDDY, "Remove Buddy"},
273 {YAHOO_SERVICE_IGNORECONTACT, "Ignore Contact"},
274 {YAHOO_SERVICE_REJECTCONTACT, "Reject Contact"},
275 {YAHOO_SERVICE_GROUPRENAME, "Group Rename"},
276 {YAHOO_SERVICE_KEEPALIVE, "Keep Alive"},
277 {YAHOO_SERVICE_CHATONLINE, "Chat Online"},
278 {YAHOO_SERVICE_CHATGOTO, "Chat Goto"},
279 {YAHOO_SERVICE_CHATJOIN, "Chat Join"},
280 {YAHOO_SERVICE_CHATLEAVE, "Chat Leave"},
281 {YAHOO_SERVICE_CHATEXIT, "Chat Exit"},
282 {YAHOO_SERVICE_CHATADDINVITE, "Chat Invite"},
283 {YAHOO_SERVICE_CHATLOGOUT, "Chat Logout"},
284 {YAHOO_SERVICE_CHATPING, "Chat Ping"},
285 {YAHOO_SERVICE_COMMENT, "Comment"},
286 {YAHOO_SERVICE_GAME_INVITE, "Game Invite"},
287 {YAHOO_SERVICE_STEALTH_PERM, "Stealth Permanent"},
288 {YAHOO_SERVICE_STEALTH_SESSION, "Stealth Session"},
289 {YAHOO_SERVICE_AVATAR, "Avatar"},
290 {YAHOO_SERVICE_PICTURE_CHECKSUM, "Picture Checksum"},
291 {YAHOO_SERVICE_PICTURE, "Picture"},
292 {YAHOO_SERVICE_PICTURE_UPDATE, "Picture Update"},
293 {YAHOO_SERVICE_PICTURE_UPLOAD, "Picture Upload"},
294 {YAHOO_SERVICE_YAB_UPDATE, "Yahoo Address Book Update"},
295 {YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, "Y6 Visibility Toggle"},
296 {YAHOO_SERVICE_Y6_STATUS_UPDATE, "Y6 Status Update"},
297 {YAHOO_SERVICE_PICTURE_STATUS, "Picture Sharing Status"},
298 {YAHOO_SERVICE_VERIFY_ID_EXISTS, "Verify ID Exists"},
299 {YAHOO_SERVICE_AUDIBLE, "Audible"},
300 {YAHOO_SERVICE_Y7_CONTACT_DETAILS, "Y7 Contact Details"},
301 {YAHOO_SERVICE_Y7_CHAT_SESSION, "Y7 Chat Session"},
302 {YAHOO_SERVICE_Y7_AUTHORIZATION, "Y7 Buddy Authorization"},
303 {YAHOO_SERVICE_Y7_FILETRANSFER, "Y7 File Transfer"},
304 {YAHOO_SERVICE_Y7_FILETRANSFERINFO, "Y7 File Transfer Information"},
305 {YAHOO_SERVICE_Y7_FILETRANSFERACCEPT, "Y7 File Transfer Accept"},
306 {YAHOO_SERVICE_Y7_CHANGE_GROUP, "Y7 Change Group"},
307 {YAHOO_SERVICE_STATUS_15, "Status V15"},
308 {YAHOO_SERVICE_LIST_15, "List V15"},
309 {YAHOO_SERVICE_WEBLOGIN, "WebLogin"},
310 {YAHOO_SERVICE_SMS_MSG, "SMS Message"},
311 {0, NULL}
314 static const value_string ymsg_status_vals[] = {
315 {YPACKET_STATUS_DISCONNECTED, "Disconnected"},
316 {YPACKET_STATUS_DEFAULT, "Default"},
317 {YPACKET_STATUS_SERVERACK, "Server Ack"},
318 {YPACKET_STATUS_GAME, "Playing Game"},
319 {YPACKET_STATUS_AWAY, "Away"},
320 {YPACKET_STATUS_CONTINUED, "More Packets??"},
321 {YPACKET_STATUS_NOTIFY, "Notify"},
322 {YPACKET_STATUS_WEBLOGIN, "Web Login"},
323 {YPACKET_STATUS_OFFLINE, "Offline"},
324 {0, NULL}
327 /* Find the end of the current content line and return its length */
328 static int get_content_item_length(tvbuff_t *tvb, int offset)
330 int origoffset = offset;
332 /* Keep reading until the magic delimiter (or end of tvb) is found */
333 while (tvb_length_remaining(tvb, offset) >= 2) {
334 if (tvb_get_ntohs(tvb, offset) == 0xc080) {
335 break;
337 offset += 1;
339 return offset - origoffset;
342 static guint
343 get_ymsg_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
345 guint plen;
348 * Get the length of the YMSG packet.
350 plen = tvb_get_ntohs(tvb, offset + 8);
353 * That length doesn't include the length of the header itself; add that in.
355 return plen + YAHOO_HEADER_SIZE;
358 static int
359 dissect_ymsg_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
361 proto_tree *ymsg_tree, *ti;
362 proto_item *content_item;
363 proto_tree *content_tree;
364 char *keybuf;
365 char *valbuf;
366 int keylen;
367 int vallen;
368 int content_len;
369 int offset = 0;
371 col_set_str(pinfo->cinfo, COL_PROTOCOL, "YMSG");
373 col_add_fstr(pinfo->cinfo, COL_INFO,
374 "%s (status=%s) ",
375 val_to_str(tvb_get_ntohs(tvb, offset + 10),
376 ymsg_service_vals, "Unknown Service: %u"),
377 val_to_str(tvb_get_ntohl(tvb, offset + 12),
378 ymsg_status_vals, "Unknown Status: %u")
381 if (tree) {
382 ti = proto_tree_add_item(tree, proto_ymsg, tvb, offset, -1, ENC_NA);
383 ymsg_tree = proto_item_add_subtree(ti, ett_ymsg);
385 offset += 4; /* skip the YMSG string */
387 /* Version */
388 proto_tree_add_item(ymsg_tree, hf_ymsg_version, tvb, offset, 2, ENC_BIG_ENDIAN);
389 offset += 2;
391 /* Vendor ID */
392 proto_tree_add_item(ymsg_tree, hf_ymsg_vendor, tvb, offset, 2, ENC_BIG_ENDIAN);
393 offset += 2;
395 /* Length */
396 content_len = tvb_get_ntohs(tvb, offset);
397 proto_tree_add_item(ymsg_tree, hf_ymsg_len, tvb, offset, 2, ENC_BIG_ENDIAN);
398 offset += 2;
400 /* Service */
401 proto_item_append_text(ti, " (%s)",
402 val_to_str_const(tvb_get_ntohs(tvb, offset),
403 ymsg_service_vals,
404 "Unknown"));
406 proto_tree_add_item(ymsg_tree, hf_ymsg_service, tvb, offset, 2, ENC_BIG_ENDIAN);
407 offset += 2;
409 /* Status */
410 proto_tree_add_item(ymsg_tree, hf_ymsg_status, tvb, offset, 4, ENC_BIG_ENDIAN);
411 offset += 4;
413 /* Session id */
414 proto_tree_add_item(ymsg_tree, hf_ymsg_session_id, tvb, offset, 4, ENC_LITTLE_ENDIAN);
415 offset += 4;
417 /* Contents */
418 if (content_len) {
419 /* Create content subtree */
420 content_item = proto_tree_add_item(ymsg_tree, hf_ymsg_content, tvb,
421 offset, -1, ENC_ASCII|ENC_NA);
422 content_tree = proto_item_add_subtree(content_item, ett_ymsg_content);
424 /* Each entry consists of:
425 <key string> <delimiter> <value string> <delimiter>
428 /* Parse and show each line of the contents */
429 for (;;)
431 proto_item *ti_2;
432 proto_tree *content_line_tree;
434 /* Don't continue unless there is room for another whole item.
435 (including 2 2-byte delimiters */
436 if (offset >= (YAHOO_HEADER_SIZE+content_len-4))
438 break;
441 /* Get the length of the key */
442 keylen = get_content_item_length(tvb, offset);
443 /* Extract the key */
444 keybuf = tvb_format_text(tvb, offset, keylen);
446 /* Get the length of the value */
447 vallen = get_content_item_length(tvb, offset+keylen+2);
448 /* Extract the value */
449 valbuf = tvb_format_text(tvb, offset+keylen+2, vallen);
451 /* Add a text item with the key... */
452 ti_2 = proto_tree_add_string_format(content_tree, hf_ymsg_content_line, tvb,
453 offset, keylen+2+vallen+2,
454 "", "%s:%s", keybuf, valbuf);
455 content_line_tree = proto_item_add_subtree(ti_2, ett_ymsg_content_line);
457 /* And add the key and value separately inside */
458 proto_tree_add_item(content_line_tree, hf_ymsg_content_line_key, tvb,
459 offset, keylen, ENC_ASCII|ENC_NA);
460 proto_tree_add_item(content_line_tree, hf_ymsg_content_line_value, tvb,
461 offset+keylen+2, vallen, ENC_ASCII|ENC_NA);
463 /* Move beyone key and value lines */
464 offset += keylen+2+vallen+2;
469 col_set_fence(pinfo->cinfo, COL_INFO);
471 return tvb_length(tvb);
475 static gboolean
476 dissect_ymsg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
478 if (tvb_length(tvb) < 4) {
479 return FALSE;
481 if (tvb_memeql(tvb, 0, "YMSG", 4) == -1) {
482 /* Not a Yahoo Messenger packet. */
483 return FALSE;
486 tcp_dissect_pdus(tvb, pinfo, tree, ymsg_desegment, 10, get_ymsg_pdu_len,
487 dissect_ymsg_pdu, data);
488 return TRUE;
491 void
492 proto_register_ymsg(void)
494 static hf_register_info hf[] = {
495 { &hf_ymsg_version, {
496 "Version", "ymsg.version", FT_UINT16, BASE_DEC,
497 NULL, 0, "Packet version identifier", HFILL }},
498 { &hf_ymsg_vendor, {
499 "Vendor ID", "ymsg.vendor", FT_UINT16, BASE_DEC,
500 NULL, 0, "Vendor identifier", HFILL }},
501 { &hf_ymsg_len, {
502 "Packet Length", "ymsg.len", FT_UINT16, BASE_DEC,
503 NULL, 0, NULL, HFILL }},
504 { &hf_ymsg_service, {
505 "Service", "ymsg.service", FT_UINT16, BASE_DEC,
506 VALS(ymsg_service_vals), 0, "Service Type", HFILL }},
507 { &hf_ymsg_status, {
508 "Status", "ymsg.status", FT_UINT32, BASE_DEC,
509 VALS(ymsg_status_vals), 0, "Message Type Flags", HFILL }},
510 { &hf_ymsg_session_id, {
511 "Session ID", "ymsg.session_id", FT_UINT32, BASE_HEX,
512 NULL, 0, "Connection ID", HFILL }},
514 { &hf_ymsg_content, {
515 "Content", "ymsg.content", FT_STRING, BASE_NONE,
516 NULL, 0, "Data portion of the packet", HFILL }},
517 { &hf_ymsg_content_line, {
518 "Content-line", "ymsg.content-line", FT_STRING, BASE_NONE,
519 NULL, 0, "Data portion of the packet", HFILL }},
520 { &hf_ymsg_content_line_key, {
521 "Key", "ymsg.content-line.key", FT_STRING, BASE_NONE,
522 NULL, 0, "Content line key", HFILL }},
523 { &hf_ymsg_content_line_value, {
524 "Value", "ymsg.content-line.value", FT_STRING, BASE_NONE,
525 NULL, 0, "Content line value", HFILL }}
527 static gint *ett[] = {
528 &ett_ymsg,
529 &ett_ymsg_content,
530 &ett_ymsg_content_line
532 module_t *ymsg_module;
534 proto_ymsg = proto_register_protocol("Yahoo YMSG Messenger Protocol",
535 "YMSG", "ymsg");
537 proto_register_field_array(proto_ymsg, hf, array_length(hf));
539 proto_register_subtree_array(ett, array_length(ett));
541 ymsg_module = prefs_register_protocol(proto_ymsg, NULL);
542 prefs_register_bool_preference(ymsg_module, "desegment",
543 "Reassemble YMSG messages spanning multiple TCP segments",
544 "Whether the YMSG dissector should reassemble messages spanning multiple TCP segments. "
545 "To use this option, you must also enable"
546 " \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
547 &ymsg_desegment);
550 void
551 proto_reg_handoff_ymsg(void)
554 * DO NOT register for port 23, as that's Telnet, or for port
555 * 25, as that's SMTP.
557 * Also, DO NOT register for port 5050, as that's used by the
558 * old and new Yahoo messenger protocols.
560 * Just register as a heuristic TCP dissector, and reject stuff
561 * that doesn't begin with a YMSG signature.
563 heur_dissector_add("tcp", dissect_ymsg, proto_ymsg);