4 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * Format and print trivial file transfer protocol packets.
26 #include <sys/cdefs.h>
29 static const char rcsid
[] _U_
=
30 "@(#) Header: /tcpdump/master/tcpdump/print-tftp.c,v 1.37 2003/11/16 09:36:40 guy Exp (LBL)";
32 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
40 #include <tcpdump-stdinc.h>
43 #undef SEGSIZE /* SINIX sucks */
45 #include <arpa/tftp.h>
50 #include "interface.h"
51 #include "addrtoname.h"
54 /* op code to string mapping */
55 static struct tok op2str
[] = {
56 { RRQ
, "RRQ" }, /* read request */
57 { WRQ
, "WRQ" }, /* write request */
58 { DATA
, "DATA" }, /* data packet */
59 { ACK
, "ACK" }, /* acknowledgement */
60 { ERROR
, "ERROR" }, /* error code */
64 /* error code to string mapping */
65 static struct tok err2str
[] = {
66 { EUNDEF
, "EUNDEF" }, /* not defined */
67 { ENOTFOUND
, "ENOTFOUND" }, /* file not found */
68 { EACCESS
, "EACCESS" }, /* access violation */
69 { ENOSPACE
, "ENOSPACE" }, /* disk full or allocation exceeded */
70 { EBADOP
, "EBADOP" }, /* illegal TFTP operation */
71 { EBADID
, "EBADID" }, /* unknown transfer ID */
72 { EEXISTS
, "EEXISTS" }, /* file already exists */
73 { ENOUSER
, "ENOUSER" }, /* no such user */
78 * Print trivial file transfer program requests
81 tftp_print(register const u_char
*bp
, u_int length
)
83 register const struct tftphdr
*tp
;
84 register const char *cp
;
85 register const u_char
*p
;
86 register int opcode
, i
;
87 static char tstr
[] = " [|tftp]";
89 tp
= (const struct tftphdr
*)bp
;
92 printf(" %d", length
);
94 /* Print tftp request type */
95 TCHECK(tp
->th_opcode
);
96 opcode
= EXTRACT_16BITS(&tp
->th_opcode
);
97 cp
= tok2str(op2str
, "tftp-#%d", opcode
);
99 /* Bail if bogus opcode */
108 * XXX Not all arpa/tftp.h's specify th_stuff as any
109 * array; use address of th_block instead
112 p
= (u_char
*)tp
->th_stuff
;
114 p
= (u_char
*)&tp
->th_block
;
116 fputs(" \"", stdout
);
117 i
= fn_print(p
, snapend
);
120 /* Print the mode and any options */
121 while ((p
= (const u_char
*)strchr((const char *)p
, '\0')) != NULL
) {
122 if (length
<= (u_int
)(p
- (const u_char
*)&tp
->th_block
))
127 fn_print(p
, snapend
);
137 TCHECK(tp
->th_block
);
138 printf(" block %d", EXTRACT_16BITS(&tp
->th_block
));
142 /* Print error code string */
144 printf(" %s ", tok2str(err2str
, "tftp-err-#%d \"",
145 EXTRACT_16BITS(&tp
->th_code
)));
146 /* Print error message string */
147 i
= fn_print((const u_char
*)tp
->th_data
, snapend
);
154 /* We shouldn't get here */
155 printf("(unknown #%d)", opcode
);