]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - stand/libsa/tftp.c
libsa: memory leak in tftp_open()
[FreeBSD/FreeBSD.git] / stand / libsa / tftp.c
1 /*      $NetBSD: tftp.c,v 1.4 1997/09/17 16:57:07 drochner Exp $         */
2
3 /*
4  * Copyright (c) 1996
5  *      Matthias Drochner.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed for the NetBSD Project
18  *      by Matthias Drochner.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
36
37 /*
38  * Simple TFTP implementation for libsa.
39  * Assumes:
40  *  - socket descriptor (int) at open_file->f_devdata
41  *  - server host IP in global servip
42  * Restrictions:
43  *  - read only
44  *  - lseek only with SEEK_SET or SEEK_CUR
45  *  - no big time differences between transfers (<tftp timeout)
46  */
47
48 #include <sys/types.h>
49 #include <sys/stat.h>
50 #include <netinet/in.h>
51 #include <netinet/udp.h>
52 #include <netinet/in_systm.h>
53 #include <arpa/tftp.h>
54
55 #include <string.h>
56
57 #include "stand.h"
58 #include "net.h"
59 #include "netif.h"
60
61 #include "tftp.h"
62
63 struct tftp_handle;
64 struct tftprecv_extra;
65
66 static ssize_t recvtftp(struct iodesc *d, void **pkt, void **payload,
67     time_t tleft, void *recv_extra);
68 static int      tftp_open(const char *path, struct open_file *f);
69 static int      tftp_close(struct open_file *f);
70 static int      tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len);
71 static int      tftp_read(struct open_file *f, void *buf, size_t size, size_t *resid);
72 static off_t    tftp_seek(struct open_file *f, off_t offset, int where);
73 static int      tftp_set_blksize(struct tftp_handle *h, const char *str);
74 static int      tftp_stat(struct open_file *f, struct stat *sb);
75
76 struct fs_ops tftp_fsops = {
77         "tftp",
78         tftp_open,
79         tftp_close,
80         tftp_read,
81         null_write,
82         tftp_seek,
83         tftp_stat,
84         null_readdir
85 };
86
87 extern struct in_addr servip;
88
89 static int      tftpport = 2000;
90 static int      is_open = 0;
91
92 /*
93  * The legacy TFTP_BLKSIZE value was SEGSIZE(512).
94  * TFTP_REQUESTED_BLKSIZE of 1428 is (Ethernet MTU, less the TFTP, UDP and
95  * IP header lengths).
96  */
97 #define TFTP_REQUESTED_BLKSIZE 1428
98
99 /*
100  * Choose a blksize big enough so we can test with Ethernet
101  * Jumbo frames in the future.
102  */
103 #define TFTP_MAX_BLKSIZE 9008
104
105 struct tftp_handle {
106         struct iodesc  *iodesc;
107         int             currblock;      /* contents of lastdata */
108         int             islastblock;    /* flag */
109         int             validsize;
110         int             off;
111         char           *path;   /* saved for re-requests */
112         unsigned int    tftp_blksize;
113         unsigned long   tftp_tsize;
114         void            *pkt;
115         struct tftphdr  *tftp_hdr;
116 };
117
118 struct tftprecv_extra {
119         struct tftp_handle      *tftp_handle;
120         unsigned short           rtype;         /* Received type */
121 };
122
123 #define TFTP_MAX_ERRCODE EOPTNEG
124 static const int tftperrors[TFTP_MAX_ERRCODE + 1] = {
125         0,                      /* ??? */
126         ENOENT,
127         EPERM,
128         ENOSPC,
129         EINVAL,                 /* ??? */
130         EINVAL,                 /* ??? */
131         EEXIST,
132         EINVAL,                 /* ??? */
133         EINVAL,                 /* Option negotiation failed. */
134 };
135
136 static int  tftp_getnextblock(struct tftp_handle *h);
137
138 /* send error message back. */
139 static void
140 tftp_senderr(struct tftp_handle *h, u_short errcode, const char *msg)
141 {
142         struct {
143                 u_char header[HEADER_SIZE];
144                 struct tftphdr  t;
145                 u_char space[63]; /* +1 from t */
146         } __packed __aligned(4) wbuf;
147         char           *wtail;
148         int             len;
149
150         len = strlen(msg);
151         if (len > sizeof(wbuf.space))
152                 len = sizeof(wbuf.space);
153
154         wbuf.t.th_opcode = htons((u_short) ERROR);
155         wbuf.t.th_code   = htons(errcode);
156
157         wtail = wbuf.t.th_msg;
158         bcopy(msg, wtail, len);
159         wtail[len] = '\0';
160         wtail += len + 1;
161
162         sendudp(h->iodesc, &wbuf.t, wtail - (char *) &wbuf.t);
163 }
164
165 static void
166 tftp_sendack(struct tftp_handle *h)
167 {
168         struct {
169                 u_char header[HEADER_SIZE];
170                 struct tftphdr  t;
171         } __packed __aligned(4) wbuf;
172         char           *wtail;
173
174         wbuf.t.th_opcode = htons((u_short) ACK);
175         wtail = (char *) &wbuf.t.th_block;
176         wbuf.t.th_block = htons((u_short) h->currblock);
177         wtail += 2;
178
179         sendudp(h->iodesc, &wbuf.t, wtail - (char *) &wbuf.t);
180 }
181
182 static ssize_t
183 recvtftp(struct iodesc *d, void **pkt, void **payload, time_t tleft,
184     void *recv_extra)
185 {
186         struct tftprecv_extra *extra;
187         struct tftp_handle *h;
188         struct tftphdr *t;
189         void *ptr = NULL;
190         ssize_t len;
191
192         errno = 0;
193         extra = (struct tftprecv_extra *)recv_extra;
194         h = extra->tftp_handle;
195
196         len = readudp(d, &ptr, (void **)&t, tleft);
197
198         if (len < 4) {
199                 free(ptr);
200                 return (-1);
201         }
202
203         extra->rtype = ntohs(t->th_opcode);
204         switch (ntohs(t->th_opcode)) {
205         case DATA: {
206                 int got;
207
208                 if (htons(t->th_block) != (u_short) d->xid) {
209                         /*
210                          * Expected block?
211                          */
212                         free(ptr);
213                         return (-1);
214                 }
215                 if (d->xid == 1) {
216                         /*
217                          * First data packet from new port.
218                          */
219                         struct udphdr *uh;
220                         uh = (struct udphdr *) t - 1;
221                         d->destport = uh->uh_sport;
222                 } /* else check uh_sport has not changed??? */
223                 got = len - (t->th_data - (char *)t);
224                 *pkt = ptr;
225                 *payload = t;
226                 return (got);
227         }
228         case ERROR:
229                 if ((unsigned) ntohs(t->th_code) > TFTP_MAX_ERRCODE) {
230                         printf("illegal tftp error %d\n", ntohs(t->th_code));
231                         errno = EIO;
232                 } else {
233 #ifdef TFTP_DEBUG
234                         printf("tftp-error %d\n", ntohs(t->th_code));
235 #endif
236                         errno = tftperrors[ntohs(t->th_code)];
237                 }
238                 free(ptr);
239                 return (-1);
240         case OACK: {
241                 struct udphdr *uh;
242                 int tftp_oack_len;
243
244                 /* 
245                  * Unexpected OACK. TFTP transfer already in progress. 
246                  * Drop the pkt.
247                  */
248                 if (d->xid != 1) {
249                         free(ptr);
250                         return (-1);
251                 }
252
253                 /*
254                  * Remember which port this OACK came from, because we need
255                  * to send the ACK or errors back to it.
256                  */
257                 uh = (struct udphdr *) t - 1;
258                 d->destport = uh->uh_sport;
259                 
260                 /* Parse options ACK-ed by the server. */
261                 tftp_oack_len = len - sizeof(t->th_opcode);
262                 if (tftp_parse_oack(h, t->th_u.tu_stuff, tftp_oack_len) != 0) {
263                         tftp_senderr(h, EOPTNEG, "Malformed OACK");
264                         errno = EIO;
265                         free(ptr);
266                         return (-1);
267                 }
268                 *pkt = ptr;
269                 *payload = t;
270                 return (0);
271         }
272         default:
273 #ifdef TFTP_DEBUG
274                 printf("tftp type %d not handled\n", ntohs(t->th_opcode));
275 #endif
276                 free(ptr);
277                 return (-1);
278         }
279 }
280
281 /* send request, expect first block (or error) */
282 static int
283 tftp_makereq(struct tftp_handle *h)
284 {
285         struct {
286                 u_char header[HEADER_SIZE];
287                 struct tftphdr  t;
288                 u_char space[FNAME_SIZE + 6];
289         } __packed __aligned(4) wbuf;
290         struct tftprecv_extra recv_extra;
291         char           *wtail;
292         int             l;
293         ssize_t         res;
294         void *pkt;
295         struct tftphdr *t;
296         char *tftp_blksize = NULL;
297         int blksize_l;
298
299         /*
300          * Allow overriding default TFTP block size by setting
301          * a tftp.blksize environment variable.
302          */
303         if ((tftp_blksize = getenv("tftp.blksize")) != NULL) {
304                 tftp_set_blksize(h, tftp_blksize);
305         }
306
307         wbuf.t.th_opcode = htons((u_short) RRQ);
308         wtail = wbuf.t.th_stuff;
309         l = strlen(h->path);
310 #ifdef TFTP_PREPEND_PATH
311         if (l > FNAME_SIZE - (sizeof(TFTP_PREPEND_PATH) - 1))
312                 return (ENAMETOOLONG);
313         bcopy(TFTP_PREPEND_PATH, wtail, sizeof(TFTP_PREPEND_PATH) - 1);
314         wtail += sizeof(TFTP_PREPEND_PATH) - 1;
315 #else
316         if (l > FNAME_SIZE)
317                 return (ENAMETOOLONG);
318 #endif
319         bcopy(h->path, wtail, l + 1);
320         wtail += l + 1;
321         bcopy("octet", wtail, 6);
322         wtail += 6;
323         bcopy("blksize", wtail, 8);
324         wtail += 8;
325         blksize_l = sprintf(wtail, "%d", h->tftp_blksize);
326         wtail += blksize_l + 1;
327         bcopy("tsize", wtail, 6);
328         wtail += 6;
329         bcopy("0", wtail, 2);
330         wtail += 2;
331
332         /* h->iodesc->myport = htons(--tftpport); */
333         h->iodesc->myport = htons(tftpport + (getsecs() & 0x3ff));
334         h->iodesc->destport = htons(IPPORT_TFTP);
335         h->iodesc->xid = 1;     /* expected block */
336
337         h->currblock = 0;
338         h->islastblock = 0;
339         h->validsize = 0;
340
341         pkt = NULL;
342         recv_extra.tftp_handle = h;
343         res = sendrecv(h->iodesc, &sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
344                        (void *)&recvtftp, &pkt, (void **)&t, &recv_extra);
345         if (res == -1) {
346                 free(pkt);
347                 return (errno);
348         }
349
350         free(h->pkt);
351         h->pkt = pkt;
352         h->tftp_hdr = t;
353
354         if (recv_extra.rtype == OACK)
355                 return (tftp_getnextblock(h));
356
357         /* Server ignored our blksize request, revert to TFTP default. */
358         h->tftp_blksize = SEGSIZE;
359
360         switch (recv_extra.rtype) {
361                 case DATA: {
362                         h->currblock = 1;
363                         h->validsize = res;
364                         h->islastblock = 0;
365                         if (res < h->tftp_blksize) {
366                                 h->islastblock = 1;     /* very short file */
367                                 tftp_sendack(h);
368                         }
369                         return (0);
370                 }
371                 case ERROR:
372                 default:
373                         return (errno);
374         }
375
376 }
377
378 /* ack block, expect next */
379 static int 
380 tftp_getnextblock(struct tftp_handle *h)
381 {
382         struct {
383                 u_char header[HEADER_SIZE];
384                 struct tftphdr t;
385         } __packed __aligned(4) wbuf;
386         struct tftprecv_extra recv_extra;
387         char           *wtail;
388         int             res;
389         void *pkt;
390         struct tftphdr *t;
391         wbuf.t.th_opcode = htons((u_short) ACK);
392         wtail = (char *) &wbuf.t.th_block;
393         wbuf.t.th_block = htons((u_short) h->currblock);
394         wtail += 2;
395
396         h->iodesc->xid = h->currblock + 1;      /* expected block */
397
398         pkt = NULL;
399         recv_extra.tftp_handle = h;
400         res = sendrecv(h->iodesc, &sendudp, &wbuf.t, wtail - (char *) &wbuf.t,
401                        (void *)&recvtftp, &pkt, (void **)&t, &recv_extra);
402
403         if (res == -1) {                /* 0 is OK! */
404                 free(pkt);
405                 return (errno);
406         }
407
408         free(h->pkt);
409         h->pkt = pkt;
410         h->tftp_hdr = t;
411         h->currblock++;
412         h->validsize = res;
413         if (res < h->tftp_blksize)
414                 h->islastblock = 1;     /* EOF */
415
416         if (h->islastblock == 1) {
417                 /* Send an ACK for the last block */ 
418                 wbuf.t.th_block = htons((u_short) h->currblock);
419                 sendudp(h->iodesc, &wbuf.t, wtail - (char *)&wbuf.t);
420         }
421
422         return (0);
423 }
424
425 static int
426 tftp_open(const char *path, struct open_file *f)
427 {
428         struct tftp_handle *tftpfile;
429         struct iodesc  *io;
430         int             res;
431         size_t          pathsize;
432         const char     *extraslash;
433
434         if (netproto != NET_TFTP)
435                 return (EINVAL);
436
437         if (f->f_dev->dv_type != DEVT_NET)
438                 return (EINVAL);
439
440         if (is_open)
441                 return (EBUSY);
442
443         tftpfile = (struct tftp_handle *) malloc(sizeof(*tftpfile));
444         if (!tftpfile)
445                 return (ENOMEM);
446
447         memset(tftpfile, 0, sizeof(*tftpfile));
448         tftpfile->tftp_blksize = TFTP_REQUESTED_BLKSIZE;
449         tftpfile->iodesc = io = socktodesc(*(int *) (f->f_devdata));
450         if (io == NULL) {
451                 free(tftpfile);
452                 return (EINVAL);
453         }
454
455         io->destip = servip;
456         tftpfile->off = 0;
457         pathsize = (strlen(rootpath) + 1 + strlen(path) + 1) * sizeof(char);
458         tftpfile->path = malloc(pathsize);
459         if (tftpfile->path == NULL) {
460                 free(tftpfile);
461                 return(ENOMEM);
462         }
463         if (rootpath[strlen(rootpath) - 1] == '/' || path[0] == '/')
464                 extraslash = "";
465         else
466                 extraslash = "/";
467         res = snprintf(tftpfile->path, pathsize, "%s%s%s",
468             rootpath, extraslash, path);
469         if (res < 0 || res > pathsize) {
470                 free(tftpfile->path);
471                 free(tftpfile);
472                 return(ENOMEM);
473         }
474
475         res = tftp_makereq(tftpfile);
476
477         if (res) {
478                 free(tftpfile->path);
479                 free(tftpfile->pkt);
480                 free(tftpfile);
481                 return (res);
482         }
483         f->f_fsdata = (void *) tftpfile;
484         is_open = 1;
485         return (0);
486 }
487
488 static int
489 tftp_read(struct open_file *f, void *addr, size_t size,
490     size_t *resid /* out */)
491 {
492         struct tftp_handle *tftpfile;
493         tftpfile = (struct tftp_handle *) f->f_fsdata;
494
495         while (size > 0) {
496                 int needblock, count;
497
498                 twiddle(32);
499
500                 needblock = tftpfile->off / tftpfile->tftp_blksize + 1;
501
502                 if (tftpfile->currblock > needblock) {  /* seek backwards */
503                         tftp_senderr(tftpfile, 0, "No error: read aborted");
504                         tftp_makereq(tftpfile); /* no error check, it worked
505                                                  * for open */
506                 }
507
508                 while (tftpfile->currblock < needblock) {
509                         int res;
510
511                         res = tftp_getnextblock(tftpfile);
512                         if (res) {      /* no answer */
513 #ifdef TFTP_DEBUG
514                                 printf("tftp: read error\n");
515 #endif
516                                 return (res);
517                         }
518                         if (tftpfile->islastblock)
519                                 break;
520                 }
521
522                 if (tftpfile->currblock == needblock) {
523                         int offinblock, inbuffer;
524
525                         offinblock = tftpfile->off % tftpfile->tftp_blksize;
526
527                         inbuffer = tftpfile->validsize - offinblock;
528                         if (inbuffer < 0) {
529 #ifdef TFTP_DEBUG
530                                 printf("tftp: invalid offset %d\n",
531                                     tftpfile->off);
532 #endif
533                                 return (EINVAL);
534                         }
535                         count = (size < inbuffer ? size : inbuffer);
536                         bcopy(tftpfile->tftp_hdr->th_data + offinblock,
537                             addr, count);
538
539                         addr = (char *)addr + count;
540                         tftpfile->off += count;
541                         size -= count;
542
543                         if ((tftpfile->islastblock) && (count == inbuffer))
544                                 break;  /* EOF */
545                 } else {
546 #ifdef TFTP_DEBUG
547                         printf("tftp: block %d not found\n", needblock);
548 #endif
549                         return (EINVAL);
550                 }
551
552         }
553
554         if (resid)
555                 *resid = size;
556         return (0);
557 }
558
559 static int 
560 tftp_close(struct open_file *f)
561 {
562         struct tftp_handle *tftpfile;
563         tftpfile = (struct tftp_handle *) f->f_fsdata;
564
565         /* let it time out ... */
566
567         if (tftpfile) {
568                 free(tftpfile->path);
569                 free(tftpfile->pkt);
570                 free(tftpfile);
571         }
572         is_open = 0;
573         return (0);
574 }
575
576 static int 
577 tftp_stat(struct open_file *f, struct stat *sb)
578 {
579         struct tftp_handle *tftpfile;
580         tftpfile = (struct tftp_handle *) f->f_fsdata;
581
582         sb->st_mode = 0444 | S_IFREG;
583         sb->st_nlink = 1;
584         sb->st_uid = 0;
585         sb->st_gid = 0;
586         sb->st_size = (off_t) tftpfile->tftp_tsize;
587         return (0);
588 }
589
590 static off_t
591 tftp_seek(struct open_file *f, off_t offset, int where)
592 {
593         struct tftp_handle *tftpfile;
594         tftpfile = (struct tftp_handle *) f->f_fsdata;
595
596         switch (where) {
597         case SEEK_SET:
598                 tftpfile->off = offset;
599                 break;
600         case SEEK_CUR:
601                 tftpfile->off += offset;
602                 break;
603         default:
604                 errno = EOFFSET;
605                 return (-1);
606         }
607         return (tftpfile->off);
608 }
609
610 static int
611 tftp_set_blksize(struct tftp_handle *h, const char *str)
612 {
613         char *endptr;
614         int new_blksize;
615         int ret = 0;
616
617         if (h == NULL || str == NULL)
618                 return (ret);
619
620         new_blksize =
621             (unsigned int)strtol(str, &endptr, 0);
622
623         /*
624          * Only accept blksize value if it is numeric.
625          * RFC2348 specifies that acceptable values are 8-65464.
626          * Let's choose a limit less than MAXRSPACE.
627          */
628         if (*endptr == '\0' && new_blksize >= 8
629             && new_blksize <= TFTP_MAX_BLKSIZE) {
630                 h->tftp_blksize = new_blksize;
631                 ret = 1;
632         }
633
634         return (ret);
635 }
636
637 /*
638  * In RFC2347, the TFTP Option Acknowledgement package (OACK)
639  * is used to acknowledge a client's option negotiation request.
640  * The format of an OACK packet is:
641  *    +-------+---~~---+---+---~~---+---+---~~---+---+---~~---+---+
642  *    |  opc  |  opt1  | 0 | value1 | 0 |  optN  | 0 | valueN | 0 |
643  *    +-------+---~~---+---+---~~---+---+---~~---+---+---~~---+---+
644  *
645  *    opc
646  *       The opcode field contains a 6, for Option Acknowledgment.
647  *
648  *    opt1
649  *       The first option acknowledgment, copied from the original
650  *       request.
651  *
652  *    value1
653  *       The acknowledged value associated with the first option.  If
654  *       and how this value may differ from the original request is
655  *       detailed in the specification for the option.
656  *
657  *    optN, valueN
658  *       The final option/value acknowledgment pair.
659  */
660 static int 
661 tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len)
662 {
663         /* 
664          *  We parse the OACK strings into an array
665          *  of name-value pairs.
666          */
667         char *tftp_options[128] = { 0 };
668         char *val = buf;
669         int i = 0;
670         int option_idx = 0;
671         int blksize_is_set = 0;
672         int tsize = 0;
673         
674         unsigned int orig_blksize;
675
676         while (option_idx < 128 && i < len) {
677                 if (buf[i] == '\0') {
678                         if (&buf[i] > val) {
679                                 tftp_options[option_idx] = val;
680                                 val = &buf[i] + 1;
681                                 ++option_idx;
682                         }
683                 }
684                 ++i;
685         }
686
687         /* Save the block size we requested for sanity check later. */
688         orig_blksize = h->tftp_blksize;
689
690         /* 
691          * Parse individual TFTP options.
692          *    * "blksize" is specified in RFC2348.
693          *    * "tsize" is specified in RFC2349.
694          */ 
695         for (i = 0; i < option_idx; i += 2) {
696             if (strcasecmp(tftp_options[i], "blksize") == 0) {
697                 if (i + 1 < option_idx)
698                         blksize_is_set =
699                             tftp_set_blksize(h, tftp_options[i + 1]);
700             } else if (strcasecmp(tftp_options[i], "tsize") == 0) {
701                 if (i + 1 < option_idx)
702                         tsize = strtol(tftp_options[i + 1], (char **)NULL, 10);
703                 if (tsize != 0)
704                         h->tftp_tsize = tsize;
705             } else {
706                 /* Do not allow any options we did not expect to be ACKed. */
707                 printf("unexpected tftp option '%s'\n", tftp_options[i]);
708                 return (-1);
709             }
710         }
711
712         if (!blksize_is_set) {
713                 /*
714                  * If TFTP blksize was not set, try defaulting
715                  * to the legacy TFTP blksize of SEGSIZE(512)
716                  */
717                 h->tftp_blksize = SEGSIZE;
718         } else if (h->tftp_blksize > orig_blksize) {
719                 /*
720                  * Server should not be proposing block sizes that
721                  * exceed what we said we can handle.
722                  */
723                 printf("unexpected blksize %u\n", h->tftp_blksize);
724                 return (-1);
725         }
726
727 #ifdef TFTP_DEBUG
728         printf("tftp_blksize: %u\n", h->tftp_blksize);
729         printf("tftp_tsize: %lu\n", h->tftp_tsize);
730 #endif
731         return 0;
732 }