Better handling of extra upload requests
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Wed, 17 Feb 2016 11:31:31 +0000 (12:31 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Wed, 17 Feb 2016 11:31:31 +0000 (12:31 +0100)
nmrp.c

diff --git a/nmrp.c b/nmrp.c
index 521c39e179190e5412d7f3603ef14d61016cd04b..f95fd57c20eeadd3cb7f0f16b91fc3b1caf75b6e 100644 (file)
--- a/nmrp.c
+++ b/nmrp.c
@@ -349,7 +349,7 @@ int nmrp_do(struct nmrpd_args *args)
        char *filename;
        struct in_addr ipaddr, ipmask;
        time_t beg;
-       int i, status, ulreqs, expect;
+       int i, status, ulreqs, expect, unexpected;
        struct ethsock *sock;
        void (*sigh_orig)(int);
 
@@ -469,6 +469,9 @@ int nmrp_do(struct nmrpd_args *args)
                if (expect != NMRP_C_NONE && rx.msg.code != expect) {
                        fprintf(stderr, "Received %s while waiting for %s!\n",
                                        msg_code_str(rx.msg.code), msg_code_str(expect));
+                       unexpected = 1;
+               } else {
+                       unexpected = 0;
                }
 
                tx.msg.code = NMRP_C_NONE;
@@ -518,11 +521,17 @@ int nmrp_do(struct nmrpd_args *args)
 
                                break;
                        case NMRP_C_TFTP_UL_REQ:
-                               if (++ulreqs > 1) {
+                               if (!unexpected) {
+                                       if (++ulreqs > 5) {
+                                               printf("Bailing out after %d upload requests.\n",
+                                                               ulreqs);
+                                               tx.msg.code = NMRP_C_CLOSE_REQ;
+                                               break;
+                                       }
+                               } else {
                                        if (verbosity) {
-                                               printf("Ignoring upload request %d.\n", ulreqs);
+                                               printf("Ignoring extra upload request.\n");
                                        }
-                                       ethsock_set_timeout(sock, args->ul_timeout);
                                        break;
                                }