1 --- user/netflash/netflash.c
2 +++ user/netflash/netflash.c
5 #include "exit_codes.h"
6 #include "versioning.h"
9 /****************************************************************************/
11 @@ -969,9 +970,7 @@ int local_write(int fd, char *buf, int c
13 /****************************************************************************/
15 -extern int tftpmain(int argc, char *argv[]);
16 -extern int tftpsetbinary(int argc, char *argv[]);
17 -extern int tftpget(int argc, char *argv[]);
21 * Call to tftp. This will initialize tftp and do a get operation.
22 --- user/netflash/netflash.h
23 +++ user/netflash/netflash.h
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 (
45 #include "exit_codes.h"
46 +#include "netflash.h"
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);
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;
62 extern struct tftphdr *tftpw_init(void);
63 -extern FILE *local_fdopen(int fd, char *flags);
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;
73 int convert; /* true if doing nl->crlf conversion */
76 @@ -181,6 +190,7 @@ abort:
81 tftprecvfile(fd, name, mode)
84 @@ -192,7 +202,8 @@ tftprecvfile(fd, name, mode)
86 unsigned long amount = 0;
87 struct sockaddr_in from;
88 - int fromlen, firsttrip = 1;
92 int convert; /* true if converting crlf -> lf */
94 @@ -288,6 +299,7 @@ abort:
95 tftpprintstats("Received", amount, "from", name);
99 tftpmakerequest(request, name, tp, mode)
102 @@ -327,13 +339,13 @@ struct errmsg {
103 * standard TFTP codes, or a UNIX errno
110 register struct tftphdr *tp;
112 register struct errmsg *pe;
113 -/* extern char *sys_errlist[]; */
115 tp = (struct tftphdr *)tftpackbuf;
116 tp->th_opcode = htons((u_short)ERROR);
117 @@ -345,7 +357,7 @@ tftpnak(error)
121 - pe->e_msg = sys_errlist[error - 100];
122 + pe->e_msg = strerror(error - 100);
124 tp->th_code = EUNDEF;
126 @@ -358,6 +370,7 @@ tftpnak(error)
131 tftptpacket(s, tp, n)
134 @@ -401,14 +414,17 @@ struct timeval tftptstart;
135 struct timeval tftptstop;
136 struct timezone tftpzone;
140 gettimeofday(&tftptstart, &tftpzone);
145 gettimeofday(&tftptstop, &tftpzone);
149 tftpprintstats(direction, amount, join, name)
151 unsigned long amount;
152 --- user/netflash/http.c
153 +++ user/netflash/http.c
159 #include <sys/types.h>
160 #include <sys/socket.h>
161 #include <netinet/in.h>
162 +#include <arpa/inet.h>
164 /****************************************************************************/
166 @@ -47,7 +49,7 @@ int openhttp(char *url)
170 - int fd, portnr, n, relocated;
171 + int fd, portnr, relocated;
175 --- user/netflash/tftp.h
176 +++ user/netflash/tftp.h
178 +/* TFTP prototypes */
181 +#include <arpa/tftp.h>
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);
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
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>
207 +#include "netflash.h"
210 #define PKTSIZE SEGSIZE+4 /* should be moved to tftp.h */
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 */
222 @@ -150,6 +153,7 @@ tftpread_ahead(file, convert)
223 from the queue. Calls write_behind only if next buffer not
227 tftpwriteit(file, dpp, ct, convert)
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.
235 tftpwrite_behind(file, convert)
238 @@ -235,7 +240,7 @@ int f; /* socket to flush */
241 struct sockaddr_in from;
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>
252 #include <netinet/in.h>
253 +#include <arpa/inet.h>
257 @@ -44,8 +45,11 @@ static char sccsid[] = "@(#)main.c 5.8 (
263 #include "exit_codes.h"
264 +#include "netflash.h"
267 #define TIMEOUT 5 /* secs between rexmt's */
269 @@ -63,19 +67,24 @@ char *tftpprompt = "tftp";
270 jmp_buf tftptoplevel;
271 static void tftpintr(int signo);
273 -struct servent *tftpsp;
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);
284 +static void tftpquit(void);
285 +static void tftpsettrace(void);
286 +static void tftpsetverbose(void);
289 #define HELPINDENT (sizeof("connect"))
295 + void (*handler)(int argc, char *argv[]);
299 @@ -115,13 +124,14 @@ struct cmd tftpcmdtab[] = {
300 { "timeout", tftpihelp, tftpsettimeout },
301 { "?", tftphhelp, tftphelp },
306 struct cmd *tftpgetcmd();
315 @@ -174,6 +184,7 @@ tftpmain(argc, argv)
317 char tftphostname[100];
320 tftpsetpeer(argc, argv)
323 @@ -237,6 +248,7 @@ struct modes {
328 tftpmodecmd(argc, argv)
331 @@ -270,16 +282,19 @@ tftpmodecmd(argc, argv)
336 tftpsetbinary(argc, argv)
338 { tftpsetmode("octet");
342 tftpsetascii(argc, argv)
344 { tftpsetmode("netascii");
351 @@ -384,6 +399,7 @@ tftpputusage(s)
359 @@ -466,6 +482,7 @@ tftpget(argc, argv)
367 @@ -636,6 +653,7 @@ tftpgetcmd(name)
369 * Slice a string up into argc/argv.
375 @@ -658,13 +676,14 @@ tftpmakeargv()
391 @@ -694,7 +713,9 @@ tftphelp(argc, argv)
400 tftptrace = !tftptrace;
401 @@ -702,8 +723,10 @@ tftpsettrace()
408 tftpverbose = !tftpverbose;
409 printf("Verbose mode %s.\n", tftpverbose ? "on" : "off");