2 * Routines for LPR and LPRng packet disassembly
3 * Gilbert Ramirez <gram@verdict.uthscsa.edu>
5 * Ethereal - Network traffic analyzer
6 * By Gerald Combs <gerald@unicom.net>
7 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * 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>
48 enum lpr_type { request, response };
51 dissect_lpd(const u_char *pd, int offset, frame_data *fd, GtkTree *tree)
53 GtkWidget *lpd_tree, *ti;
54 enum lpr_type lpr_packet_type;
55 char *newline, *printer, *line_pos;
56 int substr_len, curr_offset;
58 /* This information comes from the LPRng HOWTO, which also describes
59 RFC 1179. http://www.astart.com/lprng/LPRng-HOWTO.html */
60 char *lpd_client_code[] = {
63 "LPR: transfer a printer job",
64 "LPQ: print short form of queue status",
65 "LPQ: print long form of queue status",
67 "LPRng lpc: do control operation",
68 "LPRng lpr: transfer a block format print job",
69 "LPRng lpc: secure command transfer",
70 "LPRng lpq: verbose status information"
72 char *lpd_server_code[] = {
73 "Success: accepted, proceed",
74 "Queue not accepting jobs",
75 "Queue temporarily full, retry later",
76 "Bad job format, do not retry"
80 if (pd[offset+1] == '\n') {
81 lpr_packet_type = response;
83 else if (pd[offset] <= 9) {
84 lpr_packet_type = request;
87 lpr_packet_type = response;
91 if (fd->win_info[0]) {
92 strcpy(fd->win_info[3], "LPD");
93 if (lpr_packet_type == request) {
94 strcpy(fd->win_info[4], lpd_client_code[pd[offset]]);
97 strcpy(fd->win_info[4], "LPD response");
102 ti = add_item_to_tree(GTK_WIDGET(tree), offset, fd->cap_len - offset,
103 "Line Printer Daemon Protocol");
104 lpd_tree = gtk_tree_new();
105 add_subtree(ti, lpd_tree, ETT_LPD);
107 if (lpr_packet_type == request) {
108 if (pd[offset] <= 9) {
109 add_item_to_tree(lpd_tree, offset, 1,
110 lpd_client_code[pd[offset]]);
113 add_item_to_tree(lpd_tree, offset, 1,
116 printer = strdup(&pd[offset+1]);
118 /* get rid of the new-line so that the tree prints out nicely */
119 if (printer[fd->cap_len - offset - 2] == 0x0a) {
120 printer[fd->cap_len - offset - 2] = 0;
122 add_item_to_tree(lpd_tree, offset+1, fd->cap_len - (offset+1),
123 /*"Printer/options: %s", &pd[offset+1]);*/
124 "Printer/options: %s", printer);
128 if (pd[offset] <= 3) {
129 add_item_to_tree(lpd_tree, offset, 2, "Response: %s",
130 lpd_server_code[pd[offset]]);
133 printer = strdup(&pd[offset]);
135 curr_offset = offset;
136 while (fd->cap_len > curr_offset) {
137 newline = strchr(line_pos, '\n');
139 add_item_to_tree(lpd_tree, curr_offset,
140 fd->cap_len - offset, "Text: %s", line_pos);
144 substr_len = strlen(line_pos);
145 add_item_to_tree(lpd_tree, curr_offset, substr_len + 1,
146 "Text: %s", line_pos);
147 curr_offset += substr_len + 1;
148 line_pos = newline + 1;