]>
Commit | Line | Data |
---|---|---|
1 | --- user/netflash/netflash.c | |
2 | +++ user/netflash/netflash.c | |
3 | @@ -80,6 +80,7 @@ | |
4 | #include "fileblock.h" | |
5 | #include "exit_codes.h" | |
6 | #include "versioning.h" | |
7 | +#include "netflash.h" | |
8 | ||
9 | /****************************************************************************/ | |
10 | ||
11 | @@ -969,9 +970,7 @@ int local_write(int fd, char *buf, int c | |
12 | ||
13 | /****************************************************************************/ | |
14 | ||
15 | -extern int tftpmain(int argc, char *argv[]); | |
16 | -extern int tftpsetbinary(int argc, char *argv[]); | |
17 | -extern int tftpget(int argc, char *argv[]); | |
18 | +#include "tftp.h" | |
19 | ||
20 | /* | |
21 | * Call to tftp. This will initialize tftp and do a get operation. | |
22 | --- user/netflash/netflash.h | |
23 | +++ user/netflash/netflash.h | |
24 | @@ -0,0 +1,8 @@ | |
25 | +#include <stdio.h> | |
26 | + | |
27 | +int local_creat(char *name, int flags); | |
28 | +int local_fclose(FILE *fp); | |
29 | +int local_fseek(FILE *fp, int offset, int whence); | |
30 | +int local_putc(int ch, FILE *fp); | |
31 | +int local_write(int fd, char *buf, int count); | |
32 | +FILE *local_fdopen(int fd, char *flags); | |
33 | --- user/netflash/tftp.c | |
34 | +++ user/netflash/tftp.c | |
35 | @@ -34,12 +34,22 @@ static char sccsid[] = "@(#)tftp.c 5.7 ( | |
36 | ||
37 | #include <signal.h> | |
38 | #include <stdio.h> | |
39 | +#include <stdlib.h> | |
40 | +#include <string.h> | |
41 | #include <errno.h> | |
42 | #include <setjmp.h> | |
43 | +#include <unistd.h> | |
44 | ||
45 | #include "exit_codes.h" | |
46 | +#include "netflash.h" | |
47 | +#include "tftp.h" | |
48 | ||
49 | -extern int errno; | |
50 | +static int tftpmakerequest(int request, char *name, struct tftphdr *tp, char *mode); | |
51 | +static void tftpnak(int error); | |
52 | +static void tftpstartclock(void); | |
53 | +static void tftptpacket(char *s, struct tftphdr *tp, int n); | |
54 | +static void tftpstopclock(void); | |
55 | +static void tftpprintstats(char *direction, unsigned long amount, char *join, char *name); | |
56 | ||
57 | extern struct sockaddr_in tftpsin; /* filled in by main */ | |
58 | extern int tftpf; /* the opened socket */ | |
59 | @@ -49,7 +59,6 @@ extern int tftprexmtval; | |
60 | extern int tftpmaxtimeout; | |
61 | ||
62 | extern struct tftphdr *tftpw_init(void); | |
63 | -extern FILE *local_fdopen(int fd, char *flags); | |
64 | ||
65 | #define PKTSIZE SEGSIZE+4 | |
66 | char tftpackbuf[PKTSIZE]; | |
67 | @@ -84,7 +93,7 @@ tftpsendfile(fd, name, mode) | |
68 | register int block = 0, size, n; | |
69 | register unsigned long amount = 0; | |
70 | struct sockaddr_in from; | |
71 | - int fromlen; | |
72 | + socklen_t fromlen; | |
73 | int convert; /* true if doing nl->crlf conversion */ | |
74 | FILE *file; | |
75 | ||
76 | @@ -181,6 +190,7 @@ abort: | |
77 | /* | |
78 | * Receive a file. | |
79 | */ | |
80 | +void | |
81 | tftprecvfile(fd, name, mode) | |
82 | int fd; | |
83 | char *name; | |
84 | @@ -192,7 +202,8 @@ tftprecvfile(fd, name, mode) | |
85 | u_short block = 1; | |
86 | unsigned long amount = 0; | |
87 | struct sockaddr_in from; | |
88 | - int fromlen, firsttrip = 1; | |
89 | + socklen_t fromlen; | |
90 | + int firsttrip = 1; | |
91 | FILE *file; | |
92 | int convert; /* true if converting crlf -> lf */ | |
93 | ||
94 | @@ -288,6 +299,7 @@ abort: | |
95 | tftpprintstats("Received", amount, "from", name); | |
96 | } | |
97 | ||
98 | +static int | |
99 | tftpmakerequest(request, name, tp, mode) | |
100 | int request; | |
101 | char *name, *mode; | |
102 | @@ -327,13 +339,13 @@ struct errmsg { | |
103 | * standard TFTP codes, or a UNIX errno | |
104 | * offset by 100. | |
105 | */ | |
106 | +static void | |
107 | tftpnak(error) | |
108 | int error; | |
109 | { | |
110 | register struct tftphdr *tp; | |
111 | int length; | |
112 | register struct errmsg *pe; | |
113 | -/* extern char *sys_errlist[]; */ | |
114 | ||
115 | tp = (struct tftphdr *)tftpackbuf; | |
116 | tp->th_opcode = htons((u_short)ERROR); | |
117 | @@ -345,7 +357,7 @@ tftpnak(error) | |
118 | #ifdef EMBED | |
119 | pe->e_msg = "error"; | |
120 | #else | |
121 | - pe->e_msg = sys_errlist[error - 100]; | |
122 | + pe->e_msg = strerror(error - 100); | |
123 | #endif | |
124 | tp->th_code = EUNDEF; | |
125 | } | |
126 | @@ -358,6 +370,7 @@ tftpnak(error) | |
127 | perror("nak"); | |
128 | } | |
129 | ||
130 | +static void | |
131 | tftptpacket(s, tp, n) | |
132 | char *s; | |
133 | struct tftphdr *tp; | |
134 | @@ -401,14 +414,17 @@ struct timeval tftptstart; | |
135 | struct timeval tftptstop; | |
136 | struct timezone tftpzone; | |
137 | ||
138 | +static void | |
139 | tftpstartclock() { | |
140 | gettimeofday(&tftptstart, &tftpzone); | |
141 | } | |
142 | ||
143 | +static void | |
144 | tftpstopclock() { | |
145 | gettimeofday(&tftptstop, &tftpzone); | |
146 | } | |
147 | ||
148 | +static void | |
149 | tftpprintstats(direction, amount, join, name) | |
150 | char *direction; | |
151 | unsigned long amount; | |
152 | --- user/netflash/http.c | |
153 | +++ user/netflash/http.c | |
154 | @@ -13,9 +13,11 @@ | |
155 | #include <string.h> | |
156 | #include <errno.h> | |
157 | #include <netdb.h> | |
158 | +#include <unistd.h> | |
159 | #include <sys/types.h> | |
160 | #include <sys/socket.h> | |
161 | #include <netinet/in.h> | |
162 | +#include <arpa/inet.h> | |
163 | ||
164 | /****************************************************************************/ | |
165 | ||
166 | @@ -47,7 +49,7 @@ int openhttp(char *url) | |
167 | char urlfile[256]; | |
168 | char buf[256]; | |
169 | char relocurl[512]; | |
170 | - int fd, portnr, n, relocated; | |
171 | + int fd, portnr, relocated; | |
172 | ||
173 | fd = -1; | |
174 | portnr = 80; | |
175 | --- user/netflash/tftp.h | |
176 | +++ user/netflash/tftp.h | |
177 | @@ -0,0 +1,16 @@ | |
178 | +/* TFTP prototypes */ | |
179 | + | |
180 | +#include <stdio.h> | |
181 | +#include <arpa/tftp.h> | |
182 | + | |
183 | +int tftpsynchnet(int f); | |
184 | +int tftpwriteit(FILE *file, struct tftphdr **dpp, int ct, int convert); | |
185 | +int tftpwrite_behind(FILE *file, int convert); | |
186 | +void tftprecvfile(int fd, char *name, char *mode); | |
187 | + | |
188 | +void tftpget(int argc, char *argv[]); | |
189 | +void tftpmain(int argc, char *argv[]); | |
190 | +void tftpmodecmd(int argc, char *argv[]); | |
191 | +void tftpsetascii(int argc, char *argv[]); | |
192 | +void tftpsetbinary(int argc, char *argv[]); | |
193 | +void tftpsetpeer(int argc, char *argv[]); | |
194 | --- user/netflash/Makefile | |
195 | +++ user/netflash/Makefile | |
196 | @@ -1,3 +1,4 @@ | |
197 | +CFLAGS += -Wall | |
198 | ||
199 | EXEC = netflash | |
200 | OBJS = tftpmain.o tftp.o tftpsubs.o http.o | |
201 | --- user/netflash/tftpsubs.c | |
202 | +++ user/netflash/tftpsubs.c | |
203 | @@ -37,6 +37,9 @@ static char sccsid[] = "@(#)tftpsubs.c 5 | |
204 | #include <arpa/tftp.h> | |
205 | #include <stdio.h> | |
206 | ||
207 | +#include "netflash.h" | |
208 | +#include "tftp.h" | |
209 | + | |
210 | #define PKTSIZE SEGSIZE+4 /* should be moved to tftp.h */ | |
211 | ||
212 | static struct bf { | |
213 | @@ -92,7 +95,7 @@ tftpreadit(file, dpp, convert) | |
214 | b = &bfs[current]; /* look at new buffer */ | |
215 | if (b->counter == BF_FREE) /* if it's empty */ | |
216 | read_ahead(file, convert); /* fill it */ | |
217 | -/* assert(b->counter != BF_FREE); /* check */ | |
218 | +// assert(b->counter != BF_FREE); /* check */ | |
219 | *dpp = (struct tftphdr *)b->buf; /* set caller's ptr */ | |
220 | return b->counter; | |
221 | } | |
222 | @@ -150,6 +153,7 @@ tftpread_ahead(file, convert) | |
223 | from the queue. Calls write_behind only if next buffer not | |
224 | available. | |
225 | */ | |
226 | +int | |
227 | tftpwriteit(file, dpp, ct, convert) | |
228 | FILE *file; | |
229 | struct tftphdr **dpp; | |
230 | @@ -170,6 +174,7 @@ tftpwriteit(file, dpp, ct, convert) | |
231 | * Note spec is undefined if we get CR as last byte of file or a | |
232 | * CR followed by anything else. In this case we leave it alone. | |
233 | */ | |
234 | +int | |
235 | tftpwrite_behind(file, convert) | |
236 | FILE *file; | |
237 | int convert; | |
238 | @@ -235,7 +240,7 @@ int f; /* socket to flush */ | |
239 | int i, j = 0; | |
240 | char rbuf[PKTSIZE]; | |
241 | struct sockaddr_in from; | |
242 | - int fromlen; | |
243 | + socklen_t fromlen; | |
244 | ||
245 | while (1) { | |
246 | (void) ioctl(f, FIONREAD, &i); | |
247 | --- user/netflash/tftpmain.c | |
248 | +++ user/netflash/tftpmain.c | |
249 | @@ -35,6 +35,7 @@ static char sccsid[] = "@(#)main.c 5.8 ( | |
250 | #include <sys/file.h> | |
251 | ||
252 | #include <netinet/in.h> | |
253 | +#include <arpa/inet.h> | |
254 | ||
255 | #include <signal.h> | |
256 | #include <stdlib.h> | |
257 | @@ -44,8 +45,11 @@ static char sccsid[] = "@(#)main.c 5.8 ( | |
258 | #include <string.h> | |
259 | #include <ctype.h> | |
260 | #include <netdb.h> | |
261 | +#include <unistd.h> | |
262 | ||
263 | #include "exit_codes.h" | |
264 | +#include "netflash.h" | |
265 | +#include "tftp.h" | |
266 | ||
267 | #define TIMEOUT 5 /* secs between rexmt's */ | |
268 | ||
269 | @@ -63,19 +67,24 @@ char *tftpprompt = "tftp"; | |
270 | jmp_buf tftptoplevel; | |
271 | static void tftpintr(int signo); | |
272 | #ifndef EMBED | |
273 | -struct servent *tftpsp; | |
274 | +struct servent *sp; | |
275 | #endif | |
276 | ||
277 | -int tftpquit(), tftphelp(), tftpsetverbose(), tftpsettrace(), tftpstatus(); | |
278 | -int tftpget(), tftpput(), tftpsetpeer(), tftpmodecmd(), tftpsetrexmt(), tftpsettimeout(); | |
279 | -int tftpsetbinary(), tftpsetascii(); | |
280 | +static void tftpgetusage(char *s); | |
281 | +static void tftpmakeargv(void); | |
282 | +static void tftpsetmode(char *newmode); | |
283 | +#if 0 | |
284 | +static void tftpquit(void); | |
285 | +static void tftpsettrace(void); | |
286 | +static void tftpsetverbose(void); | |
287 | +#endif | |
288 | ||
289 | #define HELPINDENT (sizeof("connect")) | |
290 | ||
291 | struct cmd { | |
292 | char *name; | |
293 | char *help; | |
294 | - int (*handler)(); | |
295 | + void (*handler)(int argc, char *argv[]); | |
296 | }; | |
297 | ||
298 | #if 0 | |
299 | @@ -115,13 +124,14 @@ struct cmd tftpcmdtab[] = { | |
300 | { "timeout", tftpihelp, tftpsettimeout }, | |
301 | { "?", tftphhelp, tftphelp }, | |
302 | #endif | |
303 | - 0 | |
304 | + { 0 } | |
305 | }; | |
306 | struct cmd *tftpgetcmd(); | |
307 | char *tftptail(); | |
308 | char *strchr(); | |
309 | char *strrchr(); | |
310 | ||
311 | +void | |
312 | tftpmain(argc, argv) | |
313 | char *argv[]; | |
314 | { | |
315 | @@ -174,6 +184,7 @@ tftpmain(argc, argv) | |
316 | ||
317 | char tftphostname[100]; | |
318 | ||
319 | +void | |
320 | tftpsetpeer(argc, argv) | |
321 | int argc; | |
322 | char *argv[]; | |
323 | @@ -237,6 +248,7 @@ struct modes { | |
324 | { 0, 0 } | |
325 | }; | |
326 | ||
327 | +void | |
328 | tftpmodecmd(argc, argv) | |
329 | char *argv[]; | |
330 | { | |
331 | @@ -270,16 +282,19 @@ tftpmodecmd(argc, argv) | |
332 | return; | |
333 | } | |
334 | ||
335 | +void | |
336 | tftpsetbinary(argc, argv) | |
337 | char *argv[]; | |
338 | { tftpsetmode("octet"); | |
339 | } | |
340 | ||
341 | +void | |
342 | tftpsetascii(argc, argv) | |
343 | char *argv[]; | |
344 | { tftpsetmode("netascii"); | |
345 | } | |
346 | ||
347 | +static void | |
348 | tftpsetmode(newmode) | |
349 | char *newmode; | |
350 | { | |
351 | @@ -384,6 +399,7 @@ tftpputusage(s) | |
352 | /* | |
353 | * Receive file(s). | |
354 | */ | |
355 | +void | |
356 | tftpget(argc, argv) | |
357 | char *argv[]; | |
358 | { | |
359 | @@ -466,6 +482,7 @@ tftpget(argc, argv) | |
360 | } | |
361 | } | |
362 | ||
363 | +static void | |
364 | tftpgetusage(s) | |
365 | char * s; | |
366 | { | |
367 | @@ -636,6 +653,7 @@ tftpgetcmd(name) | |
368 | /* | |
369 | * Slice a string up into argc/argv. | |
370 | */ | |
371 | +static void | |
372 | tftpmakeargv() | |
373 | { | |
374 | register char *cp; | |
375 | @@ -658,13 +676,14 @@ tftpmakeargv() | |
376 | *argp++ = 0; | |
377 | } | |
378 | ||
379 | +#if 0 | |
380 | /*VARARGS*/ | |
381 | +static void | |
382 | tftpquit() | |
383 | { | |
384 | exit(0); | |
385 | } | |
386 | ||
387 | -#if 0 | |
388 | /* | |
389 | * Help command. | |
390 | */ | |
391 | @@ -694,7 +713,9 @@ tftphelp(argc, argv) | |
392 | } | |
393 | #endif | |
394 | ||
395 | +#if 0 | |
396 | /*VARARGS*/ | |
397 | +void | |
398 | tftpsettrace() | |
399 | { | |
400 | tftptrace = !tftptrace; | |
401 | @@ -702,8 +723,10 @@ tftpsettrace() | |
402 | } | |
403 | ||
404 | /*VARARGS*/ | |
405 | +void | |
406 | tftpsetverbose() | |
407 | { | |
408 | tftpverbose = !tftpverbose; | |
409 | printf("Verbose mode %s.\n", tftpverbose ? "on" : "off"); | |
410 | } | |
411 | +#endif |