X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=lhnet.h;h=6d1d1f3f22c08f661d3c4ef40dc8da454f682e3a;hp=c865f9a9835f51b0a2766fc67af9ed22914116f4;hb=HEAD;hpb=83dcd0632d14eca27555ceddcbf39279c7a17f3f diff --git a/lhnet.h b/lhnet.h index c865f9a9..d368940d 100644 --- a/lhnet.h +++ b/lhnet.h @@ -1,65 +1,41 @@ -// Written by Forest Hale 2003-06-15 and placed into public domain. +// Written by Ashley Rose Hale (LadyHavoc) 2003-06-15 and placed into public domain. #ifndef LHNET_H #define LHNET_H -#define LHNETADDRESSTYPE_NONE 0 -#define LHNETADDRESSTYPE_LOOP 1 -#define LHNETADDRESSTYPE_INET4 2 -#define LHNETADDRESSTYPE_INET6 3 +#include +#include "com_list.h" -typedef struct lhnetaddress_loop_s +typedef enum lhnetaddresstype_e { - unsigned short port; + LHNETADDRESSTYPE_NONE, + LHNETADDRESSTYPE_LOOP, + LHNETADDRESSTYPE_INET4, + LHNETADDRESSTYPE_INET6 } -lhnetaddress_loop_t; - -#define LHNETADDRESSTYPE_INET4_FAMILY 2 -#ifdef WIN32 -#define LHNETADDRESSTYPE_INET6_FAMILY 23 -#else -#define LHNETADDRESSTYPE_INET6_FAMILY 10 -#endif - -// compatible with sockaddr_in -typedef struct lhnetaddress_inet4_s -{ - unsigned short family; // 2 - unsigned short port; - unsigned char address[4]; - unsigned char padding[8]; // to match sockaddr_in -} -lhnetaddress_inet4_t; - -// compatible with sockaddr_in6 -typedef struct lhnetaddress_inet6_s -{ - unsigned short family; // 10 - unsigned short port; - unsigned int flowinfo; - unsigned short address[8]; - unsigned int scope_id; -} -lhnetaddress_inet6_t; +lhnetaddresstype_t; typedef struct lhnetaddress_s { - int addresstype; - union - { - lhnetaddress_loop_t loop; - lhnetaddress_inet4_t inet4; - lhnetaddress_inet6_t inet6; - } - addressdata; + lhnetaddresstype_t addresstype; + int port; // used by LHNETADDRESSTYPE_LOOP + unsigned char storage[256]; // sockaddr_in or sockaddr_in6 } lhnetaddress_t; -int LHNETADDRESS_FromPort(lhnetaddress_t *address, int addresstype, int port); +int LHNETADDRESS_FromPort(lhnetaddress_t *address, lhnetaddresstype_t addresstype, int port); int LHNETADDRESS_FromString(lhnetaddress_t *address, const char *string, int defaultport); +/// Returns the number of bytes written to *string excluding the \0 terminator. int LHNETADDRESS_ToString(const lhnetaddress_t *address, char *string, int stringbuffersize, int includeport); -int LHNETADDRESS_GetAddressType(const lhnetaddress_t *address); +static inline lhnetaddresstype_t LHNETADDRESS_GetAddressType(const lhnetaddress_t *address) +{ + if (address) + return address->addresstype; + else + return LHNETADDRESSTYPE_NONE; +} +const char *LHNETADDRESS_GetInterfaceName(const lhnetaddress_t *address, char *ifname, size_t ifnamelength); int LHNETADDRESS_GetPort(const lhnetaddress_t *address); int LHNETADDRESS_SetPort(lhnetaddress_t *address, int port); int LHNETADDRESS_Compare(const lhnetaddress_t *address1, const lhnetaddress_t *address2); @@ -68,12 +44,14 @@ typedef struct lhnetsocket_s { lhnetaddress_t address; int inetsocket; - struct lhnetsocket_s *next, *prev; + llist_t list; } lhnetsocket_t; +extern lhnetsocket_t lhnet_socketlist; void LHNET_Init(void); void LHNET_Shutdown(void); +int LHNET_DefaultDSCP(int dscp); // < 0: query; >= 0: set (returns previous value) void LHNET_SleepUntilPacket_Microseconds(int microseconds); lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address); void LHNET_CloseSocket(lhnetsocket_t *lhnetsocket);