Ensure that NMRP packets are at least 64 bytes

This commit is contained in:
Joseph C. Lehner 2017-02-16 13:08:51 +02:00
parent 488cb0df6a
commit 11371109c8

7
nmrp.c
View file

@ -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)