Skip to content

Commit e18aee0

Browse files
committed
sdk_includes: update
1 parent 691e879 commit e18aee0

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

sdk_includes/common/netadr.h

+51-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2828

2929
#define PORT_ANY -1
3030

31-
typedef enum {NA_LOOPBACK = 1, NA_BROADCAST, NA_IP, NA_IPX, NA_BROADCAST_IPX, NA_IP6, NA_MULTICAST_IP6} netadrtype_t;
31+
typedef enum netadrtype_e
32+
{
33+
NA_UNDEFINED = 0,
34+
NA_LOOPBACK,
35+
NA_BROADCAST,
36+
NA_IP,
37+
NA_IPX,
38+
NA_BROADCAST_IPX,
39+
NA_IP6,
40+
NA_MULTICAST_IP6
41+
} netadrtype_t;
3242

3343
/*
3444
Original Quake-2 structure:
@@ -46,29 +56,60 @@ typedef struct
4656
#pragma pack( push, 1 )
4757
typedef struct netadr_s
4858
{
59+
// the reason we do this evil thing, is that when this struct contains IPv6
60+
// address the `type` is 2-byte wide, but when it doesn't `type` must 4-byte
61+
// wide _and_ ip6_0 must be zeroed, to keep it binary compatible.
62+
#if XASH_LITTLE_ENDIAN
63+
uint16_t type;
64+
uint8_t ip6_0[2];
65+
#elif XASH_BIG_ENDIAN
66+
uint8_t ip6_0[2];
67+
uint16_t type;
68+
#else
69+
#error
70+
#endif
71+
4972
union
5073
{
5174
// IPv6 struct
75+
uint8_t ip6_1[14];
5276
struct
5377
{
54-
uint16_t type6;
55-
uint8_t ip6[16];
56-
};
57-
struct
58-
{
59-
uint32_t type; // must be netadrtype_t but will break with short enums
6078
union
6179
{
62-
uint8_t ip[4];
63-
uint32_t ip4; // for easier conversions
80+
uint8_t ip[4];
81+
uint32_t ip4; // for easier conversions
6482
};
6583
uint8_t ipx[10];
6684
};
6785
};
68-
uint16_t port;
86+
uint16_t port;
6987
} netadr_t;
7088
#pragma pack( pop )
7189

90+
static inline netadrtype_t NET_NetadrType( const netadr_t *a )
91+
{
92+
if( a->type == NA_IP6 || a->type == NA_MULTICAST_IP6 )
93+
return (netadrtype_t)a->type;
94+
95+
if( a->ip6_0[0] || a->ip6_0[1] )
96+
return NA_UNDEFINED;
97+
98+
return (netadrtype_t)a->type;
99+
}
100+
101+
static inline void NET_NetadrSetType( netadr_t *a, netadrtype_t type )
102+
{
103+
if( type == NA_IP6 || type == NA_MULTICAST_IP6 )
104+
{
105+
a->type = type;
106+
return;
107+
}
108+
109+
a->ip6_0[0] = a->ip6_0[1] = 0;
110+
a->type = type;
111+
}
112+
72113
STATIC_CHECK_SIZEOF( netadr_t, 20, 20 );
73114

74115
#endif // NET_ADR_H

sdk_includes/common/xash3d_types.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ typedef uint32_t poolhandle_t;
3131
#undef true
3232
#undef false
3333

34-
#ifndef __cplusplus
35-
typedef enum { false, true } qboolean;
36-
#else
37-
typedef int qboolean;
34+
// true and false are keywords in C++ and C23
35+
#if !__cplusplus && __STDC_VERSION__ < 202311L
36+
enum { false, true };
3837
#endif
38+
typedef int qboolean;
3939

4040
#define MAX_STRING 256 // generic string
4141
#define MAX_VA_STRING 1024 // compatibility macro

0 commit comments

Comments
 (0)