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