version 1.25, 2006/07/12 16:58:51 |
version 1.26, 2006/07/24 17:29:58 |
|
|
|
|
#include <netinet/in.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <arpa/inet.h> |
|
#include <arpa/tftp.h> |
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <err.h> |
#include <err.h> |
|
|
void settimeout(int, char **); |
void settimeout(int, char **); |
void settrace(int, char **); |
void settrace(int, char **); |
void setverbose(int, char **); |
void setverbose(int, char **); |
|
void settsize(int, char **); |
|
void settout(int, char **); |
|
void setblksize(int, char **); |
void status(int, char **); |
void status(int, char **); |
int readcmd(char *, int, FILE *); |
int readcmd(char *, int, FILE *); |
static void getusage(char *); |
static void getusage(char *); |
|
|
char hostname[MAXHOSTNAMELEN]; |
char hostname[MAXHOSTNAMELEN]; |
FILE *file = NULL; |
FILE *file = NULL; |
volatile sig_atomic_t intrflag = 0; |
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 vhelp[] = "toggle verbose mode"; |
char thelp[] = "toggle packet tracing"; |
char thelp[] = "toggle packet tracing"; |
|
|
char ihelp[] = "set total retransmission timeout"; |
char ihelp[] = "set total retransmission timeout"; |
char ashelp[] = "set mode to netascii"; |
char ashelp[] = "set mode to netascii"; |
char bnhelp[] = "set mode to octet"; |
char bnhelp[] = "set mode to octet"; |
|
char oshelp[] = "toggle tsize option"; |
|
char othelp[] = "toggle timeout option"; |
|
char obhelp[] = "set alternative blksize option"; |
|
|
struct cmd { |
struct cmd { |
char *name; |
char *name; |
|
|
{ "ascii", ashelp, setascii }, |
{ "ascii", ashelp, setascii }, |
{ "rexmt", xhelp, setrexmt }, |
{ "rexmt", xhelp, setrexmt }, |
{ "timeout", ihelp, settimeout }, |
{ "timeout", ihelp, settimeout }, |
|
{ "tsize", oshelp, settsize }, |
|
{ "tout", othelp, settout }, |
|
{ "blksize", obhelp, setblksize }, |
{ "help", hhelp, help }, |
{ "help", hhelp, help }, |
{ "?", hhelp, help }, |
{ "?", hhelp, help }, |
{ NULL, NULL, NULL } |
{ NULL, NULL, NULL } |
|
|
/* catch SIGINT */ |
/* catch SIGINT */ |
signal(SIGINT, intr); |
signal(SIGINT, intr); |
|
|
|
/* allocate memory for packets */ |
|
if ((ackbuf = malloc(SEGSIZE_MAX + 4)) == NULL) |
|
err(1, "malloc"); |
|
|
/* command prompt */ |
/* command prompt */ |
command(); |
command(); |
|
|
|
|
void |
void |
setrexmt(int argc, char *argv[]) |
setrexmt(int argc, char *argv[]) |
{ |
{ |
int t; |
int t; |
|
const char *errstr; |
|
|
if (argc < 2) { |
if (argc < 2) { |
strlcpy(line, "Rexmt-timeout ", sizeof(line)); |
strlcpy(line, "Rexmt-timeout ", sizeof(line)); |
|
|
printf("usage: %s value\n", argv[0]); |
printf("usage: %s value\n", argv[0]); |
return; |
return; |
} |
} |
t = atoi(argv[1]); |
t = strtonum(argv[1], 1, 255, &errstr); |
if (t < 0) |
if (errstr) |
printf("%s: bad value\n", argv[1]); |
printf("%s: value is %s\n", argv[1], errstr); |
else |
else |
rexmtval = t; |
rexmtval = t; |
} |
} |
|
|
{ |
{ |
verbose = !verbose; |
verbose = !verbose; |
printf("Verbose mode %s.\n", verbose ? "on" : "off"); |
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 |
int |