]> icculus.org git repositories - divverent/darkplaces.git/blob - lhnet.h
made packfile_t (describes a file in a pack) use fs_offset_t
[divverent/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_loop_s
13 {
14         unsigned short port;
15 }
16 lhnetaddress_loop_t;
17
18 #define LHNETADDRESSTYPE_INET4_FAMILY 2
19 #ifdef WIN32
20 #define LHNETADDRESSTYPE_INET6_FAMILY 23
21 #else
22 #define LHNETADDRESSTYPE_INET6_FAMILY 10
23 #endif
24
25 // compatible with sockaddr_in
26 typedef struct lhnetaddress_inet4_s
27 {
28         unsigned short family; // 2
29         unsigned short port;
30         unsigned char address[4];
31         unsigned char padding[8]; // to match sockaddr_in
32 }
33 lhnetaddress_inet4_t;
34
35 // compatible with sockaddr_in6
36 typedef struct lhnetaddress_inet6_s
37 {
38         unsigned short family; // 10
39         unsigned short port;
40         unsigned int flowinfo;
41         unsigned short address[8];
42         unsigned int scope_id;
43 }
44 lhnetaddress_inet6_t;
45
46 typedef struct lhnetaddress_s
47 {
48         int addresstype;
49         union
50         {
51                 lhnetaddress_loop_t loop;
52                 lhnetaddress_inet4_t inet4;
53                 lhnetaddress_inet6_t inet6;
54         }
55         addressdata;
56 }
57 lhnetaddress_t;
58
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);
66
67 typedef struct lhnetsocket_s
68 {
69         lhnetaddress_t address;
70         int inetsocket;
71         struct lhnetsocket_s *next, *prev;
72 }
73 lhnetsocket_t;
74
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);
82
83 #endif
84