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