1 | ' api_winsock2.sbp
|
---|
2 | 'Windows Sockets Ver2.0
|
---|
3 |
|
---|
4 |
|
---|
5 | #ifndef _INC_WINSOCK2
|
---|
6 | #define _INC_WINSOCK2
|
---|
7 |
|
---|
8 | TypeDef SOCKET = ULONG_PTR
|
---|
9 |
|
---|
10 | Const SOCKET_ERROR = -1
|
---|
11 | Const INVALID_SOCKET = -1
|
---|
12 |
|
---|
13 |
|
---|
14 | 'Port/socket numbers - network standard functions
|
---|
15 | Const IPPORT_ECHO = 7
|
---|
16 | Const IPPORT_DISCARD = 9
|
---|
17 | Const IPPORT_SYSTAT = 11
|
---|
18 | Const IPPORT_DAYTIME = 13
|
---|
19 | Const IPPORT_NETSTAT = 15
|
---|
20 | Const IPPORT_FTP = 21
|
---|
21 | Const IPPORT_TELNET = 23
|
---|
22 | Const IPPORT_SMTP = 25
|
---|
23 | Const IPPORT_TIMESERVER = 37
|
---|
24 | Const IPPORT_NAMESERVER = 42
|
---|
25 | Const IPPORT_WHOIS = 43
|
---|
26 | Const IPPORT_MTP = 57
|
---|
27 |
|
---|
28 |
|
---|
29 | 'Address families
|
---|
30 | Const AF_UNSPEC = 0
|
---|
31 | Const AF_UNIX = 1
|
---|
32 | Const AF_INET = 2
|
---|
33 | Const AF_IMPLINK = 3
|
---|
34 | Const AF_PUP = 4
|
---|
35 | Const AF_CHAOS = 5
|
---|
36 | Const AF_NS = 6
|
---|
37 | Const AF_IPX = AF_NS
|
---|
38 | Const AF_ISO = 7
|
---|
39 | Const AF_OSI = AF_ISO
|
---|
40 | Const AF_ECMA = 8
|
---|
41 | Const AF_DATAKIT = 9
|
---|
42 | Const AF_CCITT = 10
|
---|
43 | Const AF_SNA = 11
|
---|
44 | Const AF_DECnet = 12
|
---|
45 | Const AF_DLI = 13
|
---|
46 | Const AF_LAT = 14
|
---|
47 | Const AF_HYLINK = 15
|
---|
48 | Const AF_APPLETALK = 16
|
---|
49 | Const AF_NETBIOS = 17
|
---|
50 | Const AF_VOICEVIEW = 18
|
---|
51 | Const AF_FIREFOX = 19
|
---|
52 | Const AF_UNKNOWN1 = 20
|
---|
53 | Const AF_BAN = 21
|
---|
54 | Const AF_ATM = 22
|
---|
55 | Const AF_INET6 = 23
|
---|
56 | Const AF_CLUSTER = 24
|
---|
57 | Const AF_12844 = 25
|
---|
58 | Const AF_MAX = 26
|
---|
59 |
|
---|
60 |
|
---|
61 | 'Protocol families
|
---|
62 | Const PF_UNSPEC = AF_UNSPEC
|
---|
63 | Const PF_UNIX = AF_UNIX
|
---|
64 | Const PF_INET = AF_INET
|
---|
65 | Const PF_IMPLINK = AF_IMPLINK
|
---|
66 | Const PF_PUP = AF_PUP
|
---|
67 | Const PF_CHAOS = AF_CHAOS
|
---|
68 | Const PF_NS = AF_NS
|
---|
69 | Const PF_IPX = AF_IPX
|
---|
70 | Const PF_ISO = AF_ISO
|
---|
71 | Const PF_OSI = AF_OSI
|
---|
72 | Const PF_ECMA = AF_ECMA
|
---|
73 | Const PF_DATAKIT = AF_DATAKIT
|
---|
74 | Const PF_CCITT = AF_CCITT
|
---|
75 | Const PF_SNA = AF_SNA
|
---|
76 | Const PF_DECnet = AF_DECnet
|
---|
77 | Const PF_DLI = AF_DLI
|
---|
78 | Const PF_LAT = AF_LAT
|
---|
79 | Const PF_HYLINK = AF_HYLINK
|
---|
80 | Const PF_APPLETALK = AF_APPLETALK
|
---|
81 | Const PF_VOICEVIEW = AF_VOICEVIEW
|
---|
82 | Const PF_FIREFOX = AF_FIREFOX
|
---|
83 | Const PF_UNKNOWN1 = AF_UNKNOWN1
|
---|
84 | Const PF_BAN = AF_BAN
|
---|
85 | Const PF_ATM = AF_ATM
|
---|
86 | Const PF_INET6 = AF_INET6
|
---|
87 | Const PF_MAX = AF_MAX
|
---|
88 |
|
---|
89 |
|
---|
90 | Const MSG_OOB = 1 'process out-of-band data
|
---|
91 | Const MSG_PEEK = 2 'peek at incoming message
|
---|
92 | Const MSG_DONTROUTE = 4 'send without using routing tables
|
---|
93 |
|
---|
94 |
|
---|
95 | 'Error code
|
---|
96 | Const WSABASEERR = 10000
|
---|
97 | Const WSAEINTR = WSABASEERR+4
|
---|
98 | Const WSAEBADF = WSABASEERR+9
|
---|
99 | Const WSAEACCES = WSABASEERR+13
|
---|
100 | Const WSAEFAULT = WSABASEERR+14
|
---|
101 | Const WSAEINVAL = WSABASEERR+22
|
---|
102 | Const WSAEMFILE = WSABASEERR+24
|
---|
103 | Const WSAEWOULDBLOCK = WSABASEERR+35
|
---|
104 | Const WSAEINPROGRESS = WSABASEERR+36
|
---|
105 | Const WSAEALREADY = WSABASEERR+37
|
---|
106 | Const WSAENOTSOCK = WSABASEERR+38
|
---|
107 | Const WSAEDESTADDRREQ = WSABASEERR+39
|
---|
108 | Const WSAEMSGSIZE = WSABASEERR+40
|
---|
109 | Const WSAEPROTOTYPE = WSABASEERR+41
|
---|
110 | Const WSAENOPROTOOPT = WSABASEERR+42
|
---|
111 | Const WSAEPROTONOSUPPORT = WSABASEERR+43
|
---|
112 | Const WSAESOCKTNOSUPPORT = WSABASEERR+44
|
---|
113 | Const WSAEOPNOTSUPP = WSABASEERR+45
|
---|
114 | Const WSAEPFNOSUPPORT = WSABASEERR+46
|
---|
115 | Const WSAEAFNOSUPPORT = WSABASEERR+47
|
---|
116 | Const WSAEADDRINUSE = WSABASEERR+48
|
---|
117 | Const WSAEADDRNOTAVAIL = WSABASEERR+49
|
---|
118 | Const WSAENETDOWN = WSABASEERR+50
|
---|
119 | Const WSAENETUNREACH = WSABASEERR+51
|
---|
120 | Const WSAENETRESET = WSABASEERR+52
|
---|
121 | Const WSAECONNABORTED = WSABASEERR+53
|
---|
122 | Const WSAECONNRESET = WSABASEERR+54
|
---|
123 | Const WSAENOBUFS = WSABASEERR+55
|
---|
124 | Const WSAEISCONN = WSABASEERR+56
|
---|
125 | Const WSAENOTCONN = WSABASEERR+57
|
---|
126 | Const WSAESHUTDOWN = WSABASEERR+58
|
---|
127 | Const WSAETOOMANYREFS = WSABASEERR+59
|
---|
128 | Const WSAETIMEDOUT = WSABASEERR+60
|
---|
129 | Const WSAECONNREFUSED = WSABASEERR+61
|
---|
130 | Const WSAELOOP = WSABASEERR+62
|
---|
131 | Const WSAENAMETOOLONG = WSABASEERR+63
|
---|
132 | Const WSAEHOSTDOWN = WSABASEERR+64
|
---|
133 | Const WSAEHOSTUNREACH = WSABASEERR+65
|
---|
134 | Const WSAENOTEMPTY = WSABASEERR+66
|
---|
135 | Const WSAEPROCLIM = WSABASEERR+67
|
---|
136 | Const WSAEUSERS = WSABASEERR+68
|
---|
137 | Const WSAEDQUOT = WSABASEERR+69
|
---|
138 | Const WSAESTALE = WSABASEERR+70
|
---|
139 | Const WSAEREMOTE = WSABASEERR+71
|
---|
140 | Const WSASYSNOTREADY = WSABASEERR+91
|
---|
141 | Const WSAVERNOTSUPPORTED = WSABASEERR+92
|
---|
142 | Const WSANOTINITIALISED = WSABASEERR+93
|
---|
143 | Const WSAEDISCON = WSABASEERR+101
|
---|
144 | Const WSAENOMORE = WSABASEERR+102
|
---|
145 | Const WSAECANCELLED = WSABASEERR+103
|
---|
146 | Const WSAEINVALIDPROCTABLE = WSABASEERR+104
|
---|
147 | Const WSAEINVALIDPROVIDER = WSABASEERR+105
|
---|
148 | Const WSAEPROVIDERFAILEDINIT =WSABASEERR+106
|
---|
149 | Const WSASYSCALLFAILURE = WSABASEERR+107
|
---|
150 | Const WSASERVICE_NOT_FOUND = WSABASEERR+108
|
---|
151 | Const WSATYPE_NOT_FOUND = WSABASEERR+109
|
---|
152 | Const WSA_E_NO_MORE = WSABASEERR+110
|
---|
153 | Const WSA_E_CANCELLED = WSABASEERR+111
|
---|
154 | Const WSAEREFUSED = WSABASEERR+112
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 | '---------------
|
---|
159 | ' WinSock Types
|
---|
160 | '---------------
|
---|
161 |
|
---|
162 | Type HOSTENT
|
---|
163 | h_name As BytePtr
|
---|
164 | h_aliases As DWordPtr
|
---|
165 | h_addrtype As Integer
|
---|
166 | h_length As Integer
|
---|
167 | h_addr_list As DWordPtr
|
---|
168 | End Type
|
---|
169 |
|
---|
170 | Type SERVENT
|
---|
171 | s_name As BytePtr
|
---|
172 | s_aliases As DWordPtr
|
---|
173 | s_port As Integer
|
---|
174 | s_proto As BytePtr
|
---|
175 | End Type
|
---|
176 |
|
---|
177 | Type SOCKADDR
|
---|
178 | sa_family As Word
|
---|
179 | sa_data[13] As Byte
|
---|
180 | End Type
|
---|
181 | Type SOCKADDR_IN
|
---|
182 | sin_family As Word
|
---|
183 | sin_port As Word
|
---|
184 | sin_addr As DWord
|
---|
185 | sin_zero[7] As Byte
|
---|
186 | End Type
|
---|
187 |
|
---|
188 |
|
---|
189 | '-------------
|
---|
190 | ' WinSock API
|
---|
191 | '-------------
|
---|
192 |
|
---|
193 | Declare Function closesocket Lib "ws2_32.dll" (s As SOCKET) As Long
|
---|
194 | Declare Function connect Lib "ws2_32.dll" (s As SOCKET, ByRef name As Any, namelen As Long) As Long
|
---|
195 | Declare Function gethostbyname Lib "ws2_32.dll" (name As BytePtr) As *HOSTENT
|
---|
196 | Declare Function getservbyname Lib "ws2_32.dll" (name As BytePtr, proto As BytePtr) As *SERVENT
|
---|
197 | Declare Function htonl Lib "ws2_32.dll" (hostlong As DWord) As DWord
|
---|
198 | Declare Function htons Lib "ws2_32.dll" (hostshort As Word) As Word
|
---|
199 | Declare Function recv Lib "ws2_32.dll" (s As SOCKET, buf As BytePtr, length As Long, flags As Long) As Long
|
---|
200 | Declare Function send Lib "ws2_32.dll" (s As SOCKET, buf As BytePtr, length As Long, flags As Long) As Long
|
---|
201 |
|
---|
202 | Const SD_RECEIVE = 0
|
---|
203 | Const SD_SEND = 1
|
---|
204 | Const SD_BOTH = 2
|
---|
205 | Declare Function shutdown Lib "ws2_32.dll" (s As SOCKET, how As Long) As Long
|
---|
206 |
|
---|
207 | Const SOCK_STREAM = 1
|
---|
208 | Const SOCK_DGRAM = 2
|
---|
209 | Const SOCK_RAW = 3
|
---|
210 | Const SOCK_RDM = 4
|
---|
211 | Const SOCK_SEQPACKET = 5
|
---|
212 | Declare Function socket Lib "ws2_32.dll" (af As Long, sokettype As Long, protocol As Long) As SOCKET
|
---|
213 |
|
---|
214 | Declare Function WSACleanup Lib "ws2_32.dll" () As Integer
|
---|
215 |
|
---|
216 | Const WSADESCRIPTION_LEN = 256
|
---|
217 | Const WSASYS_STATUS_LEN = 128
|
---|
218 | Type WSADATA
|
---|
219 | wVersion As Word
|
---|
220 | wHighVersion As Word
|
---|
221 | szDescription[WSADESCRIPTION_LEN] As Byte
|
---|
222 | szSystemStatus[WSASYS_STATUS_LEN] As Byte
|
---|
223 | iMaxSockets As Word
|
---|
224 | iMaxUdpDg As Word
|
---|
225 | lpVendorInfo As BytePtr
|
---|
226 | End Type
|
---|
227 | Declare Function WSAStartup Lib "ws2_32.dll" (wVersionRequested As Word, ByRef lpWSAData As WSADATA) As Long
|
---|
228 |
|
---|
229 |
|
---|
230 | Declare Function accept Lib "ws2_32.dll" (s As SOCKET, ByRef addr As SOCKADDR_IN, ByVal addrlen As Long) As SOCKET
|
---|
231 | Declare Function bind Lib "ws2_32.dll" (s As SOCKET, ByRef sName As SOCKADDR_IN, ByVal namelen As Long) As Long
|
---|
232 | Declare Function ioctlsocket Lib "ws2_32.dll" (s As SOCKET, ByVal cmd As Long, argp As DWord) As Long
|
---|
233 | Declare Function listen Lib "ws2_32.dll" (s As SOCKET, ByVal backlog As Long) As Long
|
---|
234 |
|
---|
235 | Declare Function recvfrom Lib "ws2_32.dll" (s As SOCKET, buf As BytePtr, length As Long, flags As Long, ByRef from As SOCKADDR_IN, fromlen As Long) As Long
|
---|
236 | Declare Function sendto Lib "ws2_32.dll" (s As SOCKET, buf As BytePtr, length As Long, flags As Long, ByRef sTo As SOCKADDR_IN, tolen As Long) As Long
|
---|
237 |
|
---|
238 | Const INADDR_ANY = &h0
|
---|
239 |
|
---|
240 | Declare Function htons Lib "ws2_32.dll" (netshort As Word) As Word
|
---|
241 | Declare Function htonl Lib "ws2_32.dll" (netshort As DWord) As DWord
|
---|
242 | Declare Function ntohs Lib "ws2_32.dll" (netshort As Word) As Word
|
---|
243 | Declare Function ntohl Lib "ws2_32.dll" (netshort As DWord) As DWord
|
---|
244 |
|
---|
245 | #endif '_INC_WINSOCK2
|
---|