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