Don't use -t timeout for TFTP transfers
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Mon, 2 Mar 2020 07:34:44 +0000 (08:34 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Mon, 2 Mar 2020 07:34:44 +0000 (08:34 +0100)
nmrpd.h
tftp.c

diff --git a/nmrpd.h b/nmrpd.h
index 086d2af93448d0ae8ae5f714bc601cb296a64105..d65c8116003c339e8f614e835deb3dc5bb191248 100644 (file)
--- a/nmrpd.h
+++ b/nmrpd.h
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #endif
 
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #endif
 
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
 #ifndef PACKED
 #define PACKED __attribute__((packed))
 #endif
 #ifndef PACKED
 #define PACKED __attribute__((packed))
 #endif
diff --git a/tftp.c b/tftp.c
index b6f5ce7a5690a1d6c8a567a9360dbb06033f48e1..9fd361aab2d6bde2ede93b3abdb4507c11b52bd7 100644 (file)
--- a/tftp.c
+++ b/tftp.c
@@ -315,6 +315,7 @@ int tftp_put(struct nmrpd_args *args)
        const char *file_remote = args->file_remote;
        char *val, *end;
        bool rollover;
        const char *file_remote = args->file_remote;
        char *val, *end;
        bool rollover;
+       unsigned rx_timeout = MAX(args->rx_timeout / 200, 1);
 
        sock = -1;
        ret = -1;
 
        sock = -1;
        ret = -1;
@@ -367,6 +368,7 @@ int tftp_put(struct nmrpd_args *args)
                xperror("inet_addr");
                goto cleanup;
        }
                xperror("inet_addr");
                goto cleanup;
        }
+
        addr.sin_port = htons(args->port);
 
        blksize = 512;
        addr.sin_port = htons(args->port);
 
        blksize = 512;
@@ -447,7 +449,7 @@ int tftp_put(struct nmrpd_args *args)
                        }
                }
 
                        }
                }
 
-               ret = tftp_recvfrom(sock, rx, &port, args->rx_timeout, blksize + 4);
+               ret = tftp_recvfrom(sock, rx, &port, rx_timeout, blksize + 4);
                if (ret < 0) {
                        goto cleanup;
                } else if (!ret) {
                if (ret < 0) {
                        goto cleanup;
                } else if (!ret) {