From: Joseph C. Lehner Date: Thu, 16 Feb 2017 11:08:51 +0000 (+0200) Subject: Ensure that NMRP packets are at least 64 bytes X-Git-Tag: v0.9.11-rc1~8 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=11371109c8f808d8a7401d236789265426b4486d;p=oweals%2Fnmrpflash.git Ensure that NMRP packets are at least 64 bytes --- diff --git a/nmrp.c b/nmrp.c index e45b07e..8cf82d6 100644 --- a/nmrp.c +++ b/nmrp.c @@ -39,6 +39,10 @@ #define IP_LEN 4 #define MAX_LOOP_RECV 1024 +#ifndef MAX +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif + #ifndef PACKED #define PACKED __attribute__((__packed__)) #endif @@ -88,6 +92,7 @@ struct nmrp_msg { uint16_t len; /* only opts[0] is valid! think of this as a char* */ struct nmrp_opt opts[NMRP_MAX_OPT_NUM]; + uint8_t padding[8]; /* this is NOT part of the transmitted packet */ uint32_t num_opts; } PACKED; @@ -289,7 +294,7 @@ static uint8_t *ethsock_get_hwaddr_fake(struct ethsock* sock) static int pkt_send(struct ethsock *sock, struct nmrp_pkt *pkt) { size_t len = ntohs(pkt->msg.len) + sizeof(pkt->eh); - return ethsock_send(sock, pkt, len); + return ethsock_send(sock, pkt, MAX(len, 64)); } static int pkt_recv(struct ethsock *sock, struct nmrp_pkt *pkt)