]>
The Tcpdump Group git mirrors - tcpdump/blob - print-tftp.c
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * Format and print trivial file transfer protocol packets.
25 static const char rcsid
[] _U_
=
26 "@(#) $Header: /tcpdump/master/tcpdump/print-tftp.c,v 1.39 2008-04-11 16:47:38 gianluca Exp $ (LBL)";
33 #include <tcpdump-stdinc.h>
36 #undef SEGSIZE /* SINIX sucks */
42 #include "interface.h"
43 #include "addrtoname.h"
47 * Trivial File Transfer Protocol (IEN-133)
49 #define SEGSIZE 512 /* data segment size */
54 #define RRQ 01 /* read request */
55 #define WRQ 02 /* write request */
56 #define DATA 03 /* data packet */
57 #define ACK 04 /* acknowledgement */
58 #define TFTP_ERROR 05 /* error code */
59 #define OACK 06 /* option acknowledgement */
62 unsigned short th_opcode
; /* packet type */
64 unsigned short tu_block
; /* block # */
65 unsigned short tu_code
; /* error code */
66 char tu_stuff
[1]; /* request packet stuff */
68 char th_data
[1]; /* data or error string */
71 #define th_block th_u.tu_block
72 #define th_code th_u.tu_code
73 #define th_stuff th_u.tu_stuff
74 #define th_msg th_data
79 #define EUNDEF 0 /* not defined */
80 #define ENOTFOUND 1 /* file not found */
81 #define EACCESS 2 /* access violation */
82 #define ENOSPACE 3 /* disk full or allocation exceeded */
83 #define EBADOP 4 /* illegal TFTP operation */
84 #define EBADID 5 /* unknown transfer ID */
85 #define EEXISTS 6 /* file already exists */
86 #define ENOUSER 7 /* no such user */
88 static const char tstr
[] = " [|tftp]";
90 /* op code to string mapping */
91 static const struct tok op2str
[] = {
92 { RRQ
, "RRQ" }, /* read request */
93 { WRQ
, "WRQ" }, /* write request */
94 { DATA
, "DATA" }, /* data packet */
95 { ACK
, "ACK" }, /* acknowledgement */
96 { TFTP_ERROR
, "ERROR" }, /* error code */
97 { OACK
, "OACK" }, /* option acknowledgement */
101 /* error code to string mapping */
102 static const struct tok err2str
[] = {
103 { EUNDEF
, "EUNDEF" }, /* not defined */
104 { ENOTFOUND
, "ENOTFOUND" }, /* file not found */
105 { EACCESS
, "EACCESS" }, /* access violation */
106 { ENOSPACE
, "ENOSPACE" }, /* disk full or allocation exceeded */
107 { EBADOP
, "EBADOP" }, /* illegal TFTP operation */
108 { EBADID
, "EBADID" }, /* unknown transfer ID */
109 { EEXISTS
, "EEXISTS" }, /* file already exists */
110 { ENOUSER
, "ENOUSER" }, /* no such user */
115 * Print trivial file transfer program requests
118 tftp_print(register const u_char
*bp
, u_int length
)
120 register const struct tftphdr
*tp
;
121 register const char *cp
;
122 register const u_char
*p
;
123 register int opcode
, i
;
125 tp
= (const struct tftphdr
*)bp
;
128 printf(" %d", length
);
130 /* Print tftp request type */
131 TCHECK(tp
->th_opcode
);
132 opcode
= EXTRACT_16BITS(&tp
->th_opcode
);
133 cp
= tok2str(op2str
, "tftp-#%d", opcode
);
135 /* Bail if bogus opcode */
144 p
= (u_char
*)tp
->th_stuff
;
146 /* Print filename or first option */
149 i
= fn_print(p
, snapend
);
153 /* Print the mode (RRQ and WRQ only) and any options */
154 while ((p
= (const u_char
*)strchr((const char *)p
, '\0')) != NULL
) {
155 if (length
<= (u_int
)(p
- (const u_char
*)&tp
->th_block
))
160 fn_print(p
, snapend
);
170 TCHECK(tp
->th_block
);
171 printf(" block %d", EXTRACT_16BITS(&tp
->th_block
));
175 /* Print error code string */
177 printf(" %s \"", tok2str(err2str
, "tftp-err-#%d \"",
178 EXTRACT_16BITS(&tp
->th_code
)));
179 /* Print error message string */
180 i
= fn_print((const u_char
*)tp
->th_data
, snapend
);
187 /* We shouldn't get here */
188 printf("(unknown #%d)", opcode
);