]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - lhnet.h
redesigned lhnetaddress_t struct to be a generic container for sockaddr,
[xonotic/darkplaces.git] / lhnet.h
1
2 // Written by Forest Hale 2003-06-15 and placed into public domain.
3
4 #ifndef LHNET_H
5 #define LHNET_H
6
7 #define LHNETADDRESSTYPE_NONE 0
8 #define LHNETADDRESSTYPE_LOOP 1
9 #define LHNETADDRESSTYPE_INET4 2
10 #define LHNETADDRESSTYPE_INET6 3
11
12 typedef struct lhnetaddress_s
13 {
14         int addresstype;
15         int port; // used by LHNETADDRESSTYPE_LOOP
16         unsigned char storage[256]; // sockaddr_in or sockaddr_in6
17 }
18 lhnetaddress_t;
19
20 int LHNETADDRESS_FromPort(lhnetaddress_t *address, int addresstype, int port);
21 int LHNETADDRESS_FromString(lhnetaddress_t *address, const char *string, int defaultport);
22 int LHNETADDRESS_ToString(const lhnetaddress_t *address, char *string, int stringbuffersize, int includeport);
23 int LHNETADDRESS_GetAddressType(const lhnetaddress_t *address);
24 int LHNETADDRESS_GetPort(const lhnetaddress_t *address);
25 int LHNETADDRESS_SetPort(lhnetaddress_t *address, int port);
26 int LHNETADDRESS_Compare(const lhnetaddress_t *address1, const lhnetaddress_t *address2);
27
28 typedef struct lhnetsocket_s
29 {
30         lhnetaddress_t address;
31         int inetsocket;
32         struct lhnetsocket_s *next, *prev;
33 }
34 lhnetsocket_t;
35
36 void LHNET_Init(void);
37 void LHNET_Shutdown(void);
38 void LHNET_SleepUntilPacket_Microseconds(int microseconds);
39 lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address);
40 void LHNET_CloseSocket(lhnetsocket_t *lhnetsocket);
41 lhnetaddress_t *LHNET_AddressFromSocket(lhnetsocket_t *sock);
42 int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, lhnetaddress_t *address);
43 int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentlength, const lhnetaddress_t *address);
44
45 #endif
46