]>
git.saurik.com Git - apple/network_cmds.git/blob - tcpdump.tproj/print-tftp.c
9db577548338064bfa25aa8792a139180fd921ac
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that: (1) source code distributions
30 * retain the above copyright notice and this paragraph in its entirety, (2)
31 * distributions including binary code include the above copyright notice and
32 * this paragraph in its entirety in the documentation or other materials
33 * provided with the distribution, and (3) all advertising materials mentioning
34 * features or use of this software display the following acknowledgement:
35 * ``This product includes software developed by the University of California,
36 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
37 * the University nor the names of its contributors may be used to endorse
38 * or promote products derived from this software without specific prior
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
44 * Format and print trivial file transfer protocol packets.
48 static const char rcsid
[] =
49 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-tftp.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)";
52 #include <sys/param.h>
55 #include <netinet/in.h>
57 #include <arpa/tftp.h>
63 #include "interface.h"
64 #include "addrtoname.h"
66 /* op code to string mapping */
67 static struct tok op2str
[] = {
68 { RRQ
, "RRQ" }, /* read request */
69 { WRQ
, "WRQ" }, /* write request */
70 { DATA
, "DATA" }, /* data packet */
71 { ACK
, "ACK" }, /* acknowledgement */
72 { ERROR
, "ERROR" }, /* error code */
76 /* error code to string mapping */
77 static struct tok err2str
[] = {
78 { EUNDEF
, "EUNDEF" }, /* not defined */
79 { ENOTFOUND
, "ENOTFOUND" }, /* file not found */
80 { EACCESS
, "EACCESS" }, /* access violation */
81 { ENOSPACE
, "ENOSPACE" }, /* disk full or allocation exceeded */
82 { EBADOP
, "EBADOP" }, /* illegal TFTP operation */
83 { EBADID
, "EBADID" }, /* unknown transfer ID */
84 { EEXISTS
, "EEXISTS" }, /* file already exists */
85 { ENOUSER
, "ENOUSER" }, /* no such user */
90 * Print trivial file transfer program requests
93 tftp_print(register const u_char
*bp
, u_int length
)
95 register const struct tftphdr
*tp
;
96 register const char *cp
;
97 register const u_char
*p
;
98 register int opcode
, i
;
99 static char tstr
[] = " [|tftp]";
101 tp
= (const struct tftphdr
*)bp
;
104 printf(" %d", length
);
106 /* Print tftp request type */
107 TCHECK(tp
->th_opcode
);
108 opcode
= ntohs(tp
->th_opcode
);
109 cp
= tok2str(op2str
, "tftp-#%d", opcode
);
111 /* Bail if bogus opcode */
120 * XXX Not all arpa/tftp.h's specify th_stuff as any
121 * array; use address of th_block instead
124 p
= (u_char
*)tp
->th_stuff
;
126 p
= (u_char
*)&tp
->th_block
;
128 fputs(" \"", stdout
);
129 i
= fn_print(p
, snapend
);
137 TCHECK(tp
->th_block
);
138 printf(" block %d", ntohs(tp
->th_block
));
142 /* Print error code string */
144 printf(" %s ", tok2str(err2str
, "tftp-err-#%d \"",
145 ntohs(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
);