Browse Source

common: replace netadr.h with compatible definition from GPL Quake-2 sources

pull/4/head
Alibek Omarov 10 months ago
parent
commit
46f30e215c
  1. 110
      common/netadr.h
  2. 6
      engine/common/masterlist.c
  3. 22
      engine/common/net_ws.c

110
common/netadr.h

@ -1,76 +1,74 @@
/*** /*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
* This program is free software; you can redistribute it and/or
* This product contains software technology licensed from Id modify it under the terms of the GNU General Public License
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. as published by the Free Software Foundation; either version 2
* All Rights Reserved. of the License, or (at your option) any later version.
*
* Use, distribution, and modification of this source code and/or resulting This program is distributed in the hope that it will be useful,
* object code is restricted to non-commercial enhancements to products from but WITHOUT ANY WARRANTY; without even the implied warranty of
* Valve LLC. All other use, distribution, or modification is prohibited MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* without written permission from Valve LLC.
* See the GNU General Public License for more details.
****/
You should have received a copy of the GNU General Public License
#ifndef NETADR_H along with this program; if not, write to the Free Software
#define NETADR_H Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "build.h" */
#ifndef NET_ADR_H
#define NET_ADR_H
#include STDINT_H #include STDINT_H
typedef enum // net.h -- quake's interface to the networking layer
// a1ba: copied from Quake-2/qcommon/qcommon.h and modified to support IPv6
#define PORT_ANY -1
typedef enum {NA_LOOPBACK = 1, NA_BROADCAST, NA_IP, NA_IPX, NA_BROADCAST_IPX, NA_IP6, NA_MULTICAST_IP6} netadrtype_t;
/*
Original Quake-2 structure:
typedef struct
{ {
NA_UNUSED = 0, netadrtype_t type;
NA_LOOPBACK,
NA_BROADCAST, byte ip[4];
NA_IP, byte ipx[10];
NA_IPX,
NA_BROADCAST_IPX, unsigned short port;
NA_IP6, } netadr_t;
NA_MULTICAST_IP6, // all nodes multicast */
} netadrtype_t;
// Original structure:
// typedef struct netadr_s
// {
// netadrtype_t type;
// unsigned char ip[4];
// unsigned char ipx[10];
// unsigned short port;
// } netadr_t;
#pragma pack( push, 1 ) #pragma pack( push, 1 )
typedef struct netadr_s typedef struct netadr_s
{ {
union union
{ {
// IPv6 struct
struct struct
{ {
uint32_t type; uint16_t type6;
union uint8_t ip6[16];
{
uint8_t ip[4];
uint32_t ip4;
};
uint8_t ipx[10];
}; };
struct struct
{ {
#if XASH_LITTLE_ENDIAN uint32_t type; // must be netadrtype_t but will break with short enums
uint16_t type6; union
uint8_t ip6[16]; {
#elif XASH_BIG_ENDIAN uint8_t ip[4];
uint8_t ip6_0[2]; uint32_t ip4; // for easier conversions
uint16_t type6; };
uint8_t ip6_2[14]; uint8_t ipx[10];
#endif
}; };
}; };
uint16_t port; uint16_t port;
} netadr_t; } netadr_t;
#pragma pack( pop ) #pragma pack( pop )
STATIC_ASSERT( sizeof( netadr_t ) == 20, "invalid netadr_t size" ); STATIC_ASSERT( sizeof( netadr_t ) == 20, "netadr_t isn't 20 bytes!" );
#endif//NETADR_H #endif // NET_ADR_H

6
engine/common/masterlist.c

