4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <arpa/tftp.h>
33 extern char *dlc_header
;
38 interpret_tftp(int flags
, struct tftphdr
*tftp
, int fraglen
)
41 extern int src_port
, dst_port
;
42 int blocksize
= fraglen
- 4;
44 switch (ntohs(tftp
->th_opcode
)) {
47 add_transient(src_port
, interpret_tftp
);
50 del_transient(src_port
);
55 switch (ntohs(tftp
->th_opcode
)) {
57 name
= (char *)&tftp
->th_stuff
;
58 mode
= name
+ (strlen(name
) + 1);
59 (void) sprintf(get_sum_line(),
60 "TFTP Read \"%s\" (%s)", name
, mode
);
63 name
= (char *)&tftp
->th_stuff
;
64 mode
= name
+ (strlen(name
) + 1);
65 (void) sprintf(get_sum_line(),
66 "TFTP Write \"%s\" (%s)", name
, mode
);
69 (void) sprintf(get_sum_line(),
70 "TFTP Data block %d (%d bytes)%s",
71 ntohs(tftp
->th_block
),
73 blocksize
< 512 ? " (last block)":"");
76 (void) sprintf(get_sum_line(),
78 ntohs(tftp
->th_block
));
81 (void) sprintf(get_sum_line(),
83 tftperror(ntohs(tftp
->th_code
)));
88 if (flags
& F_DTAIL
) {
90 show_header("TFTP: ", "Trivial File Transfer Protocol", fraglen
);
92 (void) sprintf(get_line((char *)(uintptr_t)tftp
->th_opcode
-
95 ntohs(tftp
->th_opcode
),
96 show_type(ntohs(tftp
->th_opcode
)));
98 switch (ntohs(tftp
->th_opcode
)) {
101 name
= (char *)&tftp
->th_stuff
;
102 mode
= name
+ (strlen(name
) + 1);
104 get_line(name
- dlc_header
, strlen(name
) + 1),
105 "File name = \"%s\"",
108 get_line(mode
- dlc_header
, strlen(mode
) + 1),
109 "Transfer mode = %s",
115 get_line((char *)(uintptr_t)tftp
->th_block
-
116 dlc_header
, 2), "Data block = %d%s",
117 ntohs(tftp
->th_block
),
118 blocksize
< 512 ? " (last block)":"");
119 (void) sprintf(get_line((char *)(uintptr_t)tftp
->th_data
-
120 dlc_header
, blocksize
),
121 "[ %d bytes of data ]",
126 (void) sprintf(get_line((char *)(uintptr_t)tftp
->th_block
-
127 dlc_header
, 2), "Acknowledge block = %d",
128 ntohs(tftp
->th_block
));
132 (void) sprintf(get_line((char *)(uintptr_t)tftp
->th_code
-
133 dlc_header
, 2), "Error = %d (%s)",
134 ntohs(tftp
->th_code
),
135 tftperror(ntohs(tftp
->th_code
)));
136 (void) sprintf(get_line((char *)(uintptr_t)tftp
->th_data
-
137 dlc_header
, strlen(tftp
->th_data
) + 1),
138 "Error string = \"%s\"", tftp
->th_data
);
150 case RRQ
: return ("read request");
151 case WRQ
: return ("write request");
152 case DATA
: return ("data packet");
153 case ACK
: return ("acknowledgement");
154 case ERROR
: return ("error");
163 static char buf
[128];
166 case EUNDEF
: return ("not defined");
167 case ENOTFOUND
: return ("file not found");
168 case EACCESS
: return ("access violation");
169 case ENOSPACE
: return ("disk full or allocation exceeded");
170 case EBADOP
: return ("illegal TFTP operation");
171 case EBADID
: return ("unknown transfer ID");
172 case EEXISTS
: return ("file already exists");
173 case ENOUSER
: return ("no such user");
175 (void) sprintf(buf
, "%d", code
);