push ab3cc77eb114d2bd400734a9dccad24563f936a6
[wine/hacks.git] / dlls / ws2_32 / async.c
blobef7be5f6b6752b5bbd9ce1bd6c2fc0284cfaf234
1 /* Async WINSOCK DNS services
3 * Copyright (C) 1993,1994,1996,1997 John Brezak, Erik Bos, Alex Korobka.
4 * Copyright (C) 1999 Marcus Meissner
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.
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.
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
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).
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).
36 #include "config.h"
37 #include "wine/port.h"
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
58 #if defined(__EMX__)
59 # include <sys/so_ioctl.h>
60 #endif
62 #ifdef HAVE_SYS_PARAM_H
63 # include <sys/param.h>
64 #endif
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
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"
112 #include "wine/debug.h"
114 WINE_DEFAULT_DEBUG_CHANNEL(winsock);
117 /* critical section to protect some non-rentrant net function */
118 CRITICAL_SECTION csWSgetXXXbyYYY;
119 static CRITICAL_SECTION_DEBUG critsect_debug =
121 0, 0, &csWSgetXXXbyYYY,
122 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
123 0, 0, { (DWORD_PTR)(__FILE__ ": csWSgetXXXbyYYY") }
125 CRITICAL_SECTION csWSgetXXXbyYYY = { &critsect_debug, -1, 0, 0, 0, 0 };
127 /* protoptypes of some functions in socket.c
129 UINT16 wsaErrno(void);
130 UINT16 wsaHerrno(int errnr);
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
144 #define AQ_GETHOST 0
145 #define AQ_GETPROTO 1
146 #define AQ_GETSERV 2
147 #define AQ_GETMASK 3
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))
153 /* ----------------------------------- helper functions - */
155 static int list_size(char** l, int item_size)
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;
165 static int list_dup(char** l_src, char* ref, char* base, int item_size)
167 /* base is either either equal to ref or 0 or SEGPTR */
169 char* p = ref;
170 char** l_to = (char**)ref;
171 int i,j,k;
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);
183 /* ----- hostent */
185 static int hostent_size(struct hostent* p_he)
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;
196 /* Copy hostent to p_to, fix up inside pointers using p_base (different for
197 * Win16 (linear vs. segmented). Return -neededsize on overrun.
199 static int WS_copy_he(char *p_to,char *p_base,int t_size,struct hostent* p_he, int flag)
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) +
206 (flag & AQ_WIN16) ? sizeof(struct ws_hostent16) : sizeof(struct WS_hostent)
207 - sizeof(struct hostent)
210 if (t_size < size)
211 return -size;
212 p = p_to;
213 p += (flag & AQ_WIN16) ?
214 sizeof(struct ws_hostent16) : sizeof(struct WS_hostent);
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 - (char*)p_to), 0);
219 p_addr = p;
220 list_dup(p_he->h_addr_list, p, p_base + (p - (char*)p_to), p_he->h_length);
222 if (flag & AQ_WIN16)
224 p_to16->h_addrtype = (INT16)p_he->h_addrtype;
225 p_to16->h_length = (INT16)p_he->h_length;
226 p_to16->h_name = (SEGPTR)(p_base + (p_name - p_to));
227 p_to16->h_aliases = (SEGPTR)(p_base + (p_aliases - p_to));
228 p_to16->h_addr_list = (SEGPTR)(p_base + (p_addr - p_to));
230 else
232 p_to32->h_addrtype = p_he->h_addrtype;
233 p_to32->h_length = p_he->h_length;
234 p_to32->h_name = (p_base + (p_name - p_to));
235 p_to32->h_aliases = (char **)(p_base + (p_aliases - p_to));
236 p_to32->h_addr_list = (char **)(p_base + (p_addr - p_to));
239 return size;
242 /* ----- protoent */
244 static int protoent_size(struct protoent* p_pe)
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;
254 /* Copy protoent to p_to, fix up inside pointers using p_base (different for
255 * Win16 (linear vs. segmented). Return -neededsize on overrun.
257 static int WS_copy_pe(char *p_to,char *p_base,int t_size,struct protoent* p_pe, int flag)
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) +
264 (flag & AQ_WIN16) ? sizeof(struct ws_protoent16) : sizeof(struct WS_protoent)
265 - sizeof(struct protoent)
268 if (t_size < size)
269 return -size;
270 p = p_to;
271 p += (flag & AQ_WIN16) ?
272 sizeof(struct ws_protoent16) : sizeof(struct WS_protoent);
273 p_name = p;
274 strcpy(p, p_pe->p_name); p += strlen(p) + 1;
275 p_aliases = p;
276 list_dup(p_pe->p_aliases, p, p_base + (p - (char*)p_to), 0);
278 if (flag & AQ_WIN16)
280 p_to16->p_proto = (INT16)p_pe->p_proto;
281 p_to16->p_name = (SEGPTR)(p_base) + (p_name - p_to);
282 p_to16->p_aliases = (SEGPTR)((p_base) + (p_aliases - p_to));
284 else
286 p_to32->p_proto = p_pe->p_proto;
287 p_to32->p_name = (p_base) + (p_name - p_to);
288 p_to32->p_aliases = (char **)((p_base) + (p_aliases - p_to));
291 return size;
294 /* ----- servent */
296 static int servent_size(struct servent* p_se)
298 int size = 0;
299 if( p_se ) {
300 size += sizeof(struct servent);
301 size += strlen(p_se->s_proto) + strlen(p_se->s_name) + 2;
302 size += list_size(p_se->s_aliases, 0);
304 return size;
307 /* Copy servent to p_to, fix up inside pointers using p_base (different for
308 * Win16 (linear vs. segmented). Return -neededsize on overrun.
309 * Take care of different Win16/Win32 servent structs (packing !)
311 static int WS_copy_se(char *p_to,char *p_base,int t_size,struct servent* p_se, int flag)
313 char* p_name,*p_aliases,*p_proto,*p;
314 struct ws_servent16 *p_to16 = (struct ws_servent16*)p_to;
315 struct WS_servent *p_to32 = (struct WS_servent*)p_to;
316 int size = servent_size(p_se) +
318 (flag & AQ_WIN16) ? sizeof(struct ws_servent16) : sizeof(struct WS_servent)
319 - sizeof(struct servent)
322 if (t_size < size)
323 return -size;
324 p = p_to;
325 p += (flag & AQ_WIN16) ?
326 sizeof(struct ws_servent16) : sizeof(struct WS_servent);
327 p_name = p;
328 strcpy(p, p_se->s_name); p += strlen(p) + 1;
329 p_proto = p;
330 strcpy(p, p_se->s_proto); p += strlen(p) + 1;
331 p_aliases = p;
332 list_dup(p_se->s_aliases, p, p_base + (p - p_to), 0);
334 if (flag & AQ_WIN16)
336 p_to16->s_port = (INT16)p_se->s_port;
337 p_to16->s_name = (SEGPTR)(p_base + (p_name - p_to));
338 p_to16->s_proto = (SEGPTR)(p_base + (p_proto - p_to));
339 p_to16->s_aliases = (SEGPTR)(p_base + (p_aliases - p_to));
341 else
343 p_to32->s_port = p_se->s_port;
344 p_to32->s_name = (p_base + (p_name - p_to));
345 p_to32->s_proto = (p_base + (p_proto - p_to));
346 p_to32->s_aliases = (char **)(p_base + (p_aliases - p_to));
349 return size;
352 static HANDLE16 __ws_async_handle = 0xdead;
354 /* Generic async query struct. we use symbolic names for the different queries
355 * for readability.
357 typedef struct _async_query {
358 HWND16 hWnd;
359 UINT16 uMsg;
360 LPCSTR ptr1;
361 #define host_name ptr1
362 #define host_addr ptr1
363 #define serv_name ptr1
364 #define proto_name ptr1
365 LPCSTR ptr2;
366 #define serv_proto ptr2
367 int int1;
368 #define host_len int1
369 #define proto_number int1
370 #define serv_port int1
371 int int2;
372 #define host_type int2
373 SEGPTR sbuf;
374 INT16 sbuflen;
376 HANDLE16 async_handle;
377 int flags;
378 int qt;
379 char xbuf[1];
380 } async_query;
383 /****************************************************************************
384 * The async query function.
386 * It is either called as a thread startup routine or directly. It has
387 * to free the passed arg from the process heap and PostMessageA the async
388 * result or the error code.
390 * FIXME:
391 * - errorhandling not verified.
393 static DWORD WINAPI _async_queryfun(LPVOID arg) {
394 async_query *aq = (async_query*)arg;
395 int size = 0;
396 WORD fail = 0;
397 char *targetptr = (HB_WIN32(aq)?(char*)aq->sbuf:(char*)MapSL(aq->sbuf));
399 switch (aq->flags & AQ_GETMASK) {
400 case AQ_GETHOST: {
401 struct hostent *he;
402 char *copy_hostent = targetptr;
403 #ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
404 char *extrabuf;
405 int ebufsize=1024;
406 struct hostent hostentry;
407 int locerr = ENOBUFS;
408 #endif
409 char buf[100];
410 if( !(aq->host_name)) {
411 aq->host_name = buf;
412 if( gethostname( buf, 100) == -1) {
413 fail = WSAENOBUFS; /* appropriate ? */
414 break;
417 #ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
418 he = NULL;
419 extrabuf=HeapAlloc(GetProcessHeap(),0,ebufsize) ;
420 while(extrabuf) {
421 int res = (aq->flags & AQ_NAME) ?
422 gethostbyname_r(aq->host_name,
423 &hostentry, extrabuf, ebufsize, &he, &locerr):
424 gethostbyaddr_r(aq->host_addr,aq->host_len,aq->host_type,
425 &hostentry, extrabuf, ebufsize, &he, &locerr);
426 if( res != ERANGE) break;
427 ebufsize *=2;
428 extrabuf=HeapReAlloc(GetProcessHeap(),0,extrabuf,ebufsize) ;
430 if (!he) fail = ((locerr < 0) ? wsaErrno() : wsaHerrno(locerr));
431 #else
432 EnterCriticalSection( &csWSgetXXXbyYYY );
433 he = (aq->flags & AQ_NAME) ?
434 gethostbyname(aq->host_name):
435 gethostbyaddr(aq->host_addr,aq->host_len,aq->host_type);
436 if (!he) fail = ((h_errno < 0) ? wsaErrno() : wsaHerrno(h_errno));
437 #endif
438 if (he) {
439 size = WS_copy_he(copy_hostent,(char*)aq->sbuf,aq->sbuflen,he,aq->flags);
440 if (size < 0) {
441 fail = WSAENOBUFS;
442 size = -size;
445 #ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
446 HeapFree(GetProcessHeap(),0,extrabuf);
447 #else
448 LeaveCriticalSection( &csWSgetXXXbyYYY );
449 #endif
451 break;
452 case AQ_GETPROTO: {
453 #if defined(HAVE_GETPROTOBYNAME) && defined(HAVE_GETPROTOBYNUMBER)
454 struct protoent *pe;
455 char *copy_protoent = targetptr;
456 EnterCriticalSection( &csWSgetXXXbyYYY );
457 pe = (aq->flags & AQ_NAME)?
458 getprotobyname(aq->proto_name) :
459 getprotobynumber(aq->proto_number);
460 if (pe) {
461 size = WS_copy_pe(copy_protoent,(char*)aq->sbuf,aq->sbuflen,pe,aq->flags);
462 if (size < 0) {
463 fail = WSAENOBUFS;
464 size = -size;
466 } else {
467 if (aq->flags & AQ_NAME)
468 MESSAGE("protocol %s not found; You might want to add "
469 "this to /etc/protocols\n", debugstr_a(aq->proto_name) );
470 else
471 MESSAGE("protocol number %d not found; You might want to add "
472 "this to /etc/protocols\n", aq->proto_number );
473 fail = WSANO_DATA;
475 LeaveCriticalSection( &csWSgetXXXbyYYY );
476 #else
477 fail = WSANO_DATA;
478 #endif
480 break;
481 case AQ_GETSERV: {
482 struct servent *se;
483 char *copy_servent = targetptr;
484 EnterCriticalSection( &csWSgetXXXbyYYY );
485 se = (aq->flags & AQ_NAME)?
486 getservbyname(aq->serv_name,aq->serv_proto) :
487 #ifdef HAVE_GETSERVBYPORT
488 getservbyport(aq->serv_port,aq->serv_proto);
489 #else
490 NULL;
491 #endif
492 if (se) {
493 size = WS_copy_se(copy_servent,(char*)aq->sbuf,aq->sbuflen,se,aq->flags);
494 if (size < 0) {
495 fail = WSAENOBUFS;
496 size = -size;
498 } else {
499 if (aq->flags & AQ_NAME)
500 MESSAGE("service %s protocol %s not found; You might want to add "
501 "this to /etc/services\n", debugstr_a(aq->serv_name) ,
502 aq->serv_proto ? debugstr_a(aq->serv_proto ):"*");
503 else
504 MESSAGE("service on port %d protocol %s not found; You might want to add "
505 "this to /etc/services\n", aq->serv_port,
506 aq->serv_proto ? debugstr_a(aq->serv_proto ):"*");
507 fail = WSANO_DATA;
509 LeaveCriticalSection( &csWSgetXXXbyYYY );
511 break;
513 PostMessageA(HWND_32(aq->hWnd),aq->uMsg,(WPARAM) aq->async_handle,size|(fail<<16));
514 HeapFree(GetProcessHeap(),0,arg);
515 return 0;
518 /****************************************************************************
519 * The main async help function.
521 * It either starts a thread or just calls the function directly for platforms
522 * with no thread support. This relies on the fact that PostMessage() does
523 * not actually call the windowproc before the function returns.
525 static HANDLE16 __WSAsyncDBQuery(
526 HWND hWnd, UINT uMsg,INT int1,LPCSTR ptr1, INT int2, LPCSTR ptr2,
527 void *sbuf, INT sbuflen, UINT flags
530 async_query* aq;
531 char* pto;
532 LPCSTR pfm;
533 int xbuflen = 0;
535 /* allocate buffer to copy protocol- and service name to */
536 /* note: this is done in the calling thread so we can return */
537 /* a decent error code if the Alloc fails */
539 switch (flags & AQ_MASKPTR1) {
540 case 0: break;
541 case AQ_COPYPTR1: xbuflen += int1; break;
542 case AQ_DUPLOWPTR1: xbuflen += strlen(ptr1) + 1; break;
545 switch (flags & AQ_MASKPTR2) {
546 case 0: break;
547 case AQ_COPYPTR2: xbuflen += int2; break;
548 case AQ_DUPLOWPTR2: xbuflen += strlen(ptr2) + 1; break;
551 if(!(aq = HeapAlloc(GetProcessHeap(),0,sizeof(async_query) + xbuflen))) {
552 SetLastError(WSAEWOULDBLOCK); /* insufficient resources */
553 return 0;
556 pto = aq->xbuf;
557 if (ptr1) switch (flags & AQ_MASKPTR1) {
558 case 0: break;
559 case AQ_COPYPTR1: memcpy(pto, ptr1, int1); ptr1 = pto; pto += int1; break;
560 case AQ_DUPLOWPTR1: pfm = ptr1; ptr1 = pto; do *pto++ = tolower(*pfm); while (*pfm++); break;
562 if (ptr2) switch (flags & AQ_MASKPTR2) {
563 case 0: break;
564 case AQ_COPYPTR2: memcpy(pto, ptr2, int2); ptr2 = pto; pto += int2; break;
565 case AQ_DUPLOWPTR2: pfm = ptr2; ptr2 = pto; do *pto++ = tolower(*pfm); while (*pfm++); break;
568 aq->hWnd = HWND_16(hWnd);
569 aq->uMsg = uMsg;
570 aq->int1 = int1;
571 aq->ptr1 = ptr1;
572 aq->int2 = int2;
573 aq->ptr2 = ptr2;
574 /* avoid async_handle = 0 */
575 aq->async_handle = (++__ws_async_handle ? __ws_async_handle : ++__ws_async_handle);
576 aq->flags = flags;
577 aq->sbuf = (SEGPTR)sbuf;
578 aq->sbuflen = sbuflen;
580 #if 1
581 if (CreateThread(NULL,0,_async_queryfun,aq,0,NULL) == INVALID_HANDLE_VALUE)
582 #endif
583 _async_queryfun(aq);
584 return __ws_async_handle;
588 /***********************************************************************
589 * WSAAsyncGetHostByAddr (WINSOCK.102)
591 HANDLE16 WINAPI WSAAsyncGetHostByAddr16(HWND16 hWnd, UINT16 uMsg, LPCSTR addr,
592 INT16 len, INT16 type, SEGPTR sbuf, INT16 buflen)
594 TRACE("hwnd %04x, msg %04x, addr %08x[%i]\n",
595 hWnd, uMsg, (unsigned)addr , len );
596 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,len,addr,type,NULL,
597 (void*)sbuf,buflen,
598 AQ_NUMBER|AQ_COPYPTR1|AQ_WIN16|AQ_GETHOST);
601 /***********************************************************************
602 * WSAAsyncGetHostByAddr (WS2_32.102)
604 HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
605 INT len, INT type, LPSTR sbuf, INT buflen)
607 TRACE("hwnd %p, msg %04x, addr %08x[%i]\n",
608 hWnd, uMsg, (unsigned)addr , len );
609 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,len,addr,type,NULL,sbuf,buflen,
610 AQ_NUMBER|AQ_COPYPTR1|AQ_WIN32|AQ_GETHOST));
613 /***********************************************************************
614 * WSAAsyncGetHostByName (WINSOCK.103)
616 HANDLE16 WINAPI WSAAsyncGetHostByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
617 SEGPTR sbuf, INT16 buflen)
619 TRACE("hwnd %04x, msg %04x, host %s, buffer %i\n",
620 hWnd, uMsg, (name)?name:"<null>", (int)buflen );
621 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,NULL,
622 (void*)sbuf,buflen,
623 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN16|AQ_GETHOST);
626 /***********************************************************************
627 * WSAAsyncGetHostByName (WS2_32.103)
629 HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg, LPCSTR name,
630 LPSTR sbuf, INT buflen)
632 TRACE("hwnd %p, msg %08x, host %s, buffer %i\n",
633 hWnd, uMsg, (name)?name:"<null>", (int)buflen );
634 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,sbuf,buflen,
635 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN32|AQ_GETHOST));
638 /***********************************************************************
639 * WSAAsyncGetProtoByName (WINSOCK.105)
641 HANDLE16 WINAPI WSAAsyncGetProtoByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
642 SEGPTR sbuf, INT16 buflen)
644 TRACE("hwnd %04x, msg %08x, protocol %s\n",
645 hWnd, uMsg, (name)?name:"<null>" );
646 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,NULL,
647 (void*)sbuf,buflen,
648 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN16|AQ_GETPROTO);
651 /***********************************************************************
652 * WSAAsyncGetProtoByName (WS2_32.105)
654 HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg, LPCSTR name,
655 LPSTR sbuf, INT buflen)
657 TRACE("hwnd %p, msg %08x, protocol %s\n",
658 hWnd, uMsg, (name)?name:"<null>" );
659 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,sbuf,buflen,
660 AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN32|AQ_GETPROTO));
664 /***********************************************************************
665 * WSAAsyncGetProtoByNumber (WINSOCK.104)
667 HANDLE16 WINAPI WSAAsyncGetProtoByNumber16(HWND16 hWnd,UINT16 uMsg,INT16 number,
668 SEGPTR sbuf, INT16 buflen)
670 TRACE("hwnd %04x, msg %04x, num %i\n", hWnd, uMsg, number );
671 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,number,NULL,0,NULL,
672 (void*)sbuf,buflen,
673 AQ_GETPROTO|AQ_NUMBER|AQ_WIN16);
676 /***********************************************************************
677 * WSAAsyncGetProtoByNumber (WS2_32.104)
679 HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg, INT number,
680 LPSTR sbuf, INT buflen)
682 TRACE("hwnd %p, msg %04x, num %i\n", hWnd, uMsg, number );
683 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,number,NULL,0,NULL,sbuf,buflen,
684 AQ_GETPROTO|AQ_NUMBER|AQ_WIN32));
687 /***********************************************************************
688 * WSAAsyncGetServByName (WINSOCK.107)
690 HANDLE16 WINAPI WSAAsyncGetServByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
691 LPCSTR proto, SEGPTR sbuf, INT16 buflen)
693 TRACE("hwnd %04x, msg %04x, name %s, proto %s\n",
694 hWnd, uMsg, (name)?name:"<null>", (proto)?proto:"<null>");
695 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,proto,
696 (void*)sbuf,buflen,
697 AQ_GETSERV|AQ_NAME|AQ_DUPLOWPTR1|AQ_DUPLOWPTR2|AQ_WIN16);
700 /***********************************************************************
701 * WSAAsyncGetServByName (WS2_32.107)
703 HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name,
704 LPCSTR proto, LPSTR sbuf, INT buflen)
706 TRACE("hwnd %p, msg %04x, name %s, proto %s\n",
707 hWnd, uMsg, (name)?name:"<null>", (proto)?proto:"<null>");
708 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,proto,sbuf,buflen,
709 AQ_GETSERV|AQ_NAME|AQ_DUPLOWPTR1|AQ_DUPLOWPTR2|AQ_WIN32));
712 /***********************************************************************
713 * WSAAsyncGetServByPort (WINSOCK.106)
715 HANDLE16 WINAPI WSAAsyncGetServByPort16(HWND16 hWnd, UINT16 uMsg, INT16 port,
716 LPCSTR proto, SEGPTR sbuf, INT16 buflen)
718 TRACE("hwnd %04x, msg %04x, port %i, proto %s\n",
719 hWnd, uMsg, port, (proto)?proto:"<null>" );
720 return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,port,NULL,0,proto,
721 (void*)sbuf,buflen,
722 AQ_GETSERV|AQ_NUMBER|AQ_DUPLOWPTR2|AQ_WIN16);
725 /***********************************************************************
726 * WSAAsyncGetServByPort (WS2_32.106)
728 HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
729 LPCSTR proto, LPSTR sbuf, INT buflen)
731 TRACE("hwnd %p, msg %04x, port %i, proto %s\n",
732 hWnd, uMsg, port, (proto)?proto:"<null>" );
733 return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,port,NULL,0,proto,sbuf,buflen,
734 AQ_GETSERV|AQ_NUMBER|AQ_DUPLOWPTR2|AQ_WIN32));
737 /***********************************************************************
738 * WSACancelAsyncRequest (WS2_32.108)
740 INT WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle)
742 FIXME("(%p),stub\n", hAsyncTaskHandle);
743 return 0;
746 /***********************************************************************
747 * WSACancelAsyncRequest (WINSOCK.108)
749 INT16 WINAPI WSACancelAsyncRequest16(HANDLE16 hAsyncTaskHandle)
751 return (INT16)WSACancelAsyncRequest(WSA_H32 (hAsyncTaskHandle));
754 /***********************************************************************
755 * WSApSetPostRoutine (WS2_32.24)
757 INT WINAPI WSApSetPostRoutine(LPWPUPOSTMESSAGE lpPostRoutine)
759 FIXME("(%p), stub !\n", lpPostRoutine);
760 return 0;
763 /***********************************************************************
764 * (WS2_32.25)
766 WSAEVENT WINAPI WPUCompleteOverlappedRequest(SOCKET s, LPWSAOVERLAPPED overlapped,
767 DWORD error, DWORD transferred, LPINT errcode)
769 FIXME("(0x%08lx,%p,0x%08x,0x%08x,%p), stub !\n", s, overlapped, error, transferred, errcode);
771 if (errcode)
772 *errcode = WSAEINVAL;
774 return NULL;