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