2 // Written by Forest Hale 2003-06-15 and placed into public domain.
7 #define LHNETADDRESSTYPE_NONE 0
8 #define LHNETADDRESSTYPE_LOOP 1
9 #define LHNETADDRESSTYPE_INET4 2
10 #define LHNETADDRESSTYPE_INET6 3
12 typedef struct lhnetaddress_loop_s
18 #define LHNETADDRESSTYPE_INET4_FAMILY 2
20 #define LHNETADDRESSTYPE_INET6_FAMILY 23
22 #define LHNETADDRESSTYPE_INET6_FAMILY 10
25 // compatible with sockaddr_in
26 typedef struct lhnetaddress_inet4_s
28 unsigned short family; // 2
30 unsigned char address[4];
31 unsigned char padding[8]; // to match sockaddr_in
35 // compatible with sockaddr_in6
36 typedef struct lhnetaddress_inet6_s
38 unsigned short family; // 10
40 unsigned int flowinfo;
41 unsigned short address[8];
42 unsigned int scope_id;
46 typedef struct lhnetaddress_s
51 lhnetaddress_loop_t loop;
52 lhnetaddress_inet4_t inet4;
53 lhnetaddress_inet6_t inet6;
59 int LHNETADDRESS_FromPort(lhnetaddress_t *address, int addresstype, int port);
60 int LHNETADDRESS_FromString(lhnetaddress_t *address, const char *string, int defaultport);
61 int LHNETADDRESS_ToString(const lhnetaddress_t *address, char *string, int stringbuffersize, int includeport);
62 int LHNETADDRESS_GetAddressType(const lhnetaddress_t *address);
63 int LHNETADDRESS_GetPort(const lhnetaddress_t *address);
64 int LHNETADDRESS_SetPort(lhnetaddress_t *address, int port);
65 int LHNETADDRESS_Compare(const lhnetaddress_t *address1, const lhnetaddress_t *address2);
67 typedef struct lhnetsocket_s
69 lhnetaddress_t address;
71 struct lhnetsocket_s *next, *prev;
75 void LHNET_Init(void);
76 void LHNET_Shutdown(void);
77 lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address);
78 void LHNET_CloseSocket(lhnetsocket_t *lhnetsocket);
79 lhnetaddress_t *LHNET_AddressFromSocket(lhnetsocket_t *sock);
80 int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, lhnetaddress_t *address);
81 int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentlength, const lhnetaddress_t *address);