1999-10-17 11:40:14 +00:00
|
|
|
/* packet-lpd.c
|
1998-09-16 02:39:15 +00:00
|
|
|
* Routines for LPR and LPRng packet disassembly
|
2001-11-13 23:55:44 +00:00
|
|
|
* Gilbert Ramirez <gram@alumni.rice.edu>
|
1998-09-16 02:39:15 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
1998-09-16 03:22:19 +00:00
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
1998-09-16 02:39:15 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
#include <string.h>
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
#include <glib.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
1998-09-16 02:39:15 +00:00
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
#define TCP_PORT_PRINTER 515
|
|
|
|
|
1999-10-17 11:40:14 +00:00
|
|
|
static int proto_lpd = -1;
|
|
|
|
static int hf_lpd_response = -1;
|
|
|
|
static int hf_lpd_request = -1;
|
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint ett_lpd = -1;
|
|
|
|
|
1999-12-15 23:47:30 +00:00
|
|
|
enum lpr_type { request, response, unknown };
|
|
|
|
|
2001-01-06 00:02:41 +00:00
|
|
|
static gint find_printer_string(tvbuff_t *tvb, int offset);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
2001-11-25 22:51:14 +00:00
|
|
|
static dissector_handle_t data_handle;
|
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
static void
|
2001-01-06 00:02:41 +00:00
|
|
|
dissect_lpd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
1998-09-16 02:39:15 +00:00
|
|
|
{
|
1999-03-23 03:14:46 +00:00
|
|
|
proto_tree *lpd_tree;
|
2008-05-14 01:47:41 +00:00
|
|
|
proto_item *ti, *hidden_item;
|
1998-09-16 02:39:15 +00:00
|
|
|
enum lpr_type lpr_packet_type;
|
2001-01-06 00:02:41 +00:00
|
|
|
guint8 code;
|
|
|
|
gint printer_len;
|
1998-09-16 02:39:15 +00:00
|
|
|
|
|
|
|
/* This information comes from the LPRng HOWTO, which also describes
|
|
|
|
RFC 1179. http://www.astart.com/lprng/LPRng-HOWTO.html */
|
2005-07-30 02:06:13 +00:00
|
|
|
static const value_string lpd_client_code[] = {
|
2005-07-29 21:55:45 +00:00
|
|
|
{ 1, "LPC: start print / jobcmd: abort" },
|
|
|
|
{ 2, "LPR: transfer a printer job / jobcmd: receive control file" },
|
|
|
|
{ 3, "LPQ: print short form of queue status / jobcmd: receive data file" },
|
|
|
|
{ 4, "LPQ: print long form of queue status" },
|
|
|
|
{ 5, "LPRM: remove jobs" },
|
|
|
|
{ 6, "LPRng lpc: do control operation" },
|
|
|
|
{ 7, "LPRng lpr: transfer a block format print job" },
|
|
|
|
{ 8, "LPRng lpc: secure command transfer" },
|
|
|
|
{ 9, "LPRng lpq: verbose status information" },
|
|
|
|
{ 0, NULL }
|
1998-09-16 02:39:15 +00:00
|
|
|
};
|
2005-07-30 02:06:13 +00:00
|
|
|
static const value_string lpd_server_code[] = {
|
2005-07-29 21:55:45 +00:00
|
|
|
{ 0, "Success: accepted, proceed" },
|
|
|
|
{ 1, "Queue not accepting jobs" },
|
|
|
|
{ 2, "Queue temporarily full, retry later" },
|
|
|
|
{ 3, "Bad job format, do not retry" },
|
|
|
|
{ 0, NULL }
|
1998-09-16 02:39:15 +00:00
|
|
|
};
|
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "LPD");
|
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
Add the "Edit:Protocols..." feature which currently only implements
the following:
It is now possible to enable/disable a particular protocol decoding
(i.e. the protocol dissector is void or not). When a protocol
is disabled, it is displayed as Data and of course, all linked
sub-protocols are disabled as well.
Disabling a protocol could be interesting:
- in case of buggy dissectors
- in case of wrong heuristics
- for performance reasons
- to decode the data as another protocol (TODO)
Currently (if I am not wrong), all dissectors but NFS can be disabled
(and dissectors that do not register protocols :-)
I do not like the way the RPC sub-dissectors are disabled (in the
sub-dissectors) since this could be done in the RPC dissector itself,
knowing the sub-protocol hfinfo entry (this is why, I've not modified
the NFS one yet).
Two functions are added in proto.c :
gboolean proto_is_protocol_enabled(int n);
void proto_set_decoding(int n, gboolean enabled);
and two MACROs which can be used in dissectors:
OLD_CHECK_DISPLAY_AS_DATA(index, pd, offset, fd, tree)
CHECK_DISPLAY_AS_DATA(index, tvb, pinfo, tree)
See also the XXX in proto_dlg.c and proto.c around the new functions.
svn path=/trunk/; revision=2267
2000-08-13 14:09:15 +00:00
|
|
|
|
2000-04-20 15:24:41 +00:00
|
|
|
/* rfc1179 states that all responses are 1 byte long */
|
2001-01-06 00:02:41 +00:00
|
|
|
code = tvb_get_guint8(tvb, 0);
|
|
|
|
if (tvb_reported_length(tvb) == 1) {
|
1998-09-16 02:39:15 +00:00
|
|
|
lpr_packet_type = response;
|
|
|
|
}
|
2001-01-06 00:02:41 +00:00
|
|
|
else if (code <= 9) {
|
1998-09-16 02:39:15 +00:00
|
|
|
lpr_packet_type = request;
|
|
|
|
}
|
|
|
|
else {
|
1999-12-15 23:47:30 +00:00
|
|
|
lpr_packet_type = unknown;
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO)) {
|
2007-08-30 10:33:24 +00:00
|
|
|
if (lpr_packet_type == request && code !=0) {
|
2007-11-08 22:49:03 +00:00
|
|
|
col_add_str(pinfo->cinfo, COL_INFO, val_to_str(code, lpd_client_code, "Unknown client code: %u"));
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
1999-12-15 23:47:30 +00:00
|
|
|
else if (lpr_packet_type == response) {
|
2001-12-10 00:26:21 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "LPD response");
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
1999-12-15 23:47:30 +00:00
|
|
|
else {
|
2001-12-10 00:26:21 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "LPD continuation");
|
1999-12-15 23:47:30 +00:00
|
|
|
}
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tree) {
|
2002-01-24 09:20:54 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_lpd, tvb, 0, -1, FALSE);
|
1999-11-16 11:44:20 +00:00
|
|
|
lpd_tree = proto_item_add_subtree(ti, ett_lpd);
|
1998-09-16 02:39:15 +00:00
|
|
|
|
1999-10-17 11:40:14 +00:00
|
|
|
if (lpr_packet_type == response) {
|
2008-05-14 01:47:41 +00:00
|
|
|
hidden_item = proto_tree_add_boolean(lpd_tree, hf_lpd_response,
|
2001-01-06 00:02:41 +00:00
|
|
|
tvb, 0, 0, TRUE);
|
1999-10-17 11:40:14 +00:00
|
|
|
} else {
|
2008-05-14 01:47:41 +00:00
|
|
|
hidden_item = proto_tree_add_boolean(lpd_tree, hf_lpd_request,
|
2001-01-06 00:02:41 +00:00
|
|
|
tvb, 0, 0, TRUE);
|
1999-10-17 11:40:14 +00:00
|
|
|
}
|
2008-05-14 01:47:41 +00:00
|
|
|
PROTO_ITEM_SET_HIDDEN(hidden_item);
|
1999-10-17 11:40:14 +00:00
|
|
|
|
1998-09-16 02:39:15 +00:00
|
|
|
if (lpr_packet_type == request) {
|
2001-01-06 00:02:41 +00:00
|
|
|
printer_len = find_printer_string(tvb, 1);
|
|
|
|
|
|
|
|
if (code <= 9 && printer_len != -1) {
|
|
|
|
proto_tree_add_text(lpd_tree, tvb, 0, 1,
|
2005-07-29 21:55:45 +00:00
|
|
|
val_to_str(code, lpd_client_code, "Unknown client code: %u"));
|
2001-01-06 00:02:41 +00:00
|
|
|
proto_tree_add_text(lpd_tree, tvb, 1, printer_len,
|
|
|
|
"Printer/options: %s",
|
|
|
|
tvb_format_text(tvb, 1, printer_len));
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-07-10 09:26:20 +00:00
|
|
|
call_dissector(data_handle,tvb, pinfo, lpd_tree);
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
}
|
1999-12-15 23:47:30 +00:00
|
|
|
else if (lpr_packet_type == response) {
|
2001-01-06 00:02:41 +00:00
|
|
|
if (code <= 3) {
|
|
|
|
proto_tree_add_text(lpd_tree, tvb, 0, 1,
|
2005-07-29 21:55:45 +00:00
|
|
|
"Response: %s", val_to_str(code, lpd_server_code, "Unknown server code: %u"));
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-07-10 09:26:20 +00:00
|
|
|
call_dissector(data_handle,tvb, pinfo, lpd_tree);
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
}
|
1999-12-15 23:47:30 +00:00
|
|
|
else {
|
2005-07-10 09:26:20 +00:00
|
|
|
call_dissector(data_handle,tvb, pinfo, lpd_tree);
|
1999-12-15 23:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-06 00:02:41 +00:00
|
|
|
static gint
|
|
|
|
find_printer_string(tvbuff_t *tvb, int offset)
|
1999-12-15 23:47:30 +00:00
|
|
|
{
|
2001-01-06 00:02:41 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* try to find end of string, either '\n' or '\0' */
|
|
|
|
i = tvb_find_guint8(tvb, offset, -1, '\0');
|
|
|
|
if (i == -1)
|
|
|
|
i = tvb_find_guint8(tvb, offset, -1, '\n');
|
|
|
|
if (i == -1)
|
|
|
|
return -1;
|
|
|
|
return i - offset; /* length of string */
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
|
1999-12-15 23:47:30 +00:00
|
|
|
|
1999-10-17 11:40:14 +00:00
|
|
|
void
|
|
|
|
proto_register_lpd(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_lpd_response,
|
2002-08-28 21:04:11 +00:00
|
|
|
{ "Response", "lpd.response",
|
1999-10-17 11:40:14 +00:00
|
|
|
FT_BOOLEAN, BASE_NONE, NULL, 0x0,
|
2001-06-18 02:18:27 +00:00
|
|
|
"TRUE if LPD response", HFILL }},
|
1999-10-17 11:40:14 +00:00
|
|
|
|
|
|
|
{ &hf_lpd_request,
|
|
|
|
{ "Request", "lpd.request",
|
|
|
|
FT_BOOLEAN, BASE_NONE, NULL, 0x0,
|
2001-06-18 02:18:27 +00:00
|
|
|
"TRUE if LPD request", HFILL }}
|
1999-10-17 11:40:14 +00:00
|
|
|
};
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_lpd,
|
|
|
|
};
|
1999-10-17 11:40:14 +00:00
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_lpd = proto_register_protocol("Line Printer Daemon Protocol", "LPD", "lpd");
|
1999-10-17 11:40:14 +00:00
|
|
|
proto_register_field_array(proto_lpd, hf, array_length(hf));
|
1999-11-16 11:44:20 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
1999-10-17 11:40:14 +00:00
|
|
|
}
|
1999-12-15 23:47:30 +00:00
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
void
|
|
|
|
proto_reg_handoff_lpd(void)
|
|
|
|
{
|
2001-12-03 04:00:26 +00:00
|
|
|
dissector_handle_t lpd_handle;
|
|
|
|
|
|
|
|
lpd_handle = create_dissector_handle(dissect_lpd, proto_lpd);
|
|
|
|
dissector_add("tcp.port", TCP_PORT_PRINTER, lpd_handle);
|
2001-11-25 22:51:14 +00:00
|
|
|
data_handle = find_dissector("data");
|
2000-04-08 07:07:42 +00:00
|
|
|
}
|