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