- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- * ------------------------------------------------------------------------- */
-
-#include "busybox.h"
-
-
-#define TFTP_BLOCKSIZE_DEFAULT 512 /* according to RFC 1350, don't change */
-#define TFTP_TIMEOUT 5 /* seconds */
-#define TFTP_NUM_RETRIES 5 /* number of retries */
-
-static const char * const MODE_OCTET = "octet";
-#define MODE_OCTET_LEN 6 /* sizeof(MODE_OCTET)*/
-
-static const char * const OPTION_BLOCKSIZE = "blksize";
-#define OPTION_BLOCKSIZE_LEN 8 /* sizeof(OPTION_BLOCKSIZE) */
+ * tftpd added by Denys Vlasenko & Vladimir Dronnikov
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+
+//usage:#define tftp_trivial_usage
+//usage: "[OPTIONS] HOST [PORT]"
+//usage:#define tftp_full_usage "\n\n"
+//usage: "Transfer a file from/to tftp server\n"
+//usage: "\n -l FILE Local FILE"
+//usage: "\n -r FILE Remote FILE"
+//usage: IF_FEATURE_TFTP_GET(
+//usage: "\n -g Get file"
+//usage: )
+//usage: IF_FEATURE_TFTP_PUT(
+//usage: "\n -p Put file"
+//usage: )
+//usage: IF_FEATURE_TFTP_BLOCKSIZE(
+//usage: "\n -b SIZE Transfer blocks of SIZE octets"
+//usage: )
+//usage:
+//usage:#define tftpd_trivial_usage
+//usage: "[-cr] [-u USER] [DIR]"
+//usage:#define tftpd_full_usage "\n\n"
+//usage: "Transfer a file on tftp client's request\n"
+//usage: "\n"
+//usage: "tftpd should be used as an inetd service.\n"
+//usage: "tftpd's line for inetd.conf:\n"
+//usage: " 69 dgram udp nowait root tftpd tftpd -l /files/to/serve\n"
+//usage: "It also can be ran from udpsvd:\n"
+//usage: " udpsvd -vE 0.0.0.0 69 tftpd /files/to/serve\n"
+//usage: "\n -r Prohibit upload"
+//usage: "\n -c Allow file creation via upload"
+//usage: "\n -u Access files as USER"
+//usage: "\n -l Log to syslog (inetd mode requires this)"
+
+#include "libbb.h"
+#include <syslog.h>
+
+#if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT
+
+#define TFTP_BLKSIZE_DEFAULT 512 /* according to RFC 1350, don't change */
+#define TFTP_BLKSIZE_DEFAULT_STR "512"
+/* Was 50 ms but users asked to bump it up a bit */
+#define TFTP_TIMEOUT_MS 100
+#define TFTP_MAXTIMEOUT_MS 2000
+#define TFTP_NUM_RETRIES 12 /* number of backed-off retries */