]> git.xonotic.org Git - xonotic/darkplaces.git/blob - lhnet.h
Rename host_t -> host_static_t.
[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
9 typedef enum lhnetaddresstype_e
10 {
11         LHNETADDRESSTYPE_NONE,
12         LHNETADDRESSTYPE_LOOP,
13         LHNETADDRESSTYPE_INET4,
14         LHNETADDRESSTYPE_INET6
15 }
16 lhnetaddresstype_t;
17
18 typedef struct lhnetaddress_s
19 {
20         lhnetaddresstype_t addresstype;
21         int port; // used by LHNETADDRESSTYPE_LOOP
22         unsigned char storage[256]; // sockaddr_in or sockaddr_in6
23 }
24 lhnetaddress_t;
25
26 int LHNETADDRESS_FromPort(lhnetaddress_t *address, lhnetaddresstype_t addresstype, int port);
27 int LHNETADDRESS_FromString(lhnetaddress_t *address, const char *string, int defaultport);
28 int LHNETADDRESS_ToString(const lhnetaddress_t *address, char *string, int stringbuffersize, int includeport);
29 int LHNETADDRESS_GetAddressType(const lhnetaddress_t *address);
30 const char *LHNETADDRESS_GetInterfaceName(const lhnetaddress_t *address, char *ifname, size_t ifnamelength);
31 int LHNETADDRESS_GetPort(const lhnetaddress_t *address);
32 int LHNETADDRESS_SetPort(lhnetaddress_t *address, int port);
33 int LHNETADDRESS_Compare(const lhnetaddress_t *address1, const lhnetaddress_t *address2);
34
35 typedef struct lhnetsocket_s
36 {
37         lhnetaddress_t address;
38         int inetsocket;
39         struct lhnetsocket_s *next, *prev;
40 }
41 lhnetsocket_t;
42
43 void LHNET_Init(void);
44 void LHNET_Shutdown(void);
45 int LHNET_DefaultDSCP(int dscp); // < 0: query; >= 0: set (returns previous value)
46 void LHNET_SleepUntilPacket_Microseconds(int microseconds);
47 lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address);
48 void LHNET_CloseSocket(lhnetsocket_t *lhnetsocket);
49 lhnetaddress_t *LHNET_AddressFromSocket(lhnetsocket_t *sock);
50 int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, lhnetaddress_t *address);
51 int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentlength, const lhnetaddress_t *address);
52
53 #endif
54