@ -50,7 +50,7 @@ static net_gai_state_t NET_GetMasterHostByName( master_t *m )
if( res == NET_EAI_OK ) if( res == NET_EAI_OK )
return res; return res;
m->adr.type = NA_UNUSED; m->adr.type = 0;
if( res == NET_EAI_NONAME ) if( res == NET_EAI_NONAME )
Con_Reportf( "Can't resolve adr: %s\n", m->address ); Con_Reportf( "Can't resolve adr: %s\n", m->address );
@ -266,7 +266,7 @@ static void NET_AddMaster( const char *addr, qboolean save )
master->sent = false; master->sent = false;
master->save = save; master->save = save;
master->next = NULL; master->next = NULL;
master->adr.type = NA_UNUSED; master->adr.type = 0;
// link in // link in
if( last ) if( last )
@ -322,7 +322,7 @@ static void NET_ListMasters_f( void )
for( i = 1, list = ml.list; list; i++, list = list->next ) for( i = 1, list = ml.list; list; i++, list = list->next )
{ {
Msg( "%d\t%s", i, list->address ); Msg( "%d\t%s", i, list->address );
if( list->adr.type != NA_UNUSED ) if( list->adr.type != 0 )
Msg( "\t%s\n", NET_AdrToString( list->adr )); Msg( "\t%s\n", NET_AdrToString( list->adr ));
else Msg( "\n" ); else Msg( "\n" );
} }

22
engine/common/net_ws.c

@ -32,7 +32,6 @@ static const struct in6_addr in6addr_any;
#define NET_USE_FRAGMENTS #define NET_USE_FRAGMENTS
#define PORT_ANY -1
#define MAX_LOOPBACK 4 #define MAX_LOOPBACK 4
#define MASK_LOOPBACK (MAX_LOOPBACK - 1) #define MASK_LOOPBACK (MAX_LOOPBACK - 1)
@ -132,7 +131,7 @@ static CVAR_DEFINE_AUTO( net6_address, "0", FCVAR_PRIVILEGED|FCVAR_READ_ONLY, "c
NET_ErrorString NET_ErrorString
==================== ====================
*/ */
char *NET_ErrorString( void ) static char *NET_ErrorString( void )
{ {
#if XASH_WIN32 #if XASH_WIN32
int err = WSANOTINITIALISED; int err = WSANOTINITIALISED;
@ -226,34 +225,17 @@ _inline qboolean NET_IsSocketValid( int socket )
void NET_NetadrToIP6Bytes( uint8_t *ip6, const netadr_t *adr ) void NET_NetadrToIP6Bytes( uint8_t *ip6, const netadr_t *adr )
{ {
#if XASH_LITTLE_ENDIAN
memcpy( ip6, adr->ip6, sizeof( adr->ip6 )); memcpy( ip6, adr->ip6, sizeof( adr->ip6 ));
#elif XASH_BIG_ENDIAN
memcpy( ip6, adr->ip6_0, sizeof( adr->ip6_0 ));
memcpy( ip6 + sizeof( adr->ip6_0 ), adr->ip6_2, sizeof( adr->ip6_2 ));
#endif
} }
void NET_IP6BytesToNetadr( netadr_t *adr, const uint8_t *ip6 ) void NET_IP6BytesToNetadr( netadr_t *adr, const uint8_t *ip6 )
{ {
#if XASH_LITTLE_ENDIAN
memcpy( adr->ip6, ip6, sizeof( adr->ip6 )); memcpy( adr->ip6, ip6, sizeof( adr->ip6 ));
#elif XASH_BIG_ENDIAN
memcpy( adr->ip6_0, ip6, sizeof( adr->ip6_0 ));
memcpy( adr->ip6_2, ip6 + sizeof( adr->ip6_0 ), sizeof( adr->ip6_2 ));
#endif
} }
_inline int NET_NetadrIP6Compare( const netadr_t *a, const netadr_t *b ) static int NET_NetadrIP6Compare( const netadr_t *a, const netadr_t *b )
{ {
#if XASH_LITTLE_ENDIAN
return memcmp( a->ip6, b->ip6, sizeof( a->ip6 )); return memcmp( a->ip6, b->ip6, sizeof( a->ip6 ));
#elif XASH_BIG_ENDIAN
int ret = memcmp( a->ip6_0, b->ip6_0, sizeof( a->ip6_0 ));
if( !ret )
return memcmp( a->ip6_2, b->ip6_2, sizeof( a->ip6_2 ));
return ret;
#endif
} }
/* /*

Loading…
Cancel
Save