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