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