Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/tftp/main.c
Show First 20 Lines • Show All 490 Lines • ▼ Show 20 Lines | if (fd < 0) { | ||||
return; | return; | ||||
} | } | ||||
if (fstat(fd, &sb) < 0) { | if (fstat(fd, &sb) < 0) { | ||||
warn("%s", cp); | warn("%s", cp); | ||||
close(fd); | close(fd); | ||||
return; | return; | ||||
} | } | ||||
asprintf(&options[OPT_TSIZE].o_request, "%ju", sb.st_size); | options_set_request(OPT_TSIZE, "%ju", (uintmax_t)sb.st_size); | ||||
if (verbose) | if (verbose) | ||||
printf("putting %s to %s:%s [%s]\n", | printf("putting %s to %s:%s [%s]\n", | ||||
cp, hostname, targ, mode); | cp, hostname, targ, mode); | ||||
xmitfile(peer, port, fd, targ, mode); | xmitfile(peer, port, fd, targ, mode); | ||||
close(fd); | close(fd); | ||||
return; | return; | ||||
} | } | ||||
Show All 11 Lines | for (n = 1; n < argc - 1; n++) { | ||||
} | } | ||||
if (fstat(fd, &sb) < 0) { | if (fstat(fd, &sb) < 0) { | ||||
warn("%s", argv[n]); | warn("%s", argv[n]); | ||||
close(fd); | close(fd); | ||||
free(path); | free(path); | ||||
continue; | continue; | ||||
} | } | ||||
asprintf(&options[OPT_TSIZE].o_request, "%ju", sb.st_size); | options_set_request(OPT_TSIZE, "%ju", (uintmax_t)sb.st_size); | ||||
if (verbose) | if (verbose) | ||||
printf("putting %s to %s:%s [%s]\n", | printf("putting %s to %s:%s [%s]\n", | ||||
argv[n], hostname, path, mode); | argv[n], hostname, path, mode); | ||||
xmitfile(peer, port, fd, path, mode); | xmitfile(peer, port, fd, path, mode); | ||||
close(fd); | close(fd); | ||||
free(path); | free(path); | ||||
▲ Show 20 Lines • Show All 385 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
setrollover(int argc, char *argv[]) | setrollover(int argc, char *argv[]) | ||||
{ | { | ||||
if (argc == 2) { | if (argc == 2) { | ||||
if (strcasecmp(argv[1], "never") == 0 || | if (strcasecmp(argv[1], "never") == 0 || | ||||
strcasecmp(argv[1], "none") == 0) { | strcasecmp(argv[1], "none") == 0) { | ||||
free(options[OPT_ROLLOVER].o_request); | options_set_request(OPT_ROLLOVER, NULL); | ||||
options[OPT_ROLLOVER].o_request = NULL; | |||||
} | } | ||||
if (strcasecmp(argv[1], "1") == 0) { | if (strcasecmp(argv[1], "1") == 0) { | ||||
free(options[OPT_ROLLOVER].o_request); | options_set_request(OPT_ROLLOVER, "1"); | ||||
options[OPT_ROLLOVER].o_request = strdup("1"); | |||||
} | } | ||||
if (strcasecmp(argv[1], "0") == 0) { | if (strcasecmp(argv[1], "0") == 0) { | ||||
free(options[OPT_ROLLOVER].o_request); | options_set_request(OPT_ROLLOVER, "0"); | ||||
options[OPT_ROLLOVER].o_request = strdup("0"); | |||||
} | } | ||||
} | } | ||||
printf("Support for the rollover options is %s.\n", | printf("Support for the rollover options is %s.\n", | ||||
options[OPT_ROLLOVER].o_request != NULL ? "enabled" : "disabled"); | options[OPT_ROLLOVER].o_request != NULL ? "enabled" : "disabled"); | ||||
if (options[OPT_ROLLOVER].o_request != NULL) | if (options[OPT_ROLLOVER].o_request != NULL) | ||||
printf("Block rollover will be to block %s.\n", | printf("Block rollover will be to block %s.\n", | ||||
options[OPT_ROLLOVER].o_request); | options[OPT_ROLLOVER].o_request); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | if (argc != 1) { | ||||
if (size < BLKSIZE_MIN || size > BLKSIZE_MAX) { | if (size < BLKSIZE_MIN || size > BLKSIZE_MAX) { | ||||
printf("Blocksize should be between %d and %d bytes.\n", | printf("Blocksize should be between %d and %d bytes.\n", | ||||
BLKSIZE_MIN, BLKSIZE_MAX); | BLKSIZE_MIN, BLKSIZE_MAX); | ||||
return; | return; | ||||
} else if (size > (int)maxdgram - 4) { | } else if (size > (int)maxdgram - 4) { | ||||
printf("Blocksize can't be bigger than %ld bytes due " | printf("Blocksize can't be bigger than %ld bytes due " | ||||
"to the net.inet.udp.maxdgram sysctl limitation.\n", | "to the net.inet.udp.maxdgram sysctl limitation.\n", | ||||
maxdgram - 4); | maxdgram - 4); | ||||
asprintf(&options[OPT_BLKSIZE].o_request, | options_set_request(OPT_BLKSIZE, "%ld", maxdgram - 4); | ||||
"%ld", maxdgram - 4); | |||||
} else { | } else { | ||||
asprintf(&options[OPT_BLKSIZE].o_request, "%d", size); | options_set_request(OPT_BLKSIZE, "%d", size); | ||||
} | } | ||||
} | } | ||||
printf("Blocksize is now %s bytes.\n", options[OPT_BLKSIZE].o_request); | printf("Blocksize is now %s bytes.\n", options[OPT_BLKSIZE].o_request); | ||||
} | } | ||||
static void | static void | ||||
setblocksize2(int argc, char *argv[]) | setblocksize2(int argc, char *argv[]) | ||||
{ | { | ||||
Show All 36 Lines | if (size < BLKSIZE_MIN || size > BLKSIZE_MAX) { | ||||
return; | return; | ||||
} else if (size > (int)maxdgram - 4) { | } else if (size > (int)maxdgram - 4) { | ||||
printf("Blocksize2 can't be bigger than %ld bytes due " | printf("Blocksize2 can't be bigger than %ld bytes due " | ||||
"to the net.inet.udp.maxdgram sysctl limitation.\n", | "to the net.inet.udp.maxdgram sysctl limitation.\n", | ||||
maxdgram - 4); | maxdgram - 4); | ||||
for (i = 0; sizes[i+1] != 0; i++) { | for (i = 0; sizes[i+1] != 0; i++) { | ||||
if ((int)maxdgram < sizes[i+1]) break; | if ((int)maxdgram < sizes[i+1]) break; | ||||
} | } | ||||
asprintf(&options[OPT_BLKSIZE2].o_request, | options_set_request(OPT_BLKSIZE2, "%d", sizes[i]); | ||||
"%d", sizes[i]); | |||||
} else { | } else { | ||||
asprintf(&options[OPT_BLKSIZE2].o_request, "%d", size); | options_set_request(OPT_BLKSIZE2, "%d", size); | ||||
} | } | ||||
} | } | ||||
printf("Blocksize2 is now %s bytes.\n", | printf("Blocksize2 is now %s bytes.\n", | ||||
options[OPT_BLKSIZE2].o_request); | options[OPT_BLKSIZE2].o_request); | ||||
} | } | ||||
static void | static void | ||||
setpacketdrop(int argc, char *argv[]) | setpacketdrop(int argc, char *argv[]) | ||||
Show All 17 Lines | setwindowsize(int argc, char *argv[]) | ||||
if (argc != 1) { | if (argc != 1) { | ||||
int size = atoi(argv[1]); | int size = atoi(argv[1]); | ||||
if (size < WINDOWSIZE_MIN || size > WINDOWSIZE_MAX) { | if (size < WINDOWSIZE_MIN || size > WINDOWSIZE_MAX) { | ||||
printf("Windowsize should be between %d and %d " | printf("Windowsize should be between %d and %d " | ||||
"blocks.\n", WINDOWSIZE_MIN, WINDOWSIZE_MAX); | "blocks.\n", WINDOWSIZE_MIN, WINDOWSIZE_MAX); | ||||
return; | return; | ||||
} else { | } else { | ||||
asprintf(&options[OPT_WINDOWSIZE].o_request, "%d", | options_set_request(OPT_WINDOWSIZE, "%d", size); | ||||
size); | |||||
} | } | ||||
} | } | ||||
printf("Windowsize is now %s blocks.\n", | printf("Windowsize is now %s blocks.\n", | ||||
options[OPT_WINDOWSIZE].o_request); | options[OPT_WINDOWSIZE].o_request); | ||||
} | } |