From 9ae72dbc4729af8c2e5ada537f946381c10fa057 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 10 Mar 2022 04:43:26 +0300 Subject: [PATCH] common: update netadr_t structure to include IPv6 addresses --- common/netadr.h | 54 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/common/netadr.h b/common/netadr.h index 4dc00011..a9b4655c 100644 --- a/common/netadr.h +++ b/common/netadr.h @@ -16,6 +16,9 @@ #ifndef NETADR_H #define NETADR_H +#include "build.h" +#include STDINT_H + typedef enum { NA_UNUSED, @@ -23,15 +26,56 @@ typedef enum NA_BROADCAST, NA_IP, NA_IPX, - NA_BROADCAST_IPX + NA_BROADCAST_IPX, + NA_IP6, + NA_MULTICAST_IP6, // all nodes multicast } netadrtype_t; +#define NETADR_T_SIZE 20 + +// Original structure: +// typedef struct netadr_s +// { +// netadrtype_t type; +// unsigned char ip[4]; +// unsigned char ipx[10]; +// unsigned short port; +// } netadr_t; + typedef struct netadr_s { - netadrtype_t type; - unsigned char ip[4]; - unsigned char ipx[10]; - unsigned short port; + union + { + struct + { +#if XASH_LITTLE_ENDIAN + uint16_t type6; + uint16_t port6; +#elif XASH_BIG_ENDIAN + uint16_t port6; + uint16_t type6; +#else +#error +#endif + }; + uint32_t type; + }; + union + { + struct + { + uint16_t ip6[8]; + }; + + struct + { + uint8_t ip[4]; + uint8_t ipx[10]; + uint16_t port; + }; + }; } netadr_t; +extern int _check_netadr_t_size[sizeof( netadr_t ) == NETADR_T_SIZE ? 1 : -1]; + #endif//NETADR_H