Remove two ancient FAQ entries that did more harm than good.
[wine.git] / dlls / winsock / async.c
blob561bacf650b4fcaa4a7b59acf8c77ef9147b981e
1 /* Async WINSOCK DNS services
3 * Copyright (C) 1993,1994,1996,1997 John Brezak, Erik Bos, Alex Korobka.
4 * Copyright (C) 1999 Marcus Meissner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * NOTE: If you make any changes to fix a particular app, make sure
21 * they don't break something else like Netscape or telnet and ftp
22 * clients and servers (www.winsite.com got a lot of those).
24 * FIXME:
25 * - Add WSACancel* and correct handle management. (works rather well for
26 * now without it.)
27 * - Verify & Check all calls for correctness
28 * (currently only WSAGetHostByName*, WSAGetServByPort* calls)
29 * - Check error returns.
30 * - mirc/mirc32 Finger @linux.kernel.org sometimes fails in threaded mode.
31 * (not sure why)
32 * - This implementation did ignore the "NOTE:" section above (since the
33 * whole stuff did not work anyway to other changes).
36 #include "config.h"
37 #include "wine/port.h"
39 #include <stdarg.h>
40 #include <string.h>
41 #include <sys/types.h>
42 #ifdef HAVE_SYS_IPC_H
43 # include <sys/ipc.h>
44 #endif
45 #ifdef HAVE_SYS_IOCTL_H
46 # include <sys/ioctl.h>
47 #endif
48 #ifdef HAVE_SYS_FILIO_H
49 # include <sys/filio.h>
50 #endif
51 #if defined(__svr4__)
52 #include <sys/ioccom.h>
53 #ifdef HAVE_SYS_SOCKIO_H
54 # include <sys/sockio.h>
55 #endif
56 #endif
58 #if defined(__EMX__)
59 # include <sys/so_ioctl.h>
60 #endif
62 #ifdef HAVE_SYS_PARAM_H
63 # include <sys/param.h>
64 #endif
66 #ifdef HAVE_SYS_MSG_H
67 # include <sys/msg.h>
68 #endif
69 #ifdef HAVE_SYS_WAIT_H
70 #include <sys/wait.h>
71 #endif
72 #ifdef HAVE_SYS_SOCKET_H
73 #include <sys/socket.h>
74 #endif
75 #ifdef HAVE_NETINET_IN_H
76 # include <netinet/in.h>
77 #endif
78 #ifdef HAVE_ARPA_INET_H
79 # include <arpa/inet.h>
80 #endif
81 #include <ctype.h>
82 #include <fcntl.h>
83 #include <errno.h>
84 #ifdef HAVE_SYS_ERRNO_H
85 #include <sys/errno.h>
86 #endif
87 #ifdef HAVE_NETDB_H
88 #include <netdb.h>
89 #endif
90 #ifdef HAVE_UNISTD_H
91 # include <unistd.h>
92 #endif
93 #include <stdlib.h>
94 #ifdef HAVE_ARPA_NAMESER_H
95 # include <arpa/nameser.h>
96 #endif
97 #ifdef HAVE_RESOLV_H
98 # include <resolv.h>
99 #endif
101 #include "wine/winbase16.h"
102 #include "windef.h"
103 #include "winbase.h"
104 #include "wingdi.h"
105 #include "winuser.h"
106 #include "winsock2.h"
107 #include "mswsock.h"
108 #include "ws2spi.h"
109 #include "wownt32.h"
110 #include "wine/winsock16.h"
111 #include "winnt.h"
113 #include "wine/debug.h"
115 WINE_DEFAULT_DEBUG_CHANNEL(winsock);
118 /* critical section to protect some non-rentrant net function */
119 CRITICAL_SECTION csWSgetXXXbyYYY;
120 static CRITICAL_SECTION_DEBUG critsect_debug =
122 0, 0, &csWSgetXXXbyYYY,
123 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
124 0, 0, { 0, (DWORD)(__FILE__ ": csWSgetXXXbyYYY") }
126 CRITICAL_SECTION csWSgetXXXbyYYY = { &critsect_debug, -1, 0, 0, 0, 0 };
128 /* protoptypes of some functions in socket.c
130 UINT16 wsaErrno(void);
131 UINT16 wsaHerrno(int errnr);
133 #define AQ_WIN16 0x00
134 #define AQ_WIN32 0x04
135 #define HB_WIN32(hb) (hb->flags & AQ_WIN32)
136 #define AQ_NUMBER 0x00
137 #define AQ_NAME 0x08
138 #define AQ_COPYPTR1 0x10
139 #define AQ_DUPLOWPTR1 0x20
140 #define AQ_MASKPTR1 0x30
141 #define AQ_COPYPTR2 0x40
142 #define AQ_DUPLOWPTR2 0x80
143 #define AQ_MASKPTR2 0xC0
145 #define AQ_GETHOST 0
146 #define AQ_GETPROTO 1
147 #define AQ_GETSERV 2
148 #define AQ_GETMASK 3
150 /* The handles used are pseudo-handles that can be simply casted. */
151 /* 16-bit values are used internally (to be sure handle comparison works right in 16-bit apps). */
152 #define WSA_H32(h16) ((HANDLE)(ULONG_PTR)(h16))
154 /* ----------------------------------- helper functions - */
156 static int list_size(char** l, int item_size)
158 int i,j = 0;
159 if(l)
160 { for(i=0;l[i];i++)
161 j += (item_size) ? item_size : strlen(l[i]) + 1;
162 j += (i + 1) * sizeof(char*); }
163 return j;
166 static int list_dup(char** l_src, char* ref, char* base, int item_size)
168 /* base is either either equal to ref or 0 or SEGPTR */
170 char* p = ref;
171 char** l_to = (char**)ref;
172 int i,j,k;
174 for(j=0;l_src[j];j++) ;
175 p += (j + 1) * sizeof(char*);
176 for(i=0;i<j;i++)
177 { l_to[i] = base + (p - ref);
178 k = ( item_size ) ? item_size : strlen(l_src[i]) + 1;
179 memcpy(p, l_src[i], k); p += k; }
180 l_to[i] = NULL;
181 return (p - ref);
184 /* ----- hostent */
186 static int hostent_size(struct hostent* p_he)
188 int size = 0;
189 if( p_he )
190 { size = sizeof(struct hostent);
191 size += strlen(p_he->h_name) + 1;
192 size += list_size(p_he->h_aliases, 0);
193 size += list_size(p_he->h_addr_list, p_he->h_length ); }
194 return size;
197 /* Copy hostent to p_to, fix up inside pointers using p_base (different for
198 * Win16 (linear vs. segmented). Return -neededsize on overrun.
200 static int WS_copy_he(char *p_to,char *p_base,int t_size,struct hostent* p_he, int flag)
202 char* p_name,*p_aliases,*p_addr,*p;
203 struct ws_hostent16 *p_to16 = (struct ws_hostent16*)p_to;
204 struct WS_hostent *p_to32 = (struct WS_hostent*)p_to;
205 int size = hostent_size(p_he) +
207 (flag & AQ_WIN16) ? sizeof(struct ws_hostent16) : sizeof(struct WS_hostent)
208 - sizeof(struct hostent)
211 if (t_size < size)
212 return -size;
213 p = p_to;
214 p += (flag & AQ_WIN16) ?
215 sizeof(struct ws_hostent16) : sizeof(struct WS_hostent);
216 p_name = p;
217 strcpy(p, p_he->h_name); p += strlen(p) + 1;
218 p_aliases = p;
219 p += list_dup(p_he->h_aliases, p, p_base + (p - (char*)p_to), 0);
220 p_addr = p;
221 list_dup(p_he->h_addr_list, p, p_base + (p - (char*)p_to), p_he->h_length);
223 if (flag & AQ_WIN16)
225 p_to16->h_addrtype = (INT16)p_he->h_addrtype;
226 p_to16->h_length = (INT16)p_he->h_length;
227 p_to16->h_name = (SEGPTR)(p_base + (p_name - p_to));
228 p_to16->h_aliases = (SEGPTR)(p_base + (p_aliases - p_to));
229 p_to16->h_addr_list = (SEGPTR)(p_base + (p_addr - p_to));
231 else
233 p_to32->h_addrtype = p_he->h_addrtype;
234 p_to32->h_length = p_he->h_length;
235 p_to32->h_name = (p_base + (p_name - p_to));
236 p_to32->h_aliases = (char **)(p_base + (p_aliases - p_to));
237 p_to32->h_addr_list = (char **)(p_base + (p_addr - p_to));
240 return size;
243 /* ----- protoent */
245 static int protoent_size(struct protoent* p_pe)
247 int size = 0;
248 if( p_pe )
249 { size = sizeof(struct protoent);
250 size += strlen(p_pe->p_name) + 1;
251 size += list_size(p_pe->p_aliases, 0); }
252 return size;
255 /* Copy protoent to p_to, fix up inside pointers using p_base (different for
256 * Win16 (linear vs. segmented). Return -neededsize on overrun.
258 static int WS_copy_pe(char *p_to,char *p_base,int t_size,struct protoent* p_pe, int flag)
260 char* p_name,*p_aliases,*p;
261 struct ws_protoent16 *p_to16 = (struct ws_protoent16*)p_to;
262 struct WS_protoent *p_to32 = (struct WS_protoent*)p_to;
263 int size = protoent_size(p_pe) +
265 (flag & AQ_WIN16) ? sizeof(struct ws_protoent16) : sizeof(struct WS_protoent)
266 - sizeof(struct protoent)
269 if (t_size < size)
270 return -size;
271 p = p_to;
272 p += (flag & AQ_WIN16) ?
273 sizeof(struct ws_protoent16) : sizeof(struct WS_protoent);
274 p_name = p;
275 strcpy(p, p_pe->p_name); p += strlen(p) + 1;
276 p_aliases = p;
277 list_dup(p_pe->p_aliases, p, p_base + (p - (char*)p_to), 0);
279 if (flag & AQ_WIN16)
281 p_to16->p_proto = (INT16)p_pe->p_proto;
282 p_to16->p_name = (SEGPTR)(p_base) + (p_name - p_to);
283 p_to16->p_aliases = (SEGPTR)((p_base) + (p_aliases - p_to));
285 else
287 p_to32->p_proto = p_pe->p_proto;
288 p_to32->p_name = (p_base) + (p_name - p_to);
289 p_to32->p_aliases = (char **)((p_base) + (p_aliases - p_to));
292 return size;
295 /* ----- servent */
297 static int servent_size(struct servent* p_se)
299 int size = 0;
300 if( p_se ) {
301 size += sizeof(struct servent);
302 size += strlen(p_se->s_proto) + strlen(p_se->s_name) + 2;
303 size += list_size(p_se->s_aliases, 0);
305 return size;
308 /* Copy servent to p_to, fix up inside pointers using p_base (different for
309 * Win16 (linear vs. segmented). Return -neededsize on overrun.
310 * Take care of different Win16/Win32 servent structs (packing !)
312 static int WS_copy_se(char *p_to,char *p_base,int t_size,struct servent* p_se, int flag)
314 char* p_name,*p_aliases,*p_proto,*p;
315 struct ws_servent16 *p_to16 = (struct ws_servent16*)p_to;
316 struct WS_servent *p_to32 = (struct WS_servent*)p_to;
317 int size = servent_size(p_se) +
319 (flag & AQ_WIN16) ? sizeof(struct ws_servent16) : sizeof(struct WS_servent)
320 - sizeof(struct servent)
323 if (t_size < size)
324 return -size;
325 p = p_to;
326 p += (flag & AQ_WIN16) ?
327 sizeof(struct ws_servent16) : sizeof(struct WS_servent);
328 p_name = p;
329 strcpy(p, p_se->s_name); p += strlen(p) + 1;
330 p_proto = p;
331 strcpy(p, p_se->s_proto); p += strlen(p) + 1;
332 p_aliases = p;
333 list_dup(p_se->s_aliases, p, p_base + (p - p_to), 0);
335 if (flag & AQ_WIN16)
337 p_to16->s_port = (INT16)p_se->s_port;
338 p_to16->s_name = (SEGPTR)(p_base + (p_name - p_to));
339 p_to16->s_proto = (SEGPTR)(p_base + (p_proto - p_to));
340 p_to16->s_aliases = (SEGPTR)(p_base + (p_aliases - p_to));
342 else
344 p_to32->s_port = p_se->s_port;
345 p_to32->s_name = (p_base + (p_name - p_to));
346 p_to32->s_proto = (p_base + (p_proto - p_to));
347 p_to32->s_aliases = (char **)(p_base + (p_aliases - p_to));
350 return size;
353 static HANDLE16 __ws_async_handle = 0xdead;
355 /* Generic async query struct. we use symbolic names for the different queries
356 * for readability.
358 typedef struct _async_query {
359 HWND16 hWnd;
360 UINT16 uMsg;
361 LPCSTR ptr1;
362 #define host_name ptr1
363 #define host_addr ptr1
364 #define serv_name ptr1
365 #define proto_name ptr1
366 LPCSTR ptr2;
367 #define serv_proto ptr2
368 int int1;
369 #define host_len int1
370 #define proto_number int1
371 #define serv_port int1
372 int int2;
373 #define host_type int2
374 SEGPTR sbuf;
375 INT16 sbuflen;
377 HANDLE16 async_handle;
378 int flags;
379 int qt;
380 char xbuf[1];
381 } async_query;
384 /****************************************************************************
385 * The async query function.
387 * It is either called as a thread startup routine or directly. It has
388 * to free the passed arg from the process heap and PostMessageA the async
389 * result or the error code.
391 * FIXME:
392 * - errorhandling not verified.
394 static DWORD WINAPI _async_queryfun(LPVOID arg) {
395 async_query *aq = (async_query*)arg;
396 int size = 0;
397 WORD fail = 0;
398 char *targetptr = (HB_WIN32(aq)?(char*)aq->sbuf:(char*)MapSL(aq->sbuf));
400 switch (aq->flags & AQ_GETMASK) {
401 case AQ_GETHOST: {
402 struct hostent *he;
403 char *copy_hostent = targetptr;
404 #ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
405 char *extrabuf;
406 int ebufsize=1024;
407 struct hostent hostentry;
408 int locerr = ENOBUFS;
409 #endif
410 char buf[100];
411 if( !(aq->host_name)) {
412 aq->host_name = buf;
413 if( gethostname( buf, 100) == -1) {
414 fail = WSAENOBUFS; /* appropriate ? */
415 break;
418 #ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
419 he = NULL;
420 extrabuf=HeapAlloc(GetProcessHeap(),0,ebufsize) ;
421 while(extrabuf) {
422 int res = (aq->flags & AQ_NAME) ?
423 gethostbyname_r(aq->host_name,
424 &hostentry, extrabuf, ebufsize, &he, &locerr):
425 gethostbyaddr_r(aq->host_addr,aq->host_len,aq->host_type,
426 &hostentry, extrabuf, ebufsize, &he, &locerr);
427 if( res != ERANGE) break;
428 ebufsize *=2;
429 extrabuf=HeapReAlloc(GetProcessHeap(),0,extrabuf,ebufsize) ;
431 if (!he) fail = ((locerr < 0) ? wsaErrno() : wsaHerrno(locerr));
432 #else
433 EnterCriticalSection( &csWSgetXXXbyYYY );
434 he = (aq->flags & AQ_NAME) ?
435 gethostbyname(aq->host_name):
436 gethostbyaddr(aq->host_addr,aq->host_len,aq->host_type);
437 if (!he) fail = ((h_errno < 0) ? wsaErrno() : wsaHerrno(h_errno));
438 #endif
439 if (he) {
440 size = WS_copy_he(copy_hostent,(char*)aq->sbuf,aq->sbuflen,he,aq->flags);
441 if (size < 0) {
442 fail = WSAENOBUFS;
443 size = -size;
446 #ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
447 HeapFree(GetProcessHeap(),0,extrabuf);
448 #else
449 LeaveCriticalSection( &csWSgetXXXbyYYY );
450 #endif
452 break;
453 case AQ_GETPROTO: {
454 #if defined(HAVE_GETPROTOBYNAME) && defined(HAVE_GETPROTOBYNUMBER)
455 struct protoent *pe;
456 char *copy_protoent = targetptr;
457 EnterCriticalSection( &csWSgetXXXbyYYY );
458 pe = (aq->flags & AQ_NAME)?
459 getprotobyname(aq->proto_name) :
460 getprotobynumber(aq->proto_number);
461 if (pe) {
462 size = WS_copy_pe(copy_protoent,(char*)aq->sbuf,aq->sbuflen,pe,aq->flags);
463 if (size < 0) {
464 fail = WSAENOBUFS;
465 size = -size;
467 } else {
468 if (aq->flags & AQ_NAME)
469 MESSAGE("protocol %s not found; You might want to add "
470 "this to /etc/protocols\n", debugstr_a(aq->proto_name) );
471 else
472 MESSAGE("protocol number %d not found; You might want to add "
473 "this to /etc/protocols\n", aq->proto_number );
474 fail = WSANO_DATA;
476 LeaveCriticalSection( &csWSgetXXXbyYYY );
477 #else
478 fail = WSANO_DATA;
479 #endif
481 break;
482 case AQ_GETSERV: {
483 struct servent *se;
484 char *copy_servent = targetptr;
485 EnterCriticalSection( &csWSgetXXXbyYYY );
486 se = (aq->flags & AQ_NAME)?
487 getservbyname(aq->serv_name,aq->serv_proto) :
488 #ifdef HAVE_GETSERVBYPORT
489 getservbyport(aq->serv_port,aq->serv_proto);
490 #else
491 NULL;
492 #endif
493 if (se) {
494 size = WS_copy_se(copy_servent,(char*)aq->sbuf,aq->sbuflen,se,aq->flags);
495 if (size < 0) {
496 fail = WSAENOBUFS;
497 size = -size;
499 } else {
500 if (aq->flags & AQ_NAME)
501 MESSAGE("service %s protocol %s not found; You might want to add "
502 "this to /etc/services\n", debugstr_a(aq->serv_name) ,
503 aq->serv_proto ? debugstr_a(aq->serv_proto ):"*");
504 else
505 MESSAGE("service on port %d protocol %s not found; You might want to add "
506 "this to /etc/services\n", aq->serv_port,
507 aq->serv_proto ? debugstr_a(aq->serv_proto ):"*");
508 fail = WSANO_DATA;
510 LeaveCriticalSection( &csWSgetXXXbyYYY );
512 break;
514 PostMessageA(HWND_32(aq->hWnd),aq->uMsg,(WPARAM) aq->async_handle,size|(fail<<16));
515 HeapFree(GetProcessHeap(),0,arg);
516 return 0;
519 /****************************************************************************
520 * The main async help function.
522 * It either starts a thread or just calls the function directly for platforms
523 * with no thread support. This relies on the fact that PostMessage() does
524 * not actually call the windowproc before the function returns.
526 static HANDLE16 __WSAsyncDBQuery(
527 HWND hWnd, UINT uMsg,INT int1,LPCSTR ptr1, INT int2, LPCSTR ptr2,
528 void *sbuf, INT sbuflen, UINT flags
531 async_query* aq;
532 char* pto;
533 LPCSTR pfm;
534 int xbuflen = 0;
536 /* allocate buffer to copy protocol- and service name to */
537 /* note: this is done in the calling thread so we can return */
538 /* a decent error code if the Alloc fails */
540 switch (flags & AQ_MASKPTR1) {
541 case 0: break;
542 case AQ_COPYPTR1: xbuflen += int1; break;
543 case AQ_DUPLOWPTR1: xbuflen += strlen(ptr1) + 1; break;
546 switch (flags & AQ_MASKPTR2) {
547 case 0: break;
548 case AQ_COPYPTR2: xbuflen += int2; break;
549 case AQ_DUPLOWPTR2: xbuflen += strlen(ptr2) + 1; break;
552 if(!(aq = HeapAlloc(GetProcessHeap(),0,sizeof(async_query) + xbuflen))) {
553 SetLastError(WSAEWOULDBLOCK); /* insufficient resources */
554 return 0;
557 pto = aq->xbuf;
558 if (ptr1) switch (flags & AQ_MASKPTR1) {
559 case 0: break;
560 case AQ_COPYPTR1: memcpy(pto, ptr1, int1); ptr1 = pto; pto += int1; break;
561 case AQ_DUPLOWPTR1: pfm = ptr1; ptr1 = pto; do *pto++ = tolower(*pfm); while (*pfm++); break;
563 if (ptr2) switch (flags & AQ_MASKPTR2) {
564 case 0: break;
565 case AQ_COPYPTR2: memcpy(pto, ptr2, int2); ptr2 = pto; pto += int2; break;
566 case AQ_DUPLOWPTR2: pfm = ptr2; ptr2 = pto; do *pto++ = tolower(*pfm); while (*pfm++); break;
569 aq->hWnd = HWND_16(hWnd);
570 aq->uMsg = uMsg;
571 aq->int1 = int1;
572 aq->ptr1 = ptr1;
573 aq->int2 = int2;
574 aq->ptr2 = ptr2;
575 /* avoid async_handle = 0 */
576 aq->async_handle = (++__ws_async_handle ? __ws_async_handle : ++__ws_async_handle);
577 aq->flags = flags;
578 aq->sbuf = (SEGPTR)sbuf;
579 aq->sbuflen = sbuflen;
581 #if 1
582 if (CreateThread(NULL,0,_async_queryfun,aq,0,NULL) == INVALID_HANDLE_VALUE)
583 #endif
584 _async_queryfun(aq);
585 return __ws_async_handle;
589 /***********************************************************************
590 * WSAAsyncGetHostByAddr (WINSOCK.102)
592 HANDLE16 WINAPI WSAAsyncGetHostByAddr16(HWND16 hWnd, UINT16 uMsg, LPCSTR addr,
593 INT16 len, INT16 type, SEGPTR sbuf, INT16 buflen)
595 TRACE("hwnd %04x, msg %04x, addr %08x[%i]\n",
596 hWnd, uMsg, (unsigned)addr , len );
597 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,len,addr,type,NULL,
598 (void*)sbuf,buflen,
599 AQ_NUMBER|AQ_COPYPTR1|AQ_WIN16|AQ_GETHOST);
602 /***********************************************************************
603 * WSAAsyncGetHostByAddr (WS2_32.102)
605 HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
606 INT len, INT type, LPSTR sbuf, INT buflen)
608 TRACE("hwnd %p, msg %04x, addr %08x[%i]\n",
609 hWnd, uMsg, (unsigned)addr , len );
610 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,len,addr,type,NULL,sbuf,buflen,
611 AQ_NUMBER|AQ_COPYPTR1|AQ_WIN32|AQ_GETHOST));
614 /***********************************************************************
615 * WSAAsyncGetHostByName (WINSOCK.103)
617 HANDLE16 WINAPI WSAAsyncGetHostByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
618 SEGPTR sbuf, INT16 buflen)
620 TRACE("hwnd %04x, msg %04x, host %s, buffer %i\n",
621 hWnd, uMsg, (name)?name:"<null>", (int)buflen );
622 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,NULL,
623 (void*)sbuf,buflen,
624 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN16|AQ_GETHOST);
627 /***********************************************************************
628 * WSAAsyncGetHostByName (WS2_32.103)
630 HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg, LPCSTR name,
631 LPSTR sbuf, INT buflen)
633 TRACE("hwnd %p, msg %08x, host %s, buffer %i\n",
634 hWnd, uMsg, (name)?name:"<null>", (int)buflen );
635 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,sbuf,buflen,
636 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN32|AQ_GETHOST));
639 /***********************************************************************
640 * WSAAsyncGetProtoByName (WINSOCK.105)
642 HANDLE16 WINAPI WSAAsyncGetProtoByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
643 SEGPTR sbuf, INT16 buflen)
645 TRACE("hwnd %04x, msg %08x, protocol %s\n",
646 hWnd, uMsg, (name)?name:"<null>" );
647 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,NULL,
648 (void*)sbuf,buflen,
649 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN16|AQ_GETPROTO);
652 /***********************************************************************
653 * WSAAsyncGetProtoByName (WS2_32.105)
655 HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg, LPCSTR name,
656 LPSTR sbuf, INT buflen)
658 TRACE("hwnd %p, msg %08x, protocol %s\n",
659 hWnd, uMsg, (name)?name:"<null>" );
660 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,sbuf,buflen,
661 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN32|AQ_GETPROTO));
665 /***********************************************************************
666 * WSAAsyncGetProtoByNumber (WINSOCK.104)
668 HANDLE16 WINAPI WSAAsyncGetProtoByNumber16(HWND16 hWnd,UINT16 uMsg,INT16 number,
669 SEGPTR sbuf, INT16 buflen)
671 TRACE("hwnd %04x, msg %04x, num %i\n", hWnd, uMsg, number );
672 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,number,NULL,0,NULL,
673 (void*)sbuf,buflen,
674 AQ_GETPROTO|AQ_NUMBER|AQ_WIN16);
677 /***********************************************************************
678 * WSAAsyncGetProtoByNumber (WS2_32.104)
680 HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg, INT number,
681 LPSTR sbuf, INT buflen)
683 TRACE("hwnd %p, msg %04x, num %i\n", hWnd, uMsg, number );
684 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,number,NULL,0,NULL,sbuf,buflen,
685 AQ_GETPROTO|AQ_NUMBER|AQ_WIN32));
688 /***********************************************************************
689 * WSAAsyncGetServByName (WINSOCK.107)
691 HANDLE16 WINAPI WSAAsyncGetServByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
692 LPCSTR proto, SEGPTR sbuf, INT16 buflen)
694 TRACE("hwnd %04x, msg %04x, name %s, proto %s\n",
695 hWnd, uMsg, (name)?name:"<null>", (proto)?proto:"<null>");
696 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,proto,
697 (void*)sbuf,buflen,
698 AQ_GETSERV|AQ_NAME|AQ_DUPLOWPTR1|AQ_DUPLOWPTR2|AQ_WIN16);
701 /***********************************************************************
702 * WSAAsyncGetServByName (WS2_32.107)
704 HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name,
705 LPCSTR proto, LPSTR sbuf, INT buflen)
707 TRACE("hwnd %p, msg %04x, name %s, proto %s\n",
708 hWnd, uMsg, (name)?name:"<null>", (proto)?proto:"<null>");
709 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,proto,sbuf,buflen,
710 AQ_GETSERV|AQ_NAME|AQ_DUPLOWPTR1|AQ_DUPLOWPTR2|AQ_WIN32));
713 /***********************************************************************
714 * WSAAsyncGetServByPort (WINSOCK.106)
716 HANDLE16 WINAPI WSAAsyncGetServByPort16(HWND16 hWnd, UINT16 uMsg, INT16 port,
717 LPCSTR proto, SEGPTR sbuf, INT16 buflen)
719 TRACE("hwnd %04x, msg %04x, port %i, proto %s\n",
720 hWnd, uMsg, port, (proto)?proto:"<null>" );
721 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,port,NULL,0,proto,
722 (void*)sbuf,buflen,
723 AQ_GETSERV|AQ_NUMBER|AQ_DUPLOWPTR2|AQ_WIN16);
726 /***********************************************************************
727 * WSAAsyncGetServByPort (WS2_32.106)
729 HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
730 LPCSTR proto, LPSTR sbuf, INT buflen)
732 TRACE("hwnd %p, msg %04x, port %i, proto %s\n",
733 hWnd, uMsg, port, (proto)?proto:"<null>" );
734 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,port,NULL,0,proto,sbuf,buflen,
735 AQ_GETSERV|AQ_NUMBER|AQ_DUPLOWPTR2|AQ_WIN32));
738 /***********************************************************************
739 * WSACancelAsyncRequest (WS2_32.108)
741 INT WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle)
743 FIXME("(%p),stub\n", hAsyncTaskHandle);
744 return 0;
747 /***********************************************************************
748 * WSACancelAsyncRequest (WINSOCK.108)
750 INT16 WINAPI WSACancelAsyncRequest16(HANDLE16 hAsyncTaskHandle)
752 return (INT16)WSACancelAsyncRequest(WSA_H32 (hAsyncTaskHandle));
755 /***********************************************************************
756 * WSApSetPostRoutine (WS2_32.24)
758 INT WINAPI WSApSetPostRoutine(LPWPUPOSTMESSAGE lpPostRoutine)
760 FIXME("(%p), stub !\n", lpPostRoutine);
761 return 0;
764 /***********************************************************************
765 * (WS2_32.25)
767 WSAEVENT WINAPI WPUCompleteOverlappedRequest(SOCKET s, LPWSAOVERLAPPED overlapped,
768 DWORD error, DWORD transferred, LPINT errno)
770 FIXME("(0x%08x,%p,0x%08lx,0x%08lx,%p), stub !\n", s, overlapped, error, transferred, errno);
772 if (errno)
773 *errno = WSAEINVAL;
775 return NULL;