- fix spec file for FTPFindFirstFileA/W functions
[wine] / dlls / winsock / async.c
1 /* Async WINSOCK DNS services
2  *
3  * Copyright (C) 1993,1994,1996,1997 John Brezak, Erik Bos, Alex Korobka.
4  * Copyright (C) 1999 Marcus Meissner
5  *
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.
10  *
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.
15  *
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
19  *
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).
23  *
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).
34  */
35
36 #include "config.h"
37 #include "wine/port.h"
38
39 #include <string.h>
40 #include <sys/types.h>
41 #ifdef HAVE_SYS_IPC_H
42 # include <sys/ipc.h>
43 #endif
44 #ifdef HAVE_SYS_IOCTL_H
45 # include <sys/ioctl.h>
46 #endif
47 #ifdef HAVE_SYS_FILIO_H
48 # include <sys/filio.h>
49 #endif
50 #if defined(__svr4__)
51 #include <sys/ioccom.h>
52 #ifdef HAVE_SYS_SOCKIO_H
53 # include <sys/sockio.h>
54 #endif
55 #endif
56
57 #if defined(__EMX__)
58 # include <sys/so_ioctl.h>
59 #endif
60
61 #ifdef HAVE_SYS_PARAM_H
62 # include <sys/param.h>
63 #endif
64
65 #ifdef HAVE_SYS_MSG_H
66 # include <sys/msg.h>
67 #endif
68 #ifdef HAVE_SYS_WAIT_H
69 #include <sys/wait.h>
70 #endif
71 #ifdef HAVE_SYS_SOCKET_H
72 #include <sys/socket.h>
73 #endif
74 #ifdef HAVE_NETINET_IN_H
75 # include <netinet/in.h>
76 #endif
77 #ifdef HAVE_ARPA_INET_H
78 # include <arpa/inet.h>
79 #endif
80 #include <ctype.h>
81 #include <fcntl.h>
82 #include <errno.h>
83 #ifdef HAVE_SYS_ERRNO_H
84 #include <sys/errno.h>
85 #endif
86 #ifdef HAVE_NETDB_H
87 #include <netdb.h>
88 #endif
89 #ifdef HAVE_UNISTD_H
90 # include <unistd.h>
91 #endif
92 #include <stdlib.h>
93 #ifdef HAVE_ARPA_NAMESER_H
94 # include <arpa/nameser.h>
95 #endif
96 #ifdef HAVE_RESOLV_H
97 # include <resolv.h>
98 #endif
99
100 #include "wine/winbase16.h"
101 #include "wingdi.h"
102 #include "winuser.h"
103 #include "winsock2.h"
104 #include "ws2spi.h"
105 #include "wownt32.h"
106 #include "wine/winsock16.h"
107 #include "winnt.h"
108
109 #include "wine/debug.h"
110
111 WINE_DEFAULT_DEBUG_CHANNEL(winsock);
112
113
114 /* critical section to protect some non-rentrant net function */
115 CRITICAL_SECTION csWSgetXXXbyYYY = CRITICAL_SECTION_INIT("csWSgetXXXbyYYY");
116
117 /* protoptypes of some functions in socket.c
118  */
119 UINT16 wsaErrno(void);
120 UINT16 wsaHerrno(int errnr);
121
122 #define AQ_WIN16        0x00
123 #define AQ_WIN32        0x04
124 #define HB_WIN32(hb) (hb->flags & AQ_WIN32)
125 #define AQ_NUMBER       0x00
126 #define AQ_NAME         0x08
127 #define AQ_COPYPTR1     0x10
128 #define AQ_DUPLOWPTR1   0x20
129 #define AQ_MASKPTR1     0x30
130 #define AQ_COPYPTR2     0x40
131 #define AQ_DUPLOWPTR2   0x80
132 #define AQ_MASKPTR2     0xC0
133
134 #define AQ_GETHOST      0
135 #define AQ_GETPROTO     1
136 #define AQ_GETSERV      2
137 #define AQ_GETMASK      3
138
139 /* The handles used are pseudo-handles that can be simply casted. */
140 /* 16-bit values are used internally (to be sure handle comparison works right in 16-bit apps). */
141 #define WSA_H32(h16) ((HANDLE)(ULONG_PTR)(h16))
142
143 /* ----------------------------------- helper functions - */
144
145 static int list_size(char** l, int item_size)
146 {
147   int i,j = 0;
148   if(l)
149   { for(i=0;l[i];i++)
150         j += (item_size) ? item_size : strlen(l[i]) + 1;
151     j += (i + 1) * sizeof(char*); }
152   return j;
153 }
154
155 static int list_dup(char** l_src, char* ref, char* base, int item_size)
156 {
157    /* base is either either equal to ref or 0 or SEGPTR */
158
159    char*                p = ref;
160    char**               l_to = (char**)ref;
161    int                  i,j,k;
162
163    for(j=0;l_src[j];j++) ;
164    p += (j + 1) * sizeof(char*);
165    for(i=0;i<j;i++)
166    { l_to[i] = base + (p - ref);
167      k = ( item_size ) ? item_size : strlen(l_src[i]) + 1;
168      memcpy(p, l_src[i], k); p += k; }
169    l_to[i] = NULL;
170    return (p - ref);
171 }
172
173 /* ----- hostent */
174
175 static int hostent_size(struct hostent* p_he)
176 {
177   int size = 0;
178   if( p_he )
179   { size  = sizeof(struct hostent);
180     size += strlen(p_he->h_name) + 1;
181     size += list_size(p_he->h_aliases, 0);
182     size += list_size(p_he->h_addr_list, p_he->h_length ); }
183   return size;
184 }
185
186 /* Copy hostent to p_to, fix up inside pointers using p_base (different for
187  * Win16 (linear vs. segmented). Return -neededsize on overrun.
188  */
189 static int WS_copy_he(char *p_to,char *p_base,int t_size,struct hostent* p_he, int flag)
190 {
191         char* p_name,*p_aliases,*p_addr,*p;
192         struct ws_hostent16 *p_to16 = (struct ws_hostent16*)p_to;
193         struct WS_hostent *p_to32 = (struct WS_hostent*)p_to;
194         int     size = hostent_size(p_he) +
195                 (
196                 (flag & AQ_WIN16) ? sizeof(struct ws_hostent16) : sizeof(struct WS_hostent)
197                 - sizeof(struct hostent)
198                 );
199
200         if (t_size < size)
201                 return -size;
202         p = p_to;
203         p += (flag & AQ_WIN16) ?
204                 sizeof(struct ws_hostent16) : sizeof(struct WS_hostent);
205         p_name = p;
206         strcpy(p, p_he->h_name); p += strlen(p) + 1;
207         p_aliases = p;
208         p += list_dup(p_he->h_aliases, p, p_base + (p - (char*)p_to), 0);
209         p_addr = p;
210         list_dup(p_he->h_addr_list, p, p_base + (p - (char*)p_to), p_he->h_length);
211
212         if (flag & AQ_WIN16)
213         {
214             p_to16->h_addrtype = (INT16)p_he->h_addrtype;
215             p_to16->h_length = (INT16)p_he->h_length;
216             p_to16->h_name = (SEGPTR)(p_base + (p_name - p_to));
217             p_to16->h_aliases = (SEGPTR)(p_base + (p_aliases - p_to));
218             p_to16->h_addr_list = (SEGPTR)(p_base + (p_addr - p_to));
219         }
220         else
221         {
222             p_to32->h_addrtype = p_he->h_addrtype;
223             p_to32->h_length = p_he->h_length;
224             p_to32->h_name = (p_base + (p_name - p_to));
225             p_to32->h_aliases = (char **)(p_base + (p_aliases - p_to));
226             p_to32->h_addr_list = (char **)(p_base + (p_addr - p_to));
227         }
228
229         return size;
230 }
231
232 /* ----- protoent */
233
234 static int protoent_size(struct protoent* p_pe)
235 {
236   int size = 0;
237   if( p_pe )
238   { size  = sizeof(struct protoent);
239     size += strlen(p_pe->p_name) + 1;
240     size += list_size(p_pe->p_aliases, 0); }
241   return size;
242 }
243
244 /* Copy protoent to p_to, fix up inside pointers using p_base (different for
245  * Win16 (linear vs. segmented). Return -neededsize on overrun.
246  */
247 static int WS_copy_pe(char *p_to,char *p_base,int t_size,struct protoent* p_pe, int flag)
248 {
249         char* p_name,*p_aliases,*p;
250         struct ws_protoent16 *p_to16 = (struct ws_protoent16*)p_to;
251         struct WS_protoent *p_to32 = (struct WS_protoent*)p_to;
252         int     size = protoent_size(p_pe) +
253                 (
254                 (flag & AQ_WIN16) ? sizeof(struct ws_protoent16) : sizeof(struct WS_protoent)
255                 - sizeof(struct protoent)
256                 );
257
258         if (t_size < size)
259                 return -size;
260         p = p_to;
261         p += (flag & AQ_WIN16) ?
262                 sizeof(struct ws_protoent16) : sizeof(struct WS_protoent);
263         p_name = p;
264         strcpy(p, p_pe->p_name); p += strlen(p) + 1;
265         p_aliases = p;
266         list_dup(p_pe->p_aliases, p, p_base + (p - (char*)p_to), 0);
267
268         if (flag & AQ_WIN16)
269         {
270             p_to16->p_proto = (INT16)p_pe->p_proto;
271             p_to16->p_name = (SEGPTR)(p_base) + (p_name - p_to);
272             p_to16->p_aliases = (SEGPTR)((p_base) + (p_aliases - p_to));
273         }
274         else
275         {
276             p_to32->p_proto = p_pe->p_proto;
277             p_to32->p_name = (p_base) + (p_name - p_to);
278             p_to32->p_aliases = (char **)((p_base) + (p_aliases - p_to));
279         }
280
281         return size;
282 }
283
284 /* ----- servent */
285
286 static int servent_size(struct servent* p_se)
287 {
288         int size = 0;
289         if( p_se ) {
290                 size += sizeof(struct servent);
291                 size += strlen(p_se->s_proto) + strlen(p_se->s_name) + 2;
292                 size += list_size(p_se->s_aliases, 0);
293         }
294         return size;
295 }
296
297 /* Copy servent to p_to, fix up inside pointers using p_base (different for
298  * Win16 (linear vs. segmented). Return -neededsize on overrun.
299  * Take care of different Win16/Win32 servent structs (packing !)
300  */
301 static int WS_copy_se(char *p_to,char *p_base,int t_size,struct servent* p_se, int flag)
302 {
303         char* p_name,*p_aliases,*p_proto,*p;
304         struct ws_servent16 *p_to16 = (struct ws_servent16*)p_to;
305         struct WS_servent *p_to32 = (struct WS_servent*)p_to;
306         int     size = servent_size(p_se) +
307                 (
308                 (flag & AQ_WIN16) ? sizeof(struct ws_servent16) : sizeof(struct WS_servent)
309                 - sizeof(struct servent)
310                 );
311
312         if (t_size < size)
313                 return -size;
314         p = p_to;
315         p += (flag & AQ_WIN16) ?
316                 sizeof(struct ws_servent16) : sizeof(struct WS_servent);
317         p_name = p;
318         strcpy(p, p_se->s_name); p += strlen(p) + 1;
319         p_proto = p;
320         strcpy(p, p_se->s_proto); p += strlen(p) + 1;
321         p_aliases = p;
322         list_dup(p_se->s_aliases, p, p_base + (p - p_to), 0);
323
324         if (flag & AQ_WIN16)
325         {
326             p_to16->s_port = (INT16)p_se->s_port;
327             p_to16->s_name = (SEGPTR)(p_base + (p_name - p_to));
328             p_to16->s_proto = (SEGPTR)(p_base + (p_proto - p_to));
329             p_to16->s_aliases = (SEGPTR)(p_base + (p_aliases - p_to));
330         }
331         else
332         {
333             p_to32->s_port = p_se->s_port;
334             p_to32->s_name = (p_base + (p_name - p_to));
335             p_to32->s_proto = (p_base + (p_proto - p_to));
336             p_to32->s_aliases = (char **)(p_base + (p_aliases - p_to));
337         }
338
339         return size;
340 }
341
342 static HANDLE16 __ws_async_handle = 0xdead;
343
344 /* Generic async query struct. we use symbolic names for the different queries
345  * for readability.
346  */
347 typedef struct _async_query {
348         HWND16          hWnd;
349         UINT16          uMsg;
350         LPCSTR          ptr1;
351 #define host_name       ptr1
352 #define host_addr       ptr1
353 #define serv_name       ptr1
354 #define proto_name      ptr1
355         LPCSTR          ptr2;
356 #define serv_proto      ptr2
357         int             int1;
358 #define host_len        int1
359 #define proto_number    int1
360 #define serv_port       int1
361         int             int2;
362 #define host_type       int2
363         SEGPTR          sbuf;
364         INT16           sbuflen;
365
366         HANDLE16        async_handle;
367         int             flags;
368         int             qt;
369     char xbuf[1];
370 } async_query;
371
372
373 /****************************************************************************
374  * The async query function.
375  *
376  * It is either called as a thread startup routine or directly. It has
377  * to free the passed arg from the process heap and PostMessageA the async
378  * result or the error code.
379  *
380  * FIXME:
381  *      - errorhandling not verified.
382  */
383 static DWORD WINAPI _async_queryfun(LPVOID arg) {
384         async_query     *aq = (async_query*)arg;
385         int             size = 0;
386         WORD            fail = 0;
387         char            *targetptr = (HB_WIN32(aq)?(char*)aq->sbuf:(char*)MapSL(aq->sbuf));
388
389         switch (aq->flags & AQ_GETMASK) {
390         case AQ_GETHOST: {
391                         struct hostent *he;
392                         char *copy_hostent = targetptr;
393 #if HAVE_LINUX_GETHOSTBYNAME_R_6
394                         char *extrabuf;
395                         int ebufsize=1024;
396                         struct hostent hostentry;
397                         int locerr = ENOBUFS;
398                         he = NULL;
399                         extrabuf=HeapAlloc(GetProcessHeap(),0,ebufsize) ;
400                         while(extrabuf) {
401                             int res = (aq->flags & AQ_NAME) ?
402                                 gethostbyname_r(aq->host_name,
403                                                 &hostentry, extrabuf, ebufsize, &he, &locerr):
404                                 gethostbyaddr_r(aq->host_addr,aq->host_len,aq->host_type,
405                                                 &hostentry, extrabuf, ebufsize, &he, &locerr);
406                             if( res != ERANGE) break;
407                             ebufsize *=2;
408                             extrabuf=HeapReAlloc(GetProcessHeap(),0,extrabuf,ebufsize) ;
409                         }
410                         if (!he) fail = ((locerr < 0) ? wsaErrno() : wsaHerrno(locerr));
411 #else
412                         EnterCriticalSection( &csWSgetXXXbyYYY );
413                         he = (aq->flags & AQ_NAME) ?
414                                 gethostbyname(aq->host_name):
415                                 gethostbyaddr(aq->host_addr,aq->host_len,aq->host_type);
416                         if (!he) fail = ((h_errno < 0) ? wsaErrno() : wsaHerrno(h_errno));
417 #endif
418                         if (he) {
419                                 size = WS_copy_he(copy_hostent,(char*)aq->sbuf,aq->sbuflen,he,aq->flags);
420                                 if (size < 0) {
421                                         fail = WSAENOBUFS;
422                                         size = -size;
423                                 }
424                         }
425 #if HAVE_LINUX_GETHOSTBYNAME_R_6
426                         HeapFree(GetProcessHeap(),0,extrabuf);
427 #else
428                         LeaveCriticalSection( &csWSgetXXXbyYYY );
429 #endif
430                 }
431                 break;
432         case AQ_GETPROTO: {
433 #if defined(HAVE_GETPROTOBYNAME) && defined(HAVE_GETPROTOBYNUMBER)
434                         struct protoent *pe;
435                         char *copy_protoent = targetptr;
436                         EnterCriticalSection( &csWSgetXXXbyYYY );
437                         pe = (aq->flags & AQ_NAME)?
438                                 getprotobyname(aq->proto_name) :
439                                 getprotobynumber(aq->proto_number);
440                         if (pe) {
441                                 size = WS_copy_pe(copy_protoent,(char*)aq->sbuf,aq->sbuflen,pe,aq->flags);
442                                 if (size < 0) {
443                                         fail = WSAENOBUFS;
444                                         size = -size;
445                                 }
446                         } else {
447                             if (aq->flags & AQ_NAME)
448                                 MESSAGE("protocol %s not found; You might want to add "
449                                         "this to /etc/protocols\n", debugstr_a(aq->proto_name) );
450                             else
451                                 MESSAGE("protocol number %d not found; You might want to add "
452                                         "this to /etc/protocols\n", aq->proto_number );
453                             fail = WSANO_DATA;
454                         }
455                         LeaveCriticalSection( &csWSgetXXXbyYYY );
456 #else
457                         fail = WSANO_DATA;
458 #endif
459                 }
460                 break;
461         case AQ_GETSERV: {
462                         struct servent  *se;
463                         char *copy_servent = targetptr;
464                         EnterCriticalSection( &csWSgetXXXbyYYY );
465                         se = (aq->flags & AQ_NAME)?
466                                 getservbyname(aq->serv_name,aq->serv_proto) :
467 #ifdef HAVE_GETSERVBYPORT
468                                 getservbyport(aq->serv_port,aq->serv_proto);
469 #else
470                                 NULL;
471 #endif
472                         if (se) {
473                                 size = WS_copy_se(copy_servent,(char*)aq->sbuf,aq->sbuflen,se,aq->flags);
474                                 if (size < 0) {
475                                         fail = WSAENOBUFS;
476                                         size = -size;
477                                 }
478                         } else {
479                             if (aq->flags & AQ_NAME)
480                                 MESSAGE("service %s protocol %s not found; You might want to add "
481                                         "this to /etc/services\n", debugstr_a(aq->serv_name) ,
482                                         aq->serv_proto ? debugstr_a(aq->serv_proto ):"*");
483                             else
484                                 MESSAGE("service on port %d protocol %s not found; You might want to add "
485                                         "this to /etc/services\n", aq->serv_port,
486                                         aq->serv_proto ? debugstr_a(aq->serv_proto ):"*");
487                             fail = WSANO_DATA;
488                         }
489                         LeaveCriticalSection( &csWSgetXXXbyYYY );
490                 }
491                 break;
492         }
493         PostMessageA(HWND_32(aq->hWnd),aq->uMsg,(WPARAM) aq->async_handle,size|(fail<<16));
494         HeapFree(GetProcessHeap(),0,arg);
495         return 0;
496 }
497
498 /****************************************************************************
499  * The main async help function.
500  *
501  * It either starts a thread or just calls the function directly for platforms
502  * with no thread support. This relies on the fact that PostMessage() does
503  * not actually call the windowproc before the function returns.
504  */
505 static HANDLE16 __WSAsyncDBQuery(
506         HWND hWnd, UINT uMsg,INT int1,LPCSTR ptr1, INT int2, LPCSTR ptr2,
507         void *sbuf, INT sbuflen, UINT flags
508 )
509 {
510         async_query*    aq;
511         char*           pto;
512         LPCSTR          pfm;
513         int             xbuflen = 0;
514
515         /* allocate buffer to copy protocol- and service name to */
516         /* note: this is done in the calling thread so we can return */
517         /* a decent error code if the Alloc fails */
518
519         switch (flags & AQ_MASKPTR1) {
520         case 0:                                                 break;
521         case AQ_COPYPTR1:       xbuflen += int1;                break;
522         case AQ_DUPLOWPTR1:     xbuflen += strlen(ptr1) + 1;    break;
523         }
524
525         switch (flags & AQ_MASKPTR2) {
526         case 0:                                                 break;
527         case AQ_COPYPTR2:       xbuflen += int2;                break;
528         case AQ_DUPLOWPTR2:     xbuflen += strlen(ptr2) + 1;    break;
529         }
530
531         if(!(aq = HeapAlloc(GetProcessHeap(),0,sizeof(async_query) + xbuflen))) {
532                 SetLastError(WSAEWOULDBLOCK); /* insufficient resources */
533                 return 0;
534         }
535
536         pto = aq->xbuf;
537         if (ptr1) switch (flags & AQ_MASKPTR1) {
538         case 0:                                                                                 break;
539         case AQ_COPYPTR1:   memcpy(pto, ptr1, int1); ptr1 = pto; pto += int1;                   break;
540         case AQ_DUPLOWPTR1: pfm = ptr1; ptr1 = pto; do *pto++ = tolower(*pfm); while (*pfm++);  break;
541         }
542         if (ptr2) switch (flags & AQ_MASKPTR2) {
543         case 0:                                                                                 break;
544         case AQ_COPYPTR2:   memcpy(pto, ptr2, int2); ptr2 = pto; pto += int2;                   break;
545         case AQ_DUPLOWPTR2: pfm = ptr2; ptr2 = pto; do *pto++ = tolower(*pfm); while (*pfm++);  break;
546         }
547
548         aq->hWnd        = HWND_16(hWnd);
549         aq->uMsg        = uMsg;
550         aq->int1        = int1;
551         aq->ptr1        = ptr1;
552         aq->int2        = int2;
553         aq->ptr2        = ptr2;
554         /* avoid async_handle = 0 */
555         aq->async_handle = (++__ws_async_handle ? __ws_async_handle : ++__ws_async_handle);
556         aq->flags       = flags;
557         aq->sbuf        = (SEGPTR)sbuf;
558         aq->sbuflen     = sbuflen;
559
560 #if 1
561         if (CreateThread(NULL,0,_async_queryfun,aq,0,NULL) == INVALID_HANDLE_VALUE)
562 #endif
563                 _async_queryfun(aq);
564         return __ws_async_handle;
565 }
566
567
568 /***********************************************************************
569  *       WSAAsyncGetHostByAddr  (WINSOCK.102)
570  */
571 HANDLE16 WINAPI WSAAsyncGetHostByAddr16(HWND16 hWnd, UINT16 uMsg, LPCSTR addr,
572                                INT16 len, INT16 type, SEGPTR sbuf, INT16 buflen)
573 {
574         TRACE("hwnd %04x, msg %04x, addr %08x[%i]\n",
575                hWnd, uMsg, (unsigned)addr , len );
576         return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,len,addr,type,NULL,
577                                 (void*)sbuf,buflen,
578                                 AQ_NUMBER|AQ_COPYPTR1|AQ_WIN16|AQ_GETHOST);
579 }
580
581 /***********************************************************************
582  *       WSAAsyncGetHostByAddr        (WS2_32.102)
583  */
584 HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
585                                INT len, INT type, LPSTR sbuf, INT buflen)
586 {
587         TRACE("hwnd %p, msg %04x, addr %08x[%i]\n",
588                hWnd, uMsg, (unsigned)addr , len );
589         return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,len,addr,type,NULL,sbuf,buflen,
590                                 AQ_NUMBER|AQ_COPYPTR1|AQ_WIN32|AQ_GETHOST));
591 }
592
593 /***********************************************************************
594  *       WSAAsyncGetHostByName  (WINSOCK.103)
595  */
596 HANDLE16 WINAPI WSAAsyncGetHostByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
597                                       SEGPTR sbuf, INT16 buflen)
598 {
599         TRACE("hwnd %04x, msg %04x, host %s, buffer %i\n",
600               hWnd, uMsg, (name)?name:"<null>", (int)buflen );
601         return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,NULL,
602                                 (void*)sbuf,buflen,
603                                 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN16|AQ_GETHOST);
604 }
605
606 /***********************************************************************
607  *       WSAAsyncGetHostByName  (WS2_32.103)
608  */
609 HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg, LPCSTR name,
610                                         LPSTR sbuf, INT buflen)
611 {
612         TRACE("hwnd %p, msg %08x, host %s, buffer %i\n",
613                hWnd, uMsg, (name)?name:"<null>", (int)buflen );
614         return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,sbuf,buflen,
615                                 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN32|AQ_GETHOST));
616 }
617
618 /***********************************************************************
619  *       WSAAsyncGetProtoByName (WINSOCK.105)
620  */
621 HANDLE16 WINAPI WSAAsyncGetProtoByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
622                                          SEGPTR sbuf, INT16 buflen)
623 {
624         TRACE("hwnd %04x, msg %08x, protocol %s\n",
625                hWnd, uMsg, (name)?name:"<null>" );
626         return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,NULL,
627                                 (void*)sbuf,buflen,
628                                 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN16|AQ_GETPROTO);
629 }
630
631 /***********************************************************************
632  *       WSAAsyncGetProtoByName       (WS2_32.105)
633  */
634 HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg, LPCSTR name,
635                                          LPSTR sbuf, INT buflen)
636 {
637         TRACE("hwnd %p, msg %08x, protocol %s\n",
638                hWnd, uMsg, (name)?name:"<null>" );
639         return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,sbuf,buflen,
640                                 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN32|AQ_GETPROTO));
641 }
642
643
644 /***********************************************************************
645  *       WSAAsyncGetProtoByNumber       (WINSOCK.104)
646  */
647 HANDLE16 WINAPI WSAAsyncGetProtoByNumber16(HWND16 hWnd,UINT16 uMsg,INT16 number,
648                                            SEGPTR sbuf, INT16 buflen)
649 {
650         TRACE("hwnd %04x, msg %04x, num %i\n", hWnd, uMsg, number );
651         return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,number,NULL,0,NULL,
652                                 (void*)sbuf,buflen,
653                                 AQ_GETPROTO|AQ_NUMBER|AQ_WIN16);
654 }
655
656 /***********************************************************************
657  *       WSAAsyncGetProtoByNumber     (WS2_32.104)
658  */
659 HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg, INT number,
660                                            LPSTR sbuf, INT buflen)
661 {
662         TRACE("hwnd %p, msg %04x, num %i\n", hWnd, uMsg, number );
663         return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,number,NULL,0,NULL,sbuf,buflen,
664                                 AQ_GETPROTO|AQ_NUMBER|AQ_WIN32));
665 }
666
667 /***********************************************************************
668  *       WSAAsyncGetServByName  (WINSOCK.107)
669  */
670 HANDLE16 WINAPI WSAAsyncGetServByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
671                                         LPCSTR proto, SEGPTR sbuf, INT16 buflen)
672 {
673         TRACE("hwnd %04x, msg %04x, name %s, proto %s\n",
674                hWnd, uMsg, (name)?name:"<null>", (proto)?proto:"<null>");
675         return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,proto,
676                                 (void*)sbuf,buflen,
677                                 AQ_GETSERV|AQ_NAME|AQ_DUPLOWPTR1|AQ_DUPLOWPTR2|AQ_WIN16);
678 }
679
680 /***********************************************************************
681  *       WSAAsyncGetServByName        (WS2_32.107)
682  */
683 HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name,
684                                         LPCSTR proto, LPSTR sbuf, INT buflen)
685 {
686         TRACE("hwnd %p, msg %04x, name %s, proto %s\n",
687                hWnd, uMsg, (name)?name:"<null>", (proto)?proto:"<null>");
688         return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,proto,sbuf,buflen,
689                                 AQ_GETSERV|AQ_NAME|AQ_DUPLOWPTR1|AQ_DUPLOWPTR2|AQ_WIN32));
690 }
691
692 /***********************************************************************
693  *       WSAAsyncGetServByPort  (WINSOCK.106)
694  */
695 HANDLE16 WINAPI WSAAsyncGetServByPort16(HWND16 hWnd, UINT16 uMsg, INT16 port,
696                                         LPCSTR proto, SEGPTR sbuf, INT16 buflen)
697 {
698         TRACE("hwnd %04x, msg %04x, port %i, proto %s\n",
699                hWnd, uMsg, port, (proto)?proto:"<null>" );
700         return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,port,NULL,0,proto,
701                                 (void*)sbuf,buflen,
702                                 AQ_GETSERV|AQ_NUMBER|AQ_DUPLOWPTR2|AQ_WIN16);
703 }
704
705 /***********************************************************************
706  *       WSAAsyncGetServByPort        (WS2_32.106)
707  */
708 HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
709                                         LPCSTR proto, LPSTR sbuf, INT buflen)
710 {
711         TRACE("hwnd %p, msg %04x, port %i, proto %s\n",
712                hWnd, uMsg, port, (proto)?proto:"<null>" );
713         return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,port,NULL,0,proto,sbuf,buflen,
714                                 AQ_GETSERV|AQ_NUMBER|AQ_DUPLOWPTR2|AQ_WIN32));
715 }
716
717 /***********************************************************************
718  *       WSACancelAsyncRequest  (WS2_32.108)
719  */
720 INT WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle)
721 {
722     FIXME("(%p),stub\n", hAsyncTaskHandle);
723     return 0;
724 }
725
726 /***********************************************************************
727  *       WSACancelAsyncRequest  (WINSOCK.108)
728  */
729 INT16 WINAPI WSACancelAsyncRequest16(HANDLE16 hAsyncTaskHandle)
730 {
731     return (INT16)WSACancelAsyncRequest(WSA_H32 (hAsyncTaskHandle));
732 }
733
734 /***********************************************************************
735  *       WSApSetPostRoutine     (WS2_32.24)
736  */
737 INT WINAPI WSApSetPostRoutine(LPWPUPOSTMESSAGE lpPostRoutine)
738 {
739     FIXME("(%p), stub !\n", lpPostRoutine);
740     return 0;
741 }