Browse Source

engine: common: add network address comparator function

pull/2/head
Alibek Omarov 2 years ago
parent
commit
18c94b6ec4
  1. 44
      engine/common/net_ws.c
  2. 1
      engine/common/net_ws.h

44
engine/common/net_ws.c

@ -931,11 +931,53 @@ qboolean NET_CompareAdr( const netadr_t a, const netadr_t b ) @@ -931,11 +931,53 @@ qboolean NET_CompareAdr( const netadr_t a, const netadr_t b )
return true;
}
Con_DPrintf( S_ERROR "NET_CompareAdr: bad address type\n" );
return false;
}
/*
====================
NET_CompareAdrSort
Network address sorting comparator
====================
*/
int NET_CompareAdrSort( const void *_a, const void *_b )
{
const netadr_t *a = _a;
const netadr_t *b = _b;
int portdiff;
if( a->type6 != b->type6 )
return (int)a->type6 - (int)b->type6;
portdiff = (int)a->port - (int)b->port;
switch( a->type6 )
{
case NA_IP6:
return NET_NetadrIP6Compare( a, b );
case NA_MULTICAST_IP6:
return portdiff;
}
if( a->type != b->type )
return (int)a->type - (int)b->type;
switch( a->type )
{
case NA_IP:
return memcmp( a->ip, b->ip, sizeof( a->ip ));
case NA_IPX:
return memcmp( a->ipx, b->ipx, sizeof( a->ipx ));
case NA_BROADCAST:
case NA_BROADCAST_IPX:
return portdiff;
}
return 0;
}
/*
====================
NET_IsLocalAddress

1
engine/common/net_ws.h

@ -60,6 +60,7 @@ qboolean NET_CompareClassBAdr( const netadr_t a, const netadr_t b ); @@ -60,6 +60,7 @@ qboolean NET_CompareClassBAdr( const netadr_t a, const netadr_t b );
qboolean NET_StringToAdr( const char *string, netadr_t *adr );
qboolean NET_StringToFilterAdr( const char *s, netadr_t *adr, uint *prefixlen );
int NET_StringToAdrNB( const char *string, netadr_t *adr );
int NET_CompareAdrSort( const void *_a, const void *_b );
qboolean NET_CompareAdr( const netadr_t a, const netadr_t b );
qboolean NET_CompareBaseAdr( const netadr_t a, const netadr_t b );
qboolean NET_CompareAdrByMask( const netadr_t a, const netadr_t b, uint prefixlen );

Loading…
Cancel
Save