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
19 #define LHNETADDRESSTYPE_INET6_FAMILY 10
21 // compatible with sockaddr_in
22 typedef struct lhnetaddress_inet4_s
24 unsigned short family; // 2
26 unsigned char address[4];
27 unsigned char padding[8]; // to match sockaddr_in
31 // compatible with sockaddr_in6
32 typedef struct lhnetaddress_inet6_s
34 unsigned short family; // 10
36 unsigned int flowinfo;
37 unsigned short address[8];
38 unsigned int scope_id;
42 typedef struct lhnetaddress_s
47 lhnetaddress_loop_t loop;
48 lhnetaddress_inet4_t inet4;
49 lhnetaddress_inet6_t inet6;
55 int LHNETADDRESS_FromPort(lhnetaddress_t *address, int addresstype, int port);
56 int LHNETADDRESS_FromString(lhnetaddress_t *address, const char *string, int defaultport);
57 int LHNETADDRESS_ToString(const lhnetaddress_t *address, char *string, int stringbuffersize, int includeport);
58 int LHNETADDRESS_GetAddressType(const lhnetaddress_t *address);
59 int LHNETADDRESS_GetPort(const lhnetaddress_t *address);
60 int LHNETADDRESS_SetPort(lhnetaddress_t *address, int port);
61 int LHNETADDRESS_Compare(const lhnetaddress_t *address1, const lhnetaddress_t *address2);
63 typedef struct lhnetsocket_s
65 lhnetaddress_t address;
67 struct lhnetsocket_s *next, *prev;
71 void LHNET_Init(void);
72 void LHNET_Shutdown(void);
73 lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address);
74 void LHNET_CloseSocket(lhnetsocket_t *lhnetsocket);
75 lhnetaddress_t *LHNET_AddressFromSocket(lhnetsocket_t *sock);
76 int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, lhnetaddress_t *address);
77 int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentlength, const lhnetaddress_t *address);