/
net.h
141 lines (128 loc) · 6.45 KB
/
net.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#ifndef TILE_NET_H
#define TILE_NET_H
#include "const.h"
TILE_EXTRNC_ENTER
/* Networking errors -- !!! anything from errno is also possible !!! */
#define TL__NET_ERR_BASE 30000
#define TL_NET_ERR_INVALID_HANDLE (TL__NET_ERR_BASE + 1)
#define TL_NET_ERR_NOT_ENOUGH_MEMORY (TL__NET_ERR_BASE + 2)
#define TL_NET_ERR_INVALID_PARAMETER (TL__NET_ERR_BASE + 3)
#define TL_NET_ERR_OPERATION_ABORTED (TL__NET_ERR_BASE + 4)
#define TL_NET_ERR_IO_INCOMPLETE (TL__NET_ERR_BASE + 5)
#define TL_NET_ERR_IO_PENDING (TL__NET_ERR_BASE + 6)
#define TL_NET_ERR_SYS_NOT_READY (TL__NET_ERR_BASE + 7)
#define TL_NET_ERR_VER_NOT_SUPPORTED (TL__NET_ERR_BASE + 8)
#define TL_NET_ERR_NOT_INITIALIZED (TL__NET_ERR_BASE + 9)
#define TL_NET_ERR_HOST_NOT_FOUND (TL__NET_ERR_BASE + 10)
#define TL_NET_ERR_TRY_AGAIN (TL__NET_ERR_BASE + 11)
#define TL_NET_ERR_NO_RECOVERY (TL__NET_ERR_BASE + 12)
#define TL_NET_ERR_NO_DATA (TL__NET_ERR_BASE + 13)
#define TL_NET_ERR_SYSCALL_FAILURE (TL__NET_ERR_BASE + 14)
#define TL_NET_ERR_SERVICE_NOT_FOUND (TL__NET_ERR_BASE + 15)
#define TL_NET_ERR_TYPE_NOT_FOUND (TL__NET_ERR_BASE + 16)
#define TL_NET_ERR_NO_MORE (TL__NET_ERR_BASE + 17)
#define TL_NET_ERR_CANCELLED (TL__NET_ERR_BASE + 18)
#define TL_NET_ERR_QOS_RECEIVERS (TL__NET_ERR_BASE + 19)
#define TL_NET_ERR_QOS_SENDERS (TL__NET_ERR_BASE + 20)
#define TL_NET_ERR_QOS_NO_SENDERS (TL__NET_ERR_BASE + 21)
#define TL_NET_ERR_QOS_NO_RECEIVERS (TL__NET_ERR_BASE + 22)
#define TL_NET_ERR_QOS_REQUEST_CONFIRMED (TL__NET_ERR_BASE + 23)
#define TL_NET_ERR_QOS_ADMISSION_FAILURE (TL__NET_ERR_BASE + 24)
#define TL_NET_ERR_QOS_POLICY_FAILURE (TL__NET_ERR_BASE + 25)
#define TL_NET_ERR_QOS_BAD_STYLE (TL__NET_ERR_BASE + 26)
#define TL_NET_ERR_QOS_BAD_OBJECT (TL__NET_ERR_BASE + 27)
#define TL_NET_ERR_QOS_TRAFFIC_CTRL_ERROR (TL__NET_ERR_BASE + 28)
#define TL_NET_ERR_QOS_GENERIC_ERROR (TL__NET_ERR_BASE + 29)
#define TL_NET_ERR_QOS_SERVICE_TYPE (TL__NET_ERR_BASE + 30)
#define TL_NET_ERR_QOS_FLOWSPEC (TL__NET_ERR_BASE + 31)
#define TL_NET_ERR_QOS_PROV_BUF (TL__NET_ERR_BASE + 32)
#define TL_NET_ERR_QOS_FILTER_STYLE (TL__NET_ERR_BASE + 33)
#define TL_NET_ERR_QOS_FILTER_TYPE (TL__NET_ERR_BASE + 34)
#define TL_NET_ERR_QOS_FILTER_COUNT (TL__NET_ERR_BASE + 35)
#define TL_NET_ERR_QOS_OBJ_LENGTH (TL__NET_ERR_BASE + 36)
#define TL_NET_ERR_QOS_FLOW_COUNT (TL__NET_ERR_BASE + 37)
#define TL_NET_ERR_QOS_UNKOWN_PS_OBJ (TL__NET_ERR_BASE + 38)
#define TL_NET_ERR_QOS_POLICY_OBJ (TL__NET_ERR_BASE + 39)
#define TL_NET_ERR_QOS_FLOWDESC (TL__NET_ERR_BASE + 40)
#define TL_NET_ERR_QOS_PS_FLOWSPEC (TL__NET_ERR_BASE + 41)
#define TL_NET_ERR_QOS_PS_FILTERSPEC (TL__NET_ERR_BASE + 42)
#define TL_NET_ERR_QOS_SD_MODE_OBJ (TL__NET_ERR_BASE + 43)
#define TL_NET_ERR_QOS_SHAPERATE_OBJ (TL__NET_ERR_BASE + 44)
#define TL_NET_ERR_QOS_RESERVED_PETYPE (TL__NET_ERR_BASE + 45)
#define TL_NET_ERR_EINPROGRESS (TL__NET_ERR_BASE + 46)
#define TL_NET_ERR_EALREADY (TL__NET_ERR_BASE + 47)
#define TL_NET_ERR_ENOTSOCK (TL__NET_ERR_BASE + 48)
#define TL_NET_ERR_EDESTADDRREQ (TL__NET_ERR_BASE + 49)
#define TL_NET_ERR_EMSGSIZE (TL__NET_ERR_BASE + 50)
#define TL_NET_ERR_EPROTOTYPE (TL__NET_ERR_BASE + 51)
#define TL_NET_ERR_ENOPROTOOPT (TL__NET_ERR_BASE + 52)
#define TL_NET_ERR_EPROTONOSUPPORT (TL__NET_ERR_BASE + 53)
#define TL_NET_ERR_ESOCKTNOSUPPORT (TL__NET_ERR_BASE + 54)
#define TL_NET_ERR_EOPNOTSUPP (TL__NET_ERR_BASE + 55)
#define TL_NET_ERR_EPFNOSUPPORT (TL__NET_ERR_BASE + 56)
#define TL_NET_ERR_EAFNOSUPPORT (TL__NET_ERR_BASE + 57)
#define TL_NET_ERR_EADDRINUSE (TL__NET_ERR_BASE + 58)
#define TL_NET_ERR_EADDRNOTAVAIL (TL__NET_ERR_BASE + 59)
#define TL_NET_ERR_ENETDOWN (TL__NET_ERR_BASE + 60)
#define TL_NET_ERR_ENETUNREACH (TL__NET_ERR_BASE + 61)
#define TL_NET_ERR_ENETRESET (TL__NET_ERR_BASE + 62)
#define TL_NET_ERR_ECONNABORTED (TL__NET_ERR_BASE + 63)
#define TL_NET_ERR_ECONNRESET (TL__NET_ERR_BASE + 64)
#define TL_NET_ERR_ENOBUFS (TL__NET_ERR_BASE + 65)
#define TL_NET_ERR_EISCONN (TL__NET_ERR_BASE + 66)
#define TL_NET_ERR_ENOTCONN (TL__NET_ERR_BASE + 67)
#define TL_NET_ERR_ESHUTDOWN (TL__NET_ERR_BASE + 68)
#define TL_NET_ERR_ETOOMANYREFS (TL__NET_ERR_BASE + 69)
#define TL_NET_ERR_ETIMEDOUT (TL__NET_ERR_BASE + 70)
#define TL_NET_ERR_ECONNREFUSED (TL__NET_ERR_BASE + 71)
#define TL_NET_ERR_ELOOP (TL__NET_ERR_BASE + 72)
#define TL_NET_ERR_ENAMETOOLONG (TL__NET_ERR_BASE + 73)
#define TL_NET_ERR_EHOSTDOWN (TL__NET_ERR_BASE + 74)
#define TL_NET_ERR_EHOSTUNREACH (TL__NET_ERR_BASE + 75)
#define TL_NET_ERR_ENOTEMPTY (TL__NET_ERR_BASE + 76)
#define TL_NET_ERR_EPROCLIM (TL__NET_ERR_BASE + 77)
#define TL_NET_ERR_EUSERS (TL__NET_ERR_BASE + 78)
#define TL_NET_ERR_EDQUOT (TL__NET_ERR_BASE + 79)
#define TL_NET_ERR_ESTALE (TL__NET_ERR_BASE + 80)
#define TL_NET_ERR_EREMOTE (TL__NET_ERR_BASE + 81)
#define TL_NET_ERR_EDISCON (TL__NET_ERR_BASE + 82)
#define TL_NET_ERR_ENOMORE (TL__NET_ERR_BASE + 83)
#define TL_NET_ERR_ECANCELLED (TL__NET_ERR_BASE + 84)
#define TL_NET_ERR_EINVALIDPROCTABLE (TL__NET_ERR_BASE + 85)
#define TL_NET_ERR_EINVALIDPROVIDER (TL__NET_ERR_BASE + 86)
#define TL_NET_ERR_EPROVIDERFAILEDINIT (TL__NET_ERR_BASE + 87)
#define TL_NET_ERR_EREFUSED (TL__NET_ERR_BASE + 88)
#define TL_NET_ERR_EWOULDBLOCK (TL__NET_ERR_BASE + 89)
/* Networking */
TlBool tlNet_Init(TlU16 port);
void tlNet_Fini();
TlBool tlNet_SetCurrentPort(TlU16 port);
TlU16 tlNet_GetCurrentPort();
void tlNet_FreePort(TlU16 port);
TlU32 tlNet_GetActivePortCount();
#define tlNet_MakeIP(a,b,c,d) \
((TlU32)((((TlU8)(a))<<24)|(((TlU8)(b))<<16)|(((TlU8)(c))<<8)|((TlU8)(d))))
#define tlNet_GetIP_A(ip) \
((TlU8)((((TlU32)(ip))&0xFF000000)>>24))
#define tlNet_GetIP_B(ip) \
((TlU8)((((TlU32)(ip))&0x00FF0000)>>16))
#define tlNet_GetIP_C(ip) \
((TlU8)((((TlU32)(ip))&0x0000FF00)>>8))
#define tlNet_GetIP_D(ip) \
((TlU8)((((TlU32)(ip))&0x000000FF)>>0))
const char *tlNet_ResolveHostAddress(const char *domain);
TlBool tlNet_ResolveHostAddressIP(const char *domain, TlU32 *ip, TlU16 *port);
TlBool tlNet_SetSendAddress(const char *addr);
TlBool tlNet_SetSendAddressIP(TlU32 ip, TlU16 port);
const char *tlNet_GetSendAddress();
void tlNet_GetSendAddressIP(TlU32 *ip, TlU16 *port);
const char *tlNet_GetFromAddress();
void tlNet_GetFromAddressIP(TlU32 *ip, TlU16 *port);
TlBool tlNet_SendPacket(const void *data, TlUInt dataLen);
TlUInt tlNet_RecvPacket(void *data, TlUInt dataLen);
int tlNet_LastError();
const char *tlNet_ErrorText(int code);
void tlNet_ClearError();
const char *tlNet_LastErrorText();
TILE_EXTRNC_LEAVE
#endif