=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tftp/main.c,v retrieving revision 1.25 retrieving revision 1.26 diff -c -r1.25 -r1.26 *** src/usr.bin/tftp/main.c 2006/07/12 16:58:51 1.25 --- src/usr.bin/tftp/main.c 2006/07/24 17:29:58 1.26 *************** *** 1,4 **** ! /* $OpenBSD: main.c,v 1.25 2006/07/12 16:58:51 mglocker Exp $ */ /* $NetBSD: main.c,v 1.6 1995/05/21 16:54:10 mycroft Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: main.c,v 1.26 2006/07/24 17:29:58 mglocker Exp $ */ /* $NetBSD: main.c,v 1.6 1995/05/21 16:54:10 mycroft Exp $ */ /* *************** *** 41,47 **** static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = ! "$OpenBSD: main.c,v 1.25 2006/07/12 16:58:51 mglocker Exp $"; #endif /* not lint */ /* --- 41,47 ---- static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = ! "$OpenBSD: main.c,v 1.26 2006/07/24 17:29:58 mglocker Exp $"; #endif /* not lint */ /* *************** *** 56,61 **** --- 56,62 ---- #include #include + #include #include #include *************** *** 87,92 **** --- 88,96 ---- void settimeout(int, char **); void settrace(int, char **); void setverbose(int, char **); + void settsize(int, char **); + void settout(int, char **); + void setblksize(int, char **); void status(int, char **); int readcmd(char *, int, FILE *); static void getusage(char *); *************** *** 115,120 **** --- 119,129 ---- char hostname[MAXHOSTNAMELEN]; FILE *file = NULL; volatile sig_atomic_t intrflag = 0; + char *ackbuf; + int has_options = 0; + int opt_tsize = 0; + int opt_tout = 0; + int opt_blksize = 0; char vhelp[] = "toggle verbose mode"; char thelp[] = "toggle packet tracing"; *************** *** 129,134 **** --- 138,146 ---- char ihelp[] = "set total retransmission timeout"; char ashelp[] = "set mode to netascii"; char bnhelp[] = "set mode to octet"; + char oshelp[] = "toggle tsize option"; + char othelp[] = "toggle timeout option"; + char obhelp[] = "set alternative blksize option"; struct cmd { char *name; *************** *** 149,154 **** --- 161,169 ---- { "ascii", ashelp, setascii }, { "rexmt", xhelp, setrexmt }, { "timeout", ihelp, settimeout }, + { "tsize", oshelp, settsize }, + { "tout", othelp, settout }, + { "blksize", obhelp, setblksize }, { "help", hhelp, help }, { "?", hhelp, help }, { NULL, NULL, NULL } *************** *** 194,199 **** --- 209,218 ---- /* catch SIGINT */ signal(SIGINT, intr); + /* allocate memory for packets */ + if ((ackbuf = malloc(SEGSIZE_MAX + 4)) == NULL) + err(1, "malloc"); + /* command prompt */ command(); *************** *** 484,490 **** void setrexmt(int argc, char *argv[]) { ! int t; if (argc < 2) { strlcpy(line, "Rexmt-timeout ", sizeof(line)); --- 503,510 ---- void setrexmt(int argc, char *argv[]) { ! int t; ! const char *errstr; if (argc < 2) { strlcpy(line, "Rexmt-timeout ", sizeof(line)); *************** *** 499,507 **** printf("usage: %s value\n", argv[0]); return; } ! t = atoi(argv[1]); ! if (t < 0) ! printf("%s: bad value\n", argv[1]); else rexmtval = t; } --- 519,527 ---- printf("usage: %s value\n", argv[0]); return; } ! t = strtonum(argv[1], 1, 255, &errstr); ! if (errstr) ! printf("%s: value is %s\n", argv[1], errstr); else rexmtval = t; } *************** *** 707,712 **** --- 727,783 ---- { verbose = !verbose; printf("Verbose mode %s.\n", verbose ? "on" : "off"); + } + + void + settsize(int argc, char *argv[]) + { + opt_tsize = !opt_tsize; + printf("Tsize option %s.\n", opt_tsize ? "on" : "off"); + if (opt_tsize) + has_options++; + else + has_options--; + } + + void + settout(int argc, char *argv[]) + { + opt_tout = !opt_tout; + printf("Timeout option %s.\n", opt_tout ? "on" : "off"); + if (opt_tout) + has_options++; + else + has_options--; + } + + void + setblksize(int argc, char *argv[]) + { + int t; + const char *errstr; + + if (argc < 2) { + strlcpy(line, "Blocksize ", sizeof(line)); + printf("(value) "); + readcmd(&line[strlen(line)], LBUFLEN - strlen(line), stdin); + if (makeargv()) + return; + argc = margc; + argv = margv; + } + if (argc != 2) { + printf("usage: %s value\n", argv[0]); + return; + } + t = strtonum(argv[1], SEGSIZE_MIN, SEGSIZE_MAX, &errstr); + if (errstr) + printf("%s: value is %s\n", argv[1], errstr); + else { + if (opt_blksize == 0) + has_options++; + opt_blksize = t; + } } int