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