diff --git a/libexec/tftpd/Makefile b/libexec/tftpd/Makefile index 48c5e0dc08d7..84458298d6c5 100644 --- a/libexec/tftpd/Makefile +++ b/libexec/tftpd/Makefile @@ -5,7 +5,6 @@ PROG= tftpd MAN= tftpd.8 SRCS= tftp-file.c tftp-io.c tftp-options.c tftp-transfer.c tftp-utils.c SRCS+= tftpd.c -WARNS= 3 WFORMAT=0 LDFLAGS= -lwrap diff --git a/libexec/tftpd/tftp-file.c b/libexec/tftpd/tftp-file.c index e0f8e784a4b3..1ef882014ea6 100644 --- a/libexec/tftpd/tftp-file.c +++ b/libexec/tftpd/tftp-file.c @@ -103,13 +103,13 @@ static size_t convert_to_net(char *buffer, size_t count, int init) { size_t i; - static size_t n = 0, read = 0; + static size_t n = 0, in = 0; static int newline = 0; if (init) { newline = 0; n = 0; - read = 0; + in = 0; return 0 ; } @@ -124,13 +124,13 @@ convert_to_net(char *buffer, size_t count, int init) } while (i < count) { - if (n == read) { + if (n == in) { /* When done we're done */ if (feof(file)) break; /* Otherwise read another bunch */ - read = fread(convbuffer, 1, count, file); - if (read == 0) break; + in = fread(convbuffer, 1, count, file); + if (in == 0) break; n = 0; } @@ -250,7 +250,7 @@ read_close(void) int -synchnet(int peer) +synchnet(int peer __unused) { return 0; diff --git a/libexec/tftpd/tftp-options.c b/libexec/tftpd/tftp-options.c index 0b97aaf18f6f..d5b638692044 100644 --- a/libexec/tftpd/tftp-options.c +++ b/libexec/tftpd/tftp-options.c @@ -79,7 +79,8 @@ int options_extra_enabled = 1; */ int -option_tsize(int peer, struct tftphdr *tp, int mode, struct stat *stbuf) +option_tsize(int peer __unused, struct tftphdr *tp __unused, int mode, + struct stat *stbuf) { if (options[OPT_TSIZE].o_request == NULL) @@ -159,21 +160,19 @@ option_rollover(int peer) int option_blksize(int peer) { - int *maxdgram; - char maxbuffer[100]; + u_long maxdgram; size_t len; if (options[OPT_BLKSIZE].o_request == NULL) return (0); /* maximum size of an UDP packet according to the system */ - len = sizeof(maxbuffer); + len = sizeof(maxdgram); if (sysctlbyname("net.inet.udp.maxdgram", - maxbuffer, &len, NULL, 0) < 0) { + &maxdgram, &len, NULL, 0) < 0) { tftp_log(LOG_ERR, "sysctl: net.inet.udp.maxdgram"); return (acting_as_client ? 1 : 0); } - maxdgram = (int *)maxbuffer; int size = atoi(options[OPT_BLKSIZE].o_request); if (size < BLKSIZE_MIN || size > BLKSIZE_MAX) { @@ -191,20 +190,20 @@ option_blksize(int peer) } } - if (size > *maxdgram) { + if (size > (int)maxdgram) { if (acting_as_client) { tftp_log(LOG_ERR, "Invalid blocksize (%d bytes), " "net.inet.udp.maxdgram sysctl limits it to " - "%d bytes.\n", size, *maxdgram); + "%d bytes.\n", size, maxdgram); send_error(peer, EBADOP); return (1); } else { tftp_log(LOG_WARNING, "Invalid blocksize (%d bytes), " "net.inet.udp.maxdgram sysctl limits it to " - "%d bytes.\n", size, *maxdgram); - size = *maxdgram; + "%d bytes.\n", size, maxdgram); + size = maxdgram; /* No reason to return */ } } @@ -220,10 +219,9 @@ option_blksize(int peer) } int -option_blksize2(int peer) +option_blksize2(int peer __unused) { - int *maxdgram; - char maxbuffer[100]; + u_long maxdgram; int size, i; size_t len; @@ -236,13 +234,12 @@ option_blksize2(int peer) return (0); /* maximum size of an UDP packet according to the system */ - len = sizeof(maxbuffer); + len = sizeof(maxdgram); if (sysctlbyname("net.inet.udp.maxdgram", - maxbuffer, &len, NULL, 0) < 0) { + &maxdgram, &len, NULL, 0) < 0) { tftp_log(LOG_ERR, "sysctl: net.inet.udp.maxdgram"); return (acting_as_client ? 1 : 0); } - maxdgram = (int *)maxbuffer; size = atoi(options[OPT_BLKSIZE2].o_request); for (i = 0; sizes[i] != 0; i++) { @@ -254,13 +251,13 @@ option_blksize2(int peer) return (acting_as_client ? 1 : 0); } - if (size > *maxdgram) { + if (size > (int)maxdgram) { for (i = 0; sizes[i+1] != 0; i++) { - if (*maxdgram < sizes[i+1]) break; + if ((int)maxdgram < sizes[i+1]) break; } tftp_log(LOG_INFO, "Invalid blocksize2 (%d bytes), net.inet.udp.maxdgram " - "sysctl limits it to %d bytes.\n", size, *maxdgram); + "sysctl limits it to %d bytes.\n", size, maxdgram); size = sizes[i]; /* No need to return */ } @@ -279,7 +276,7 @@ option_blksize2(int peer) * Append the available options to the header */ uint16_t -make_options(int peer, char *buffer, uint16_t size) { +make_options(int peer __unused, char *buffer, uint16_t size) { int i; char *value; const char *option; diff --git a/libexec/tftpd/tftp-utils.c b/libexec/tftpd/tftp-utils.c index da58064dc067..d6d0558e10ed 100644 --- a/libexec/tftpd/tftp-utils.c +++ b/libexec/tftpd/tftp-utils.c @@ -59,7 +59,7 @@ int acting_as_client; * first timeout) to 'timeoutnetwork' (i.e. the last timeout) */ int -settimeouts(int _timeoutpacket, int _timeoutnetwork, int _maxtimeouts) +settimeouts(int _timeoutpacket, int _timeoutnetwork, int _maxtimeouts __unused) { int i; @@ -91,7 +91,7 @@ unmappedaddr(struct sockaddr_in6 *sin6) !IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) return; sin4 = (struct sockaddr_in *)sin6; - addr = *(u_int32_t *)&sin6->sin6_addr.s6_addr[12]; + memcpy(&addr, &sin6->sin6_addr.s6_addr[12], sizeof(addr)); port = sin6->sin6_port; memset(sin4, 0, sizeof(struct sockaddr_in)); sin4->sin_addr.s_addr = addr; @@ -170,7 +170,7 @@ struct packettypes packettypes[] = { { 0, NULL }, }; -char * +const char * packettype(int type) { static char failed[100]; @@ -231,7 +231,7 @@ debug_finds(char *s) return (i); } -char * +const char * debug_show(int d) { static char s[100]; @@ -317,4 +317,3 @@ printstats(const char *direction, int verbose, struct tftp_stats *ts) printf(" [%.0f bits/sec]", (ts->amount*8.)/delta); putchar('\n'); } - diff --git a/libexec/tftpd/tftp-utils.h b/libexec/tftpd/tftp-utils.h index d07247908d97..a789252fe4a0 100644 --- a/libexec/tftpd/tftp-utils.h +++ b/libexec/tftpd/tftp-utils.h @@ -64,17 +64,17 @@ ssize_t get_field(int peer, char *buffer, ssize_t size); */ struct packettypes { int value; - char *name; + const char *const name; }; extern struct packettypes packettypes[]; -char *packettype(int); +const char *packettype(int); /* * RP_ */ struct rp_errors { int error; - char *desc; + const char *const desc; }; extern struct rp_errors rp_errors[]; char *rp_strerror(int error); @@ -89,15 +89,15 @@ char *rp_strerror(int error); #define DEBUG_ACCESS 0x0008 struct debugs { int value; - char *name; - char *desc; + const char *const name; + const char *const desc; }; extern int debug; extern struct debugs debugs[]; extern int packetdroppercentage; int debug_find(char *s); int debug_finds(char *s); -char *debug_show(int d); +const char *debug_show(int d); /* * Log routines diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c index 93943f5b43d8..33911ec48018 100644 --- a/libexec/tftpd/tftpd.c +++ b/libexec/tftpd/tftpd.c @@ -97,7 +97,7 @@ static int suppress_naks; static int logging; static int ipchroot; static int create_new = 0; -static char *newfile_format = "%Y%m%d"; +static const char *newfile_format = "%Y%m%d"; static int increase_name = 0; static mode_t mask = S_IWGRP | S_IWOTH; @@ -785,7 +785,6 @@ static void tftp_xmitfile(int peer, const char *mode) { uint16_t block; - uint32_t amount; time_t now; struct tftp_stats ts; @@ -799,13 +798,12 @@ tftp_xmitfile(int peer, const char *mode) read_close(); if (debug&DEBUG_SIMPLE) tftp_log(LOG_INFO, "Sent %d bytes in %d seconds", - amount, time(NULL) - now); + ts.amount, time(NULL) - now); } static void tftp_recvfile(int peer, const char *mode) { - uint32_t filesize; uint16_t block; struct timeval now1, now2; struct tftp_stats ts; @@ -820,6 +818,7 @@ tftp_recvfile(int peer, const char *mode) tftp_receive(peer, &block, &ts, NULL, 0); write_close(); + gettimeofday(&now2, NULL); if (debug&DEBUG_SIMPLE) { double f; @@ -832,9 +831,8 @@ tftp_recvfile(int peer, const char *mode) (now2.tv_usec - now1.tv_usec) / 100000.0; tftp_log(LOG_INFO, "Download of %d bytes in %d blocks completed after %0.1f seconds\n", - filesize, block, f); + ts.amount, block, f); } return; } - diff --git a/usr.bin/tftp/Makefile b/usr.bin/tftp/Makefile index 12b8216c0450..7521e4e41a1b 100644 --- a/usr.bin/tftp/Makefile +++ b/usr.bin/tftp/Makefile @@ -1,12 +1,11 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD$ -.PATH: ${.CURDIR}/../../libexec/tftpd +.PATH: ${.CURDIR}/../../libexec/tftpd PROG= tftp SRCS= main.c tftp-file.c tftp-io.c tftp-options.c tftp-transfer.c SRCS+= tftp-utils.c tftp.c -WARNS= 3 CFLAGS+=-I${.CURDIR}/../../libexec/tftpd DPADD= ${LIBEDIT} ${LIBTERMCAP} LDADD= -ledit -ltermcap diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index 26ca024454de..247d7e42cc97 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -222,8 +222,8 @@ urihandling(char *URI) char uri[ARG_MAX]; char *host = NULL; char *path = NULL; - char *options = NULL; - char *mode = "octet"; + char *opts = NULL; + const char *tmode = "octet"; char *s; char line[MAXLINE]; int i; @@ -241,14 +241,14 @@ urihandling(char *URI) if ((s = strchr(path, ';')) != NULL) { *s = '\0'; - options = s + 1; + opts = s + 1; - if (strncmp(options, "mode=", 5) == 0) { - mode = options; - mode += 5; + if (strncmp(opts, "mode=", 5) == 0) { + tmode = opts; + tmode += 5; for (i = 0; modes[i].m_name != NULL; i++) { - if (strcmp(modes[i].m_name, mode) == 0) + if (strcmp(modes[i].m_name, tmode) == 0) break; } if (modes[i].m_name == NULL) { @@ -697,7 +697,7 @@ tail(char *filename) } static const char * -command_prompt() +command_prompt(void) { return ("tftp> "); @@ -964,27 +964,25 @@ setblocksize(int argc, char *argv[]) if (argc != 1) { int size = atoi(argv[1]); size_t max; - char maxbuffer[100]; - int *maxdgram; + u_long maxdgram; - max = sizeof(maxbuffer); + max = sizeof(maxdgram); if (sysctlbyname("net.inet.udp.maxdgram", - maxbuffer, &max, NULL, 0) < 0) { + &maxdgram, &max, NULL, 0) < 0) { perror("sysctl: net.inet.udp.maxdgram"); return; } - maxdgram = (int *)maxbuffer; if (size < BLKSIZE_MIN || size > BLKSIZE_MAX) { printf("Blocksize should be between %d and %d bytes.\n", BLKSIZE_MIN, BLKSIZE_MAX); return; - } else if (size > *maxdgram - 4) { - printf("Blocksize can't be bigger than %d bytes due " + } else if (size > (int)maxdgram - 4) { + printf("Blocksize can't be bigger than %ld bytes due " "to the net.inet.udp.maxdgram sysctl limitation.\n", - *maxdgram - 4); + maxdgram - 4); asprintf(&options[OPT_BLKSIZE].o_request, - "%d", *maxdgram - 4); + "%ld", maxdgram - 4); } else { asprintf(&options[OPT_BLKSIZE].o_request, "%d", size); } @@ -1005,21 +1003,19 @@ setblocksize2(int argc, char *argv[]) int size = atoi(argv[1]); int i; size_t max; - char maxbuffer[100]; - int *maxdgram; + u_long maxdgram; int sizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0 }; - max = sizeof(maxbuffer); + max = sizeof(maxdgram); if (sysctlbyname("net.inet.udp.maxdgram", - maxbuffer, &max, NULL, 0) < 0) { + &maxdgram, &max, NULL, 0) < 0) { perror("sysctl: net.inet.udp.maxdgram"); return; } - maxdgram = (int *)maxbuffer; for (i = 0; sizes[i] != 0; i++) { if (sizes[i] == size) break; @@ -1034,12 +1030,12 @@ setblocksize2(int argc, char *argv[]) printf("Blocksize2 should be between " "%d and %d bytes.\n", BLKSIZE_MIN, BLKSIZE_MAX); return; - } else if (size > *maxdgram - 4) { - printf("Blocksize2 can't be bigger than %d bytes due " + } else if (size > (int)maxdgram - 4) { + printf("Blocksize2 can't be bigger than %ld bytes due " "to the net.inet.udp.maxdgram sysctl limitation.\n", - *maxdgram - 4); + maxdgram - 4); for (i = 0; sizes[i+1] != 0; i++) { - if (*maxdgram < sizes[i+1]) break; + if ((int)maxdgram < sizes[i+1]) break; } asprintf(&options[OPT_BLKSIZE2].o_request, "%d", sizes[i]);