net: ip: Verify that in_addr/in6_addr struct sizes are correct

Make sure that in_addr/in6_addr structure size match the respective
binary IP address size with BUILD_ASSERT.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2021-10-04 13:16:19 +02:00 committed by Anas Nashif
commit 0da228c57c
3 changed files with 10 additions and 0 deletions

View file

@ -144,6 +144,9 @@ struct in6_addr {
}; };
}; };
/* Binary size of the IPv6 address */
#define NET_IPV6_ADDR_SIZE 16
/** IPv4 address struct */ /** IPv4 address struct */
struct in_addr { struct in_addr {
union { union {
@ -154,6 +157,9 @@ struct in_addr {
}; };
}; };
/* Binary size of the IPv4 address */
#define NET_IPV4_ADDR_SIZE 4
/** Socket address family type */ /** Socket address family type */
typedef unsigned short int sa_family_t; typedef unsigned short int sa_family_t;

View file

@ -25,6 +25,8 @@ LOG_MODULE_REGISTER(net_ipv4, CONFIG_NET_IPV4_LOG_LEVEL);
#include "tcp_internal.h" #include "tcp_internal.h"
#include "ipv4.h" #include "ipv4.h"
BUILD_ASSERT(sizeof(struct in_addr) == NET_IPV4_ADDR_SIZE);
/* Timeout for various buffer allocations in this file. */ /* Timeout for various buffer allocations in this file. */
#define NET_BUF_TIMEOUT K_MSEC(50) #define NET_BUF_TIMEOUT K_MSEC(50)

View file

@ -35,6 +35,8 @@ LOG_MODULE_REGISTER(net_ipv6, CONFIG_NET_IPV6_LOG_LEVEL);
#include "route.h" #include "route.h"
#include "net_stats.h" #include "net_stats.h"
BUILD_ASSERT(sizeof(struct in6_addr) == NET_IPV6_ADDR_SIZE);
/* Timeout value to be used when allocating net buffer during various /* Timeout value to be used when allocating net buffer during various
* neighbor discovery procedures. * neighbor discovery procedures.
*/ */