Fix mac handling in blind mode
authorJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sun, 1 Mar 2020 21:32:26 +0000 (22:32 +0100)
committerJoseph C. Lehner <joseph.c.lehner@gmail.com>
Sun, 1 Mar 2020 21:32:26 +0000 (22:32 +0100)
nmrp.c

diff --git a/nmrp.c b/nmrp.c
index 1f17fd80184cd05c934a8bc4cff74d701f0357e6..d85d5ae7187e87322228580c006a3a1f87e1f07c 100644 (file)
--- a/nmrp.c
+++ b/nmrp.c
@@ -492,8 +492,6 @@ int nmrp_do(struct nmrpd_args *args)
                status = pkt_recv(sock, &rx);
                if (status == 0) {
                        if (memcmp(rx.eh.ether_dhost, src, 6) == 0) {
-                               // set the destination MAC for all subsequent packages
-                               memcpy(tx.eh.ether_dhost, rx.eh.ether_shost, 6);
                                break;
                        } else if (verbosity) {
                                printf("\nIgnoring bogus response: %s -> %s.\n",
@@ -512,7 +510,7 @@ int nmrp_do(struct nmrpd_args *args)
                                        goto out;
                                } else {
                                        // we're blind, so fake a response from the MAC specified by -m
-                                       memcpy(rx.eh.ether_dhost, dest, 6);
+                                       memcpy(rx.eh.ether_shost, dest, 6);
                                        msg_init(&rx.msg, NMRP_C_CONF_REQ);
                                        printf("Faking one.");
                                        break;
@@ -523,6 +521,8 @@ int nmrp_do(struct nmrpd_args *args)
 
        printf("\n");
 
+       memcpy(tx.eh.ether_dhost, rx.eh.ether_shost, 6);
+
        if (ethsock_arp_add(sock, rx.eh.ether_shost, ipaddr.s_addr, &arp_undo) != 0) {
                goto out;
        }