More work on winsock stack (ping is now working)
[reactos.git] / reactos / lib / msafd / misc / sndrcv.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Ancillary Function Driver DLL
4 * FILE: misc/sndrcv.c
5 * PURPOSE: Send/receive routines
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * REVISIONS:
8 * CSH 01/09-2000 Created
9 */
10 #include <msafd.h>
11
12 INT
13 WSPAPI
14 WSPAsyncSelect(
15 IN SOCKET s,
16 IN HWND hWnd,
17 IN UINT wMsg,
18 IN LONG lEvent,
19 OUT LPINT lpErrno)
20 {
21 UNIMPLEMENTED
22
23 return 0;
24 }
25
26
27 INT
28 WSPAPI
29 WSPRecv(
30 IN SOCKET s,
31 IN OUT LPWSABUF lpBuffers,
32 IN DWORD dwBufferCount,
33 OUT LPDWORD lpNumberOfBytesRecvd,
34 IN OUT LPDWORD lpFlags,
35 IN LPWSAOVERLAPPED lpOverlapped,
36 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
37 IN LPWSATHREADID lpThreadId,
38 OUT LPINT lpErrno)
39 {
40 UNIMPLEMENTED
41
42 return 0;
43 }
44
45
46 INT
47 WSPAPI
48 WSPRecvDisconnect(
49 IN SOCKET s,
50 OUT LPWSABUF lpInboundDisconnectData,
51 OUT LPINT lpErrno)
52 {
53 UNIMPLEMENTED
54
55 return 0;
56 }
57
58 INT
59 WSPAPI
60 WSPRecvFrom(
61 IN SOCKET s,
62 IN OUT LPWSABUF lpBuffers,
63 IN DWORD dwBufferCount,
64 OUT LPDWORD lpNumberOfBytesRecvd,
65 IN OUT LPDWORD lpFlags,
66 OUT LPSOCKADDR lpFrom,
67 IN OUT LPINT lpFromLen,
68 IN LPWSAOVERLAPPED lpOverlapped,
69 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
70 IN LPWSATHREADID lpThreadId,
71 OUT LPINT lpErrno)
72 {
73 PFILE_REQUEST_RECVFROM Request;
74 FILE_REPLY_RECVFROM Reply;
75 IO_STATUS_BLOCK Iosb;
76 NTSTATUS Status;
77 DWORD Size;
78
79 AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
80
81 Size = dwBufferCount * sizeof(WSABUF);
82
83 Request = (PFILE_REQUEST_RECVFROM)HeapAlloc(
84 GlobalHeap, 0, sizeof(FILE_REQUEST_RECVFROM) + Size);
85 if (!Request) {
86 AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
87 *lpErrno = WSAENOBUFS;
88 return SOCKET_ERROR;
89 }
90
91 /* Put buffer pointers after request structure */
92 Request->Buffers = (LPWSABUF)(Request + sizeof(FILE_REQUEST_RECVFROM));
93 Request->BufferCount = dwBufferCount;
94 Request->Flags = lpFlags;
95 Request->From = lpFrom;
96 Request->FromLen = lpFromLen;
97
98 RtlCopyMemory(Request->Buffers, lpBuffers, Size);
99
100 Status = NtDeviceIoControlFile((HANDLE)s,
101 NULL,
102 NULL,
103 NULL,
104 &Iosb,
105 IOCTL_AFD_RECVFROM,
106 Request,
107 sizeof(FILE_REQUEST_RECVFROM) + Size,
108 &Reply,
109 sizeof(FILE_REPLY_RECVFROM));
110
111 HeapFree(GlobalHeap, 0, Request);
112
113 if (Status == STATUS_PENDING) {
114 AFD_DbgPrint(MAX_TRACE, ("Waiting on transport.\n"));
115 /* FIXME: Wait only for blocking sockets */
116 Status = NtWaitForSingleObject((HANDLE)s, FALSE, NULL);
117 }
118
119 if (!NT_SUCCESS(Status)) {
120 AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
121 *lpErrno = WSAENOBUFS;
122 return SOCKET_ERROR;
123 }
124
125 AFD_DbgPrint(MAX_TRACE, ("Receive successful (0x%X).\n",
126 Reply.NumberOfBytesRecvd));
127
128 AFD_DbgPrint(MAX_TRACE, ("lpNumberOfBytesRecvd (0x%X).\n",
129 lpNumberOfBytesRecvd));
130
131 *lpNumberOfBytesRecvd = Reply.NumberOfBytesRecvd;
132 //*lpFlags = 0;
133 ((PSOCKADDR_IN)lpFrom)->sin_family = AF_INET;
134 ((PSOCKADDR_IN)lpFrom)->sin_port = 0;
135 ((PSOCKADDR_IN)lpFrom)->sin_addr.S_un.S_addr = 0x0100007F;
136 *lpFromLen = sizeof(SOCKADDR_IN);
137
138 return 0;
139 }
140
141
142 INT
143 WSPAPI
144 WSPSend(
145 IN SOCKET s,
146 IN LPWSABUF lpBuffers,
147 IN DWORD dwBufferCount,
148 OUT LPDWORD lpNumberOfBytesSent,
149 IN DWORD dwFlags,
150 IN LPWSAOVERLAPPED lpOverlapped,
151 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
152 IN LPWSATHREADID lpThreadId,
153 OUT LPINT lpErrno)
154 {
155 UNIMPLEMENTED
156
157 return 0;
158 }
159
160
161 INT
162 WSPAPI
163 WSPSendDisconnect(
164 IN SOCKET s,
165 IN LPWSABUF lpOutboundDisconnectData,
166 OUT LPINT lpErrno)
167 {
168 UNIMPLEMENTED
169
170 return 0;
171 }
172
173
174 INT
175 WSPAPI
176 WSPSendTo(
177 IN SOCKET s,
178 IN LPWSABUF lpBuffers,
179 IN DWORD dwBufferCount,
180 OUT LPDWORD lpNumberOfBytesSent,
181 IN DWORD dwFlags,
182 IN CONST LPSOCKADDR lpTo,
183 IN INT iToLen,
184 IN LPWSAOVERLAPPED lpOverlapped,
185 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
186 IN LPWSATHREADID lpThreadId,
187 OUT LPINT lpErrno)
188 {
189 PFILE_REQUEST_SENDTO Request;
190 FILE_REPLY_SENDTO Reply;
191 IO_STATUS_BLOCK Iosb;
192 NTSTATUS Status;
193 DWORD Size;
194
195 AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
196
197 Size = dwBufferCount * sizeof(WSABUF);
198
199 Request = (PFILE_REQUEST_SENDTO)HeapAlloc(
200 GlobalHeap, 0, sizeof(FILE_REQUEST_SENDTO) + Size);
201 if (!Request) {
202 *lpErrno = WSAENOBUFS;
203 return SOCKET_ERROR;
204 }
205
206 /* Put buffer pointers after request structure */
207 Request->Buffers = (LPWSABUF)(Request + sizeof(FILE_REQUEST_SENDTO));
208 Request->BufferCount = dwBufferCount;
209 Request->Flags = dwFlags;
210 Request->ToLen = iToLen;
211
212 RtlCopyMemory(&Request->To, lpTo, sizeof(SOCKADDR));
213
214 RtlCopyMemory(Request->Buffers, lpBuffers, Size);
215
216 Status = NtDeviceIoControlFile((HANDLE)s,
217 NULL,
218 NULL,
219 NULL,
220 &Iosb,
221 IOCTL_AFD_SENDTO,
222 Request,
223 sizeof(FILE_REQUEST_SENDTO) + Size,
224 &Reply,
225 sizeof(FILE_REPLY_SENDTO));
226
227 HeapFree(GlobalHeap, 0, Request);
228
229 if (Status == STATUS_PENDING) {
230 AFD_DbgPrint(MAX_TRACE, ("Waiting on transport.\n"));
231 /* FIXME: Wait only for blocking sockets */
232 Status = NtWaitForSingleObject((HANDLE)s, FALSE, NULL);
233 }
234
235 if (!NT_SUCCESS(Status)) {
236 AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
237 *lpErrno = WSAENOBUFS;
238 return SOCKET_ERROR;
239 }
240
241 AFD_DbgPrint(MAX_TRACE, ("Send successful.\n"));
242
243 return 0;
244 }
245
246 /* EOF */