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