MSWSP: add ids for another unknown Property Set
[wireshark-wip.git] / epan / dissectors / packet-lpd.c
blob48f94f511cb0d70b672c06bc63ee90c4d447b1bc
1 /* packet-lpd.c
2 * Routines for LPR and LPRng packet disassembly
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
29 #include <epan/packet.h>
31 #define TCP_PORT_PRINTER 515
33 static int proto_lpd = -1;
34 static int hf_lpd_response = -1;
35 static int hf_lpd_request = -1;
37 static gint ett_lpd = -1;
39 enum lpr_type { request, response, unknown };
41 static gint find_printer_string(tvbuff_t *tvb, int offset);
43 static dissector_handle_t data_handle;
45 static void
46 dissect_lpd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
48 proto_tree *lpd_tree;
49 proto_item *ti, *hidden_item;
50 enum lpr_type lpr_packet_type;
51 guint8 code;
52 gint printer_len;
54 /* This information comes from the LPRng HOWTO, which also describes
55 RFC 1179. http://www.astart.com/lprng/LPRng-HOWTO.html */
56 static const value_string lpd_client_code[] = {
57 { 1, "LPC: start print / jobcmd: abort" },
58 { 2, "LPR: transfer a printer job / jobcmd: receive control file" },
59 { 3, "LPQ: print short form of queue status / jobcmd: receive data file" },
60 { 4, "LPQ: print long form of queue status" },
61 { 5, "LPRM: remove jobs" },
62 { 6, "LPRng lpc: do control operation" },
63 { 7, "LPRng lpr: transfer a block format print job" },
64 { 8, "LPRng lpc: secure command transfer" },
65 { 9, "LPRng lpq: verbose status information" },
66 { 0, NULL }
68 static const value_string lpd_server_code[] = {
69 { 0, "Success: accepted, proceed" },
70 { 1, "Queue not accepting jobs" },
71 { 2, "Queue temporarily full, retry later" },
72 { 3, "Bad job format, do not retry" },
73 { 0, NULL }
76 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LPD");
77 col_clear(pinfo->cinfo, COL_INFO);
79 /* rfc1179 states that all responses are 1 byte long */
80 code = tvb_get_guint8(tvb, 0);
81 if (tvb_reported_length(tvb) == 1) {
82 lpr_packet_type = response;
84 else if (code <= 9) {
85 lpr_packet_type = request;
87 else {
88 lpr_packet_type = unknown;
91 if (lpr_packet_type == request && code !=0) {
92 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(code, lpd_client_code, "Unknown client code: %u"));
94 else if (lpr_packet_type == response) {
95 col_set_str(pinfo->cinfo, COL_INFO, "LPD response");
97 else {
98 col_set_str(pinfo->cinfo, COL_INFO, "LPD continuation");
101 if (tree) {
102 ti = proto_tree_add_item(tree, proto_lpd, tvb, 0, -1, ENC_NA);
103 lpd_tree = proto_item_add_subtree(ti, ett_lpd);
105 if (lpr_packet_type == response) {
106 hidden_item = proto_tree_add_boolean(lpd_tree, hf_lpd_response,
107 tvb, 0, 0, TRUE);
108 } else {
109 hidden_item = proto_tree_add_boolean(lpd_tree, hf_lpd_request,
110 tvb, 0, 0, TRUE);
112 PROTO_ITEM_SET_HIDDEN(hidden_item);
114 if (lpr_packet_type == request) {
115 printer_len = find_printer_string(tvb, 1);
117 if (code <= 9 && printer_len != -1) {
118 proto_tree_add_text(lpd_tree, tvb, 0, 1, "%s",
119 val_to_str(code, lpd_client_code, "Unknown client code: %u"));
120 proto_tree_add_text(lpd_tree, tvb, 1, printer_len,
121 "Printer/options: %s",
122 tvb_format_text(tvb, 1, printer_len));
124 else {
125 call_dissector(data_handle,tvb, pinfo, lpd_tree);
128 else if (lpr_packet_type == response) {
129 if (code <= 3) {
130 proto_tree_add_text(lpd_tree, tvb, 0, 1,
131 "Response: %s", val_to_str(code, lpd_server_code, "Unknown server code: %u"));
133 else {
134 call_dissector(data_handle,tvb, pinfo, lpd_tree);
137 else {
138 call_dissector(data_handle,tvb, pinfo, lpd_tree);
144 static gint
145 find_printer_string(tvbuff_t *tvb, int offset)
147 int i;
149 /* try to find end of string, either '\n' or '\0' */
150 i = tvb_find_guint8(tvb, offset, -1, '\0');
151 if (i == -1)
152 i = tvb_find_guint8(tvb, offset, -1, '\n');
153 if (i == -1)
154 return -1;
155 return i - offset; /* length of string */
159 void
160 proto_register_lpd(void)
162 static hf_register_info hf[] = {
163 { &hf_lpd_response,
164 { "Response", "lpd.response",
165 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
166 "TRUE if LPD response", HFILL }},
168 { &hf_lpd_request,
169 { "Request", "lpd.request",
170 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
171 "TRUE if LPD request", HFILL }}
173 static gint *ett[] = {
174 &ett_lpd,
177 proto_lpd = proto_register_protocol("Line Printer Daemon Protocol", "LPD", "lpd");
178 proto_register_field_array(proto_lpd, hf, array_length(hf));
179 proto_register_subtree_array(ett, array_length(ett));
182 void
183 proto_reg_handoff_lpd(void)
185 dissector_handle_t lpd_handle;
187 lpd_handle = create_dissector_handle(dissect_lpd, proto_lpd);
188 dissector_add_uint("tcp.port", TCP_PORT_PRINTER, lpd_handle);
189 data_handle = find_dissector("data");