- Start of fixing CreateProcess's problems. Implemented the console creation as...
[reactos.git] / reactos / drivers / net / wshtcpip / wshtcpip.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock Helper DLL for TCP/IP
4 * FILE: wshtcpip.c
5 * PURPOSE: DLL entry
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * REVISIONS:
8 * CSH 01/09-2000 Created
9 */
10 #include <wshtcpip.h>
11 #define NDEBUG
12 #include <debug.h>
13
14 BOOL
15 EXPORT
16 DllMain(HANDLE hInstDll,
17 ULONG dwReason,
18 PVOID Reserved)
19 {
20 DPRINT("DllMain of wshtcpip.dll\n");
21
22 switch (dwReason) {
23 case DLL_PROCESS_ATTACH:
24 /* Don't need thread attach notifications
25 so disable them to improve performance */
26 DisableThreadLibraryCalls(hInstDll);
27 break;
28
29 case DLL_THREAD_ATTACH:
30 break;
31
32 case DLL_THREAD_DETACH:
33 break;
34
35 case DLL_PROCESS_DETACH:
36 break;
37 }
38 return TRUE;
39 }
40
41
42 INT
43 EXPORT
44 WSHAddressToString(
45 IN LPSOCKADDR Address,
46 IN INT AddressLength,
47 IN LPWSAPROTOCOL_INFOW ProtocolInfo OPTIONAL,
48 OUT LPWSTR AddressString,
49 IN OUT LPDWORD AddressStringLength)
50 {
51 UNIMPLEMENTED
52
53 return 0;
54 }
55
56
57 INT
58 EXPORT
59 WSHEnumProtocols(
60 IN LPINT lpiProtocols OPTIONAL,
61 IN LPWSTR lpTransportKeyName,
62 IN OUT LPVOID lpProtocolBuffer,
63 IN OUT LPDWORD lpdwBufferLength)
64 {
65 UNIMPLEMENTED
66
67 return 0;
68 }
69
70
71 INT
72 EXPORT
73 WSHGetBroadcastSockaddr(
74 IN PVOID HelperDllSocketContext,
75 OUT PSOCKADDR Sockaddr,
76 OUT PINT SockaddrLength)
77 {
78 UNIMPLEMENTED
79
80 return 0;
81 }
82
83
84 INT
85 EXPORT
86 WSHGetProviderGuid(
87 IN LPWSTR ProviderName,
88 OUT LPGUID ProviderGuid)
89 {
90 UNIMPLEMENTED
91
92 return 0;
93 }
94
95
96 INT
97 EXPORT
98 WSHGetSockaddrType(
99 IN PSOCKADDR Sockaddr,
100 IN DWORD SockaddrLength,
101 OUT PSOCKADDR_INFO SockaddrInfo)
102 {
103 UNIMPLEMENTED
104
105 return 0;
106 }
107
108
109 INT
110 EXPORT
111 WSHGetSocketInformation(
112 IN PVOID HelperDllSocketContext,
113 IN SOCKET SocketHandle,
114 IN HANDLE TdiAddressObjectHandle,
115 IN HANDLE TdiConnectionObjectHandle,
116 IN INT Level,
117 IN INT OptionName,
118 OUT PCHAR OptionValue,
119 OUT INT OptionLength)
120 {
121 UNIMPLEMENTED
122
123 return 0;
124 }
125
126
127 INT
128 EXPORT
129 WSHGetWildcardSockaddr(
130 IN PVOID HelperDllSocketContext,
131 OUT PSOCKADDR Sockaddr,
132 OUT PINT SockaddrLength)
133 {
134 RtlZeroMemory((PVOID)Sockaddr, *SockaddrLength);
135 Sockaddr->sa_family = AF_INET;
136 return 0;
137 }
138
139
140 DWORD
141 EXPORT
142 WSHGetWinsockMapping(
143 OUT PWINSOCK_MAPPING Mapping,
144 IN DWORD MappingLength)
145 {
146 UNIMPLEMENTED
147
148 return 0;
149 }
150
151
152 INT
153 EXPORT
154 WSHGetWSAProtocolInfo(
155 IN LPWSTR ProviderName,
156 OUT LPWSAPROTOCOL_INFOW *ProtocolInfo,
157 OUT LPDWORD ProtocolInfoEntries)
158 {
159 UNIMPLEMENTED
160
161 return 0;
162 }
163
164
165 INT
166 EXPORT
167 WSHIoctl(
168 IN PVOID HelperDllSocketContext,
169 IN SOCKET SocketHandle,
170 IN HANDLE TdiAddressObjectHandle,
171 IN HANDLE TdiConnectionObjectHandle,
172 IN DWORD IoControlCode,
173 IN LPVOID InputBuffer,
174 IN DWORD InputBufferLength,
175 IN LPVOID OutputBuffer,
176 IN DWORD OutputBufferLength,
177 OUT LPDWORD NumberOfBytesReturned,
178 IN LPWSAOVERLAPPED Overlapped,
179 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine,
180 OUT LPBOOL NeedsCompletion)
181 {
182 UNIMPLEMENTED
183
184 return 0;
185 }
186
187
188 INT
189 EXPORT
190 WSHJoinLeaf(
191 IN PVOID HelperDllSocketContext,
192 IN SOCKET SocketHandle,
193 IN HANDLE TdiAddressObjectHandle,
194 IN HANDLE TdiConnectionObjectHandle,
195 IN PVOID LeafHelperDllSocketContext,
196 IN SOCKET LeafSocketHandle,
197 IN PSOCKADDR Sockaddr,
198 IN DWORD SockaddrLength,
199 IN LPWSABUF CallerData,
200 IN LPWSABUF CalleeData,
201 IN LPQOS SocketQOS,
202 IN LPQOS GroupQOS,
203 IN DWORD Flags)
204 {
205 UNIMPLEMENTED
206
207 return 0;
208 }
209
210
211 INT
212 EXPORT
213 WSHNotify(
214 IN PVOID HelperDllSocketContext,
215 IN SOCKET SocketHandle,
216 IN HANDLE TdiAddressObjectHandle,
217 IN HANDLE TdiConnectionObjectHandle,
218 IN DWORD NotifyEvent)
219 {
220 UNIMPLEMENTED
221
222 return 0;
223 }
224
225
226 INT
227 EXPORT
228 WSHOpenSocket(
229 IN OUT PINT AddressFamily,
230 IN OUT PINT SocketType,
231 IN OUT PINT Protocol,
232 OUT PUNICODE_STRING TransportDeviceName,
233 OUT PVOID HelperDllSocketContext,
234 OUT PDWORD NotificationEvents)
235 /*
236 * FUNCTION: Opens a socket
237 */
238 {
239 return WSHOpenSocket2(AddressFamily,
240 SocketType,
241 Protocol,
242 0,
243 0,
244 TransportDeviceName,
245 HelperDllSocketContext,
246 NotificationEvents);
247 }
248
249
250 INT
251 EXPORT
252 WSHOpenSocket2(
253 OUT PINT AddressFamily,
254 IN OUT PINT SocketType,
255 IN OUT PINT Protocol,
256 IN GROUP Group,
257 IN DWORD Flags,
258 OUT PUNICODE_STRING TransportDeviceName,
259 OUT PVOID *HelperDllSocketContext,
260 OUT PDWORD NotificationEvents)
261 /*
262 * FUNCTION: Opens a socket
263 * ARGUMENTS:
264 * AddressFamily = Address of buffer with address family (updated)
265 * SocketType = Address of buffer with type of socket (updated)
266 * Protocol = Address of buffer with protocol number (updated)
267 * Group = Socket group
268 * Flags = Socket flags
269 * TransportDeviceName = Address of buffer to place name of transport device
270 * HelperDllSocketContext = Address of buffer to place socket context pointer
271 * NotificationEvents = Address of buffer to place flags for event notification
272 * RETURNS:
273 * Status of operation
274 * NOTES:
275 * Mapping tripple is returned in an canonicalized form
276 */
277 {
278 PSOCKET_CONTEXT Context;
279 UNICODE_STRING String;
280 UNICODE_STRING TcpDeviceName = RTL_CONSTANT_STRING(DD_TCP_DEVICE_NAME);
281 UNICODE_STRING UdpDeviceName = RTL_CONSTANT_STRING(DD_UDP_DEVICE_NAME);
282 UNICODE_STRING RawDeviceName = RTL_CONSTANT_STRING(DD_RAW_IP_DEVICE_NAME);
283 NTSTATUS Status;
284
285 DPRINT("");
286
287 switch (*SocketType) {
288 case SOCK_STREAM:
289 String = TcpDeviceName;
290 break;
291
292 case SOCK_DGRAM:
293 String = UdpDeviceName;
294 break;
295
296 case SOCK_RAW:
297 if ((*Protocol < 0) || (*Protocol > 255))
298 return WSAEINVAL;
299
300 String = RawDeviceName;
301 break;
302
303 default:
304 return WSAEINVAL;
305 }
306
307 RtlInitUnicodeString(TransportDeviceName, NULL);
308
309 TransportDeviceName->MaximumLength = String.Length + /* Transport device name */
310 (4 * sizeof(WCHAR) + /* Separator and protocol */
311 sizeof(UNICODE_NULL)); /* Terminating null */
312
313 TransportDeviceName->Buffer = HeapAlloc(
314 GetProcessHeap(),
315 0,
316 TransportDeviceName->MaximumLength);
317
318 if (!TransportDeviceName->Buffer)
319 return WSAENOBUFS;
320
321 /* Append the transport device name */
322 Status = RtlAppendUnicodeStringToString(TransportDeviceName, &String);
323
324 if (*SocketType == SOCK_RAW) {
325 /* Append a separator */
326 TransportDeviceName->Buffer[TransportDeviceName->Length / sizeof(WCHAR)] = OBJ_NAME_PATH_SEPARATOR;
327 TransportDeviceName->Length += sizeof(WCHAR);
328 TransportDeviceName->Buffer[TransportDeviceName->Length / sizeof(WCHAR)] = UNICODE_NULL;
329
330 /* Append the protocol number */
331 String.Buffer = TransportDeviceName->Buffer + (TransportDeviceName->Length / sizeof(WCHAR));
332 String.Length = 0;
333 String.MaximumLength = TransportDeviceName->MaximumLength - TransportDeviceName->Length;
334
335 Status = RtlIntegerToUnicodeString((ULONG)*Protocol, 10, &String);
336
337 TransportDeviceName->Length += String.Length;
338 }
339
340 /* Setup a socket context area */
341
342 Context = HeapAlloc(GetProcessHeap(), 0, sizeof(SOCKET_CONTEXT));
343 if (!Context) {
344 RtlFreeUnicodeString(TransportDeviceName);
345 return WSAENOBUFS;
346 }
347
348 Context->AddressFamily = *AddressFamily;
349 Context->SocketType = *SocketType;
350 Context->Protocol = *Protocol;
351 Context->Flags = Flags;
352
353 *HelperDllSocketContext = Context;
354
355 return NO_ERROR;
356 }
357
358
359 INT
360 EXPORT
361 WSHSetSocketInformation(
362 IN PVOID HelperDllSocketContext,
363 IN SOCKET SocketHandle,
364 IN HANDLE TdiAddressObjectHandle,
365 IN HANDLE TdiConnectionObjectHandle,
366 IN INT Level,
367 IN INT OptionName,
368 IN PCHAR OptionValue,
369 IN INT OptionLength)
370 {
371 UNIMPLEMENTED
372
373 return 0;
374 }
375
376
377 INT
378 EXPORT
379 WSHStringToAddress(
380 IN LPWSTR AddressString,
381 IN DWORD AddressFamily,
382 IN LPWSAPROTOCOL_INFOW ProtocolInfo OPTIONAL,
383 OUT LPSOCKADDR Address,
384 IN OUT LPDWORD AddressStringLength)
385 {
386 UNIMPLEMENTED
387
388 return 0;
389 }
390
391 /* EOF */