]> git.xonotic.org Git - xonotic/darkplaces.git/blob - lhnet.h
build: minor adjustments
[xonotic/darkplaces.git] / lhnet.h
1
2 // Written by Ashley Rose Hale (LadyHavoc) 2003-06-15 and placed into public domain.
3
4 #ifndef LHNET_H
5 #define LHNET_H
6
7 #include <stddef.h>
8 #include "com_list.h"
9
10 typedef enum lhnetaddresstype_e
11 {
12         LHNETADDRESSTYPE_NONE,
13         LHNETADDRESSTYPE_LOOP,
14         LHNETADDRESSTYPE_INET4,
15         LHNETADDRESSTYPE_INET6
16 }
17 lhnetaddresstype_t;
18
19 typedef struct lhnetaddress_s
20 {
21         lhnetaddresstype_t addresstype;
22         int port; // used by LHNETADDRESSTYPE_LOOP
23         unsigned char storage[256]; // sockaddr_in or sockaddr_in6
24 }
25 lhnetaddress_t;
26
27 int LHNETADDRESS_FromPort(lhnetaddress_t *address, lhnetaddresstype_t addresstype, int port);
28 int LHNETADDRESS_FromString(lhnetaddress_t *address, const char *string, int defaultport);
29 /// Returns the number of bytes written to *string excluding the \0 terminator.
30 int LHNETADDRESS_ToString(const lhnetaddress_t *address, char *string, int stringbuffersize, int includeport);
31 static inline lhnetaddresstype_t LHNETADDRESS_GetAddressType(const lhnetaddress_t *address)
32 {
33         if (address)
34                 return address->addresstype;
35         else
36                 return LHNETADDRESSTYPE_NONE;
37 }
38 const char *LHNETADDRESS_GetInterfaceName(const lhnetaddress_t *address, char *ifname, size_t ifnamelength);
39 int LHNETADDRESS_GetPort(const lhnetaddress_t *address);
40 int LHNETADDRESS_SetPort(lhnetaddress_t *address, int port);
41 int LHNETADDRESS_Compare(const lhnetaddress_t *address1, const lhnetaddress_t *address2);
42
43 typedef struct lhnetsocket_s
44 {
45         lhnetaddress_t address;
46         int inetsocket;
47         llist_t list;
48 }
49 lhnetsocket_t;
50 extern lhnetsocket_t lhnet_socketlist;
51
52 void LHNET_Init(void);
53 void LHNET_Shutdown(void);
54 int LHNET_DefaultDSCP(int dscp); // < 0: query; >= 0: set (returns previous value)
55 void LHNET_SleepUntilPacket_Microseconds(int microseconds);
56 lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address);
57 void LHNET_CloseSocket(lhnetsocket_t *lhnetsocket);
58 lhnetaddress_t *LHNET_AddressFromSocket(lhnetsocket_t *sock);
59 int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, lhnetaddress_t *address);
60 int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentlength, const lhnetaddress_t *address);
61
62 #endif
63