async.c 24.3 KB
Newer Older
1
/* Async WINSOCK DNS services
2
 *
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * Copyright (C) 1993,1994,1996,1997 John Brezak, Erik Bos, Alex Korobka.
 * Copyright (C) 1999 Marcus Meissner
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 21 22
 *
 * NOTE: If you make any changes to fix a particular app, make sure
 * they don't break something else like Netscape or telnet and ftp
 * clients and servers (www.winsite.com got a lot of those).
23
 *
24 25 26 27 28 29 30 31 32 33 34
 * FIXME:
 *	- Add WSACancel* and correct handle management. (works rather well for
 *	  now without it.)
 *	- Verify & Check all calls for correctness
 *	  (currently only WSAGetHostByName*, WSAGetServByPort* calls)
 *	- Check error returns.
 *	- mirc/mirc32 Finger @linux.kernel.org sometimes fails in threaded mode.
 *	  (not sure why)
 *	- This implementation did ignore the "NOTE:" section above (since the
 *	  whole stuff did not work anyway to other changes).
 */
35

36
#include "config.h"
37
#include "wine/port.h"
38

39
#include <stdarg.h>
40 41
#include <string.h>
#include <sys/types.h>
42 43 44
#ifdef HAVE_SYS_IPC_H
# include <sys/ipc.h>
#endif
45 46 47
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
48 49 50 51 52
#ifdef HAVE_SYS_FILIO_H
# include <sys/filio.h>
#endif
#if defined(__svr4__)
#include <sys/ioccom.h>
53 54 55
#ifdef HAVE_SYS_SOCKIO_H
# include <sys/sockio.h>
#endif
56 57 58 59 60 61 62 63 64 65
#endif

#if defined(__EMX__)
# include <sys/so_ioctl.h>
#endif

#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif

66 67 68 69
#ifdef HAVE_SYS_MSG_H
# include <sys/msg.h>
#endif
#ifdef HAVE_SYS_WAIT_H
70
#include <sys/wait.h>
71 72
#endif
#ifdef HAVE_SYS_SOCKET_H
73
#include <sys/socket.h>
74 75 76 77 78 79 80
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
81 82 83
#include <ctype.h>
#include <fcntl.h>
#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 91 92
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
93 94 95 96 97 98 99 100 101
#include <stdlib.h>
#ifdef HAVE_ARPA_NAMESER_H
# include <arpa/nameser.h>
#endif
#ifdef HAVE_RESOLV_H
# include <resolv.h>
#endif

#include "wine/winbase16.h"
102 103
#include "windef.h"
#include "winbase.h"
104 105
#include "wingdi.h"
#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-rentrant net function */
118 119 120 121 122
CRITICAL_SECTION csWSgetXXXbyYYY;
static CRITICAL_SECTION_DEBUG critsect_debug =
{
    0, 0, &csWSgetXXXbyYYY,
    { &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 128 129
/* protoptypes of some functions in socket.c
 */
UINT16 wsaErrno(void);
130
UINT16 wsaHerrno(int errnr);
131

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
#define AQ_WIN16	0x00
#define AQ_WIN32	0x04
#define HB_WIN32(hb) (hb->flags & AQ_WIN32)
#define AQ_NUMBER	0x00
#define AQ_NAME		0x08
#define AQ_COPYPTR1	0x10
#define AQ_DUPLOWPTR1	0x20
#define AQ_MASKPTR1	0x30
#define AQ_COPYPTR2	0x40
#define AQ_DUPLOWPTR2	0x80
#define AQ_MASKPTR2	0xC0

#define AQ_GETHOST	0
#define AQ_GETPROTO	1
#define AQ_GETSERV	2
#define AQ_GETMASK	3

149 150 151 152
/* The handles used are pseudo-handles that can be simply casted. */
/* 16-bit values are used internally (to be sure handle comparison works right in 16-bit apps). */
#define WSA_H32(h16) ((HANDLE)(ULONG_PTR)(h16))

153 154 155 156 157 158
/* ----------------------------------- helper functions - */

static int list_size(char** l, int item_size)
{
  int i,j = 0;
  if(l)
159
  { for(i=0;l[i];i++)
160 161 162 163 164 165
	j += (item_size) ? item_size : strlen(l[i]) + 1;
    j += (i + 1) * sizeof(char*); }
  return j;
}

static int list_dup(char** l_src, char* ref, char* base, int item_size)
166
{
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
   /* base is either either equal to ref or 0 or SEGPTR */

   char*		p = ref;
   char**		l_to = (char**)ref;
   int			i,j,k;

   for(j=0;l_src[j];j++) ;
   p += (j + 1) * sizeof(char*);
   for(i=0;i<j;i++)
   { l_to[i] = base + (p - ref);
     k = ( item_size ) ? item_size : strlen(l_src[i]) + 1;
     memcpy(p, l_src[i], k); p += k; }
   l_to[i] = NULL;
   return (p - ref);
}

/* ----- hostent */

static int hostent_size(struct hostent* p_he)
{
  int size = 0;
  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 193 194 195 196 197 198
    size += list_size(p_he->h_addr_list, p_he->h_length ); }
  return size;
}

/* Copy hostent to p_to, fix up inside pointers using p_base (different for
 * 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)
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 205
	int	size = hostent_size(p_he) +
		(
206
		(flag & AQ_WIN16) ? sizeof(struct ws_hostent16) : sizeof(struct WS_hostent)
207 208
		- sizeof(struct hostent)
		);
209 210 211

	if (t_size < size)
		return -size;
212 213
	p = p_to;
	p += (flag & AQ_WIN16) ?
214
		sizeof(struct ws_hostent16) : sizeof(struct WS_hostent);
215 216 217 218 219 220 221
	p_name = p;
	strcpy(p, p_he->h_name); p += strlen(p) + 1;
	p_aliases = p;
	p += list_dup(p_he->h_aliases, p, p_base + (p - (char*)p_to), 0);
	p_addr = p;
	list_dup(p_he->h_addr_list, p, p_base + (p - (char*)p_to), p_he->h_length);

222 223
	if (flag & AQ_WIN16)
	{
224
	    p_to16->h_addrtype = (INT16)p_he->h_addrtype;
225 226 227 228 229 230 231
	    p_to16->h_length = (INT16)p_he->h_length;
	    p_to16->h_name = (SEGPTR)(p_base + (p_name - p_to));
	    p_to16->h_aliases = (SEGPTR)(p_base + (p_aliases - p_to));
	    p_to16->h_addr_list = (SEGPTR)(p_base + (p_addr - p_to));
	}
	else
	{
232
	    p_to32->h_addrtype = p_he->h_addrtype;
233 234 235 236 237
	    p_to32->h_length = p_he->h_length;
	    p_to32->h_name = (p_base + (p_name - p_to));
	    p_to32->h_aliases = (char **)(p_base + (p_aliases - p_to));
	    p_to32->h_addr_list = (char **)(p_base + (p_addr - p_to));
	}
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256

	return size;
}

/* ----- protoent */

static int protoent_size(struct protoent* p_pe)
{
  int size = 0;
  if( p_pe )
  { size  = sizeof(struct protoent);
    size += strlen(p_pe->p_name) + 1;
    size += list_size(p_pe->p_aliases, 0); }
  return size;
}

/* Copy protoent to p_to, fix up inside pointers using p_base (different for
 * 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)
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 263
	int	size = protoent_size(p_pe) +
		(
264
		(flag & AQ_WIN16) ? sizeof(struct ws_protoent16) : sizeof(struct WS_protoent)
265 266
		- sizeof(struct protoent)
		);
267 268 269

	if (t_size < size)
		return -size;
270 271
	p = p_to;
	p += (flag & AQ_WIN16) ?
272
		sizeof(struct ws_protoent16) : sizeof(struct WS_protoent);
273 274 275 276 277
	p_name = p;
	strcpy(p, p_pe->p_name); p += strlen(p) + 1;
	p_aliases = p;
	list_dup(p_pe->p_aliases, p, p_base + (p - (char*)p_to), 0);

278 279 280 281
	if (flag & AQ_WIN16)
	{
	    p_to16->p_proto = (INT16)p_pe->p_proto;
	    p_to16->p_name = (SEGPTR)(p_base) + (p_name - p_to);
282
	    p_to16->p_aliases = (SEGPTR)((p_base) + (p_aliases - p_to));
283 284 285 286 287
	}
	else
	{
	    p_to32->p_proto = p_pe->p_proto;
	    p_to32->p_name = (p_base) + (p_name - p_to);
288
	    p_to32->p_aliases = (char **)((p_base) + (p_aliases - p_to));
289
	}
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308

	return size;
}

/* ----- servent */

static int servent_size(struct servent* p_se)
{
	int size = 0;
	if( p_se ) {
		size += sizeof(struct servent);
		size += strlen(p_se->s_proto) + strlen(p_se->s_name) + 2;
		size += list_size(p_se->s_aliases, 0);
	}
	return size;
}

/* Copy servent to p_to, fix up inside pointers using p_base (different for
 * Win16 (linear vs. segmented). Return -neededsize on overrun.
309
 * Take care of different Win16/Win32 servent structs (packing !)
310
 */
311
static int WS_copy_se(char *p_to,char *p_base,int t_size,struct servent* p_se, int flag)
312 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 317
	int	size = servent_size(p_se) +
		(
318
		(flag & AQ_WIN16) ? sizeof(struct ws_servent16) : sizeof(struct WS_servent)
319 320
		- sizeof(struct servent)
		);
321

322
	if (t_size < size)
323
		return -size;
324 325
	p = p_to;
	p += (flag & AQ_WIN16) ?
326
		sizeof(struct ws_servent16) : sizeof(struct WS_servent);
327 328 329 330 331
	p_name = p;
	strcpy(p, p_se->s_name); p += strlen(p) + 1;
	p_proto = p;
	strcpy(p, p_se->s_proto); p += strlen(p) + 1;
	p_aliases = p;
332 333 334 335 336 337 338
	list_dup(p_se->s_aliases, p, p_base + (p - p_to), 0);

	if (flag & AQ_WIN16)
	{
	    p_to16->s_port = (INT16)p_se->s_port;
	    p_to16->s_name = (SEGPTR)(p_base + (p_name - p_to));
	    p_to16->s_proto = (SEGPTR)(p_base + (p_proto - p_to));
339
	    p_to16->s_aliases = (SEGPTR)(p_base + (p_aliases - p_to));
340 341 342 343 344 345
	}
	else
	{
	    p_to32->s_port = p_se->s_port;
	    p_to32->s_name = (p_base + (p_name - p_to));
	    p_to32->s_proto = (p_base + (p_proto - p_to));
346
	    p_to32->s_aliases = (char **)(p_base + (p_aliases - p_to));
347
	}
348 349 350 351

	return size;
}

352
static HANDLE16 __ws_async_handle = 0xdead;
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378

/* Generic async query struct. we use symbolic names for the different queries
 * for readability.
 */
typedef struct _async_query {
	HWND16		hWnd;
	UINT16		uMsg;
	LPCSTR		ptr1;
#define host_name	ptr1
#define host_addr	ptr1
#define serv_name	ptr1
#define proto_name	ptr1
	LPCSTR		ptr2;
#define serv_proto	ptr2
	int		int1;
#define host_len	int1
#define proto_number	int1
#define serv_port	int1
	int		int2;
#define host_type	int2
	SEGPTR		sbuf;
	INT16		sbuflen;

	HANDLE16	async_handle;
	int		flags;
	int		qt;
379
    char xbuf[1];
380 381
} async_query;

382

383 384 385 386 387 388
/****************************************************************************
 * The async query function.
 *
 * It is either called as a thread startup routine or directly. It has
 * to free the passed arg from the process heap and PostMessageA the async
 * result or the error code.
389
 *
390 391 392 393 394 395 396
 * FIXME:
 *	- errorhandling not verified.
 */
static DWORD WINAPI _async_queryfun(LPVOID arg) {
	async_query	*aq = (async_query*)arg;
	int		size = 0;
	WORD		fail = 0;
397
	char		*targetptr = (HB_WIN32(aq)?(char*)aq->sbuf:(char*)MapSL(aq->sbuf));
398 399 400

	switch (aq->flags & AQ_GETMASK) {
	case AQ_GETHOST: {
401 402
			struct hostent *he;
			char *copy_hostent = targetptr;
403
#ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
404 405 406 407
                        char *extrabuf;
                        int ebufsize=1024;
                        struct hostent hostentry;
                        int locerr = ENOBUFS;
408 409 410 411 412 413 414 415 416 417
#endif
                        char buf[100];
                        if( !(aq->host_name)) {
                            aq->host_name = buf;
                            if( gethostname( buf, 100) == -1) {
                                fail = WSAENOBUFS; /* appropriate ? */
                                break;
                            }
                        }
#ifdef  HAVE_LINUX_GETHOSTBYNAME_R_6
418 419
                        he = NULL;
                        extrabuf=HeapAlloc(GetProcessHeap(),0,ebufsize) ;
420
                        while(extrabuf) {
421 422 423 424 425 426 427 428 429 430 431 432
                            int res = (aq->flags & AQ_NAME) ?
                                gethostbyname_r(aq->host_name,
                                                &hostentry, extrabuf, ebufsize, &he, &locerr):
                                gethostbyaddr_r(aq->host_addr,aq->host_len,aq->host_type,
                                                &hostentry, extrabuf, ebufsize, &he, &locerr);
                            if( res != ERANGE) break;
                            ebufsize *=2;
                            extrabuf=HeapReAlloc(GetProcessHeap(),0,extrabuf,ebufsize) ;
                        }
                        if (!he) fail = ((locerr < 0) ? wsaErrno() : wsaHerrno(locerr));
#else
                        EnterCriticalSection( &csWSgetXXXbyYYY );
433 434 435
			he = (aq->flags & AQ_NAME) ?
				gethostbyname(aq->host_name):
				gethostbyaddr(aq->host_addr,aq->host_len,aq->host_type);
436 437
                        if (!he) fail = ((h_errno < 0) ? wsaErrno() : wsaHerrno(h_errno));
#endif
438
			if (he) {
439
				size = WS_copy_he(copy_hostent,(char*)aq->sbuf,aq->sbuflen,he,aq->flags);
440 441 442 443 444
				if (size < 0) {
					fail = WSAENOBUFS;
					size = -size;
				}
			}
445
#ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
446 447 448 449
                        HeapFree(GetProcessHeap(),0,extrabuf);
#else
                        LeaveCriticalSection( &csWSgetXXXbyYYY );
#endif
450 451 452
		}
		break;
	case AQ_GETPROTO: {
453
#if defined(HAVE_GETPROTOBYNAME) && defined(HAVE_GETPROTOBYNUMBER)
454 455
			struct protoent *pe;
			char *copy_protoent = targetptr;
456
                        EnterCriticalSection( &csWSgetXXXbyYYY );
457
			pe = (aq->flags & AQ_NAME)?
458
				getprotobyname(aq->proto_name) :
459 460
				getprotobynumber(aq->proto_number);
			if (pe) {
461
				size = WS_copy_pe(copy_protoent,(char*)aq->sbuf,aq->sbuflen,pe,aq->flags);
462 463 464 465 466
				if (size < 0) {
					fail = WSAENOBUFS;
					size = -size;
				}
			} else {
467 468 469 470 471 472 473
                            if (aq->flags & AQ_NAME)
                                MESSAGE("protocol %s not found; You might want to add "
                                        "this to /etc/protocols\n", debugstr_a(aq->proto_name) );
                            else
                                MESSAGE("protocol number %d not found; You might want to add "
                                        "this to /etc/protocols\n", aq->proto_number );
                            fail = WSANO_DATA;
474
			}
475
                        LeaveCriticalSection( &csWSgetXXXbyYYY );
476 477 478
#else
                        fail = WSANO_DATA;
#endif
479 480 481
		}
		break;
	case AQ_GETSERV: {
482 483
			struct servent	*se;
			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 490 491
#else
                                NULL;
#endif
492
			if (se) {
493
				size = WS_copy_se(copy_servent,(char*)aq->sbuf,aq->sbuflen,se,aq->flags);
494 495 496 497 498
				if (size < 0) {
					fail = WSAENOBUFS;
					size = -size;
				}
			} else {
499 500 501
                            if (aq->flags & AQ_NAME)
                                MESSAGE("service %s protocol %s not found; You might want to add "
                                        "this to /etc/services\n", debugstr_a(aq->serv_name) ,
502
                                        aq->serv_proto ? debugstr_a(aq->serv_proto ):"*");
503 504 505
                            else
                                MESSAGE("service on port %d protocol %s not found; You might want to add "
                                        "this to /etc/services\n", aq->serv_port,
506
                                        aq->serv_proto ? debugstr_a(aq->serv_proto ):"*");
507
                            fail = WSANO_DATA;
508
			}
509
                        LeaveCriticalSection( &csWSgetXXXbyYYY );
510 511 512
		}
		break;
	}
513
	PostMessageA(HWND_32(aq->hWnd),aq->uMsg,(WPARAM) aq->async_handle,size|(fail<<16));
514 515 516 517 518
	HeapFree(GetProcessHeap(),0,arg);
	return 0;
}

/****************************************************************************
519 520
 * The main async help function.
 *
521 522 523 524 525 526 527
 * It either starts a thread or just calls the function directly for platforms
 * with no thread support. This relies on the fact that PostMessage() does
 * not actually call the windowproc before the function returns.
 */
static HANDLE16	__WSAsyncDBQuery(
	HWND hWnd, UINT uMsg,INT int1,LPCSTR ptr1, INT int2, LPCSTR ptr2,
	void *sbuf, INT sbuflen, UINT flags
528
)
529
{
530 531 532 533
        async_query*	aq;
	char*		pto;
	LPCSTR		pfm;
	int		xbuflen = 0;
534

535 536 537
	/* allocate buffer to copy protocol- and service name to */
	/* note: this is done in the calling thread so we can return */
	/* a decent error code if the Alloc fails */
538

539 540 541 542 543
	switch (flags & AQ_MASKPTR1) {
	case 0:							break;
	case AQ_COPYPTR1:	xbuflen += int1;		break;
	case AQ_DUPLOWPTR1:	xbuflen += strlen(ptr1) + 1;	break;
	}
544

545 546 547 548 549
	switch (flags & AQ_MASKPTR2) {
	case 0:							break;
	case AQ_COPYPTR2:	xbuflen += int2;		break;
	case AQ_DUPLOWPTR2:	xbuflen += strlen(ptr2) + 1;	break;
	}
550

551 552 553 554
	if(!(aq = HeapAlloc(GetProcessHeap(),0,sizeof(async_query) + xbuflen))) {
	        SetLastError(WSAEWOULDBLOCK); /* insufficient resources */
		return 0;
	}
555

556 557 558 559 560 561 562 563 564 565 566
	pto = aq->xbuf;
	if (ptr1) switch (flags & AQ_MASKPTR1) {
	case 0:											break;
	case AQ_COPYPTR1:   memcpy(pto, ptr1, int1); ptr1 = pto; pto += int1; 			break;
	case AQ_DUPLOWPTR1: pfm = ptr1; ptr1 = pto; do *pto++ = tolower(*pfm); while (*pfm++);	break;
	}
	if (ptr2) switch (flags & AQ_MASKPTR2) {
	case 0:											break;
	case AQ_COPYPTR2:   memcpy(pto, ptr2, int2); ptr2 = pto; pto += int2;			break;
	case AQ_DUPLOWPTR2: pfm = ptr2; ptr2 = pto; do *pto++ = tolower(*pfm); while (*pfm++);	break;
	}
567

568
	aq->hWnd	= HWND_16(hWnd);
569 570 571 572 573
	aq->uMsg	= uMsg;
	aq->int1	= int1;
	aq->ptr1	= ptr1;
	aq->int2	= int2;
	aq->ptr2	= ptr2;
574 575
	/* avoid async_handle = 0 */
	aq->async_handle = (++__ws_async_handle ? __ws_async_handle : ++__ws_async_handle);
576 577 578
	aq->flags	= flags;
	aq->sbuf	= (SEGPTR)sbuf;
	aq->sbuflen	= sbuflen;
579

580
#if 1
581
	if (CreateThread(NULL,0,_async_queryfun,aq,0,NULL) == INVALID_HANDLE_VALUE)
582 583 584 585 586 587 588
#endif
		_async_queryfun(aq);
	return __ws_async_handle;
}


/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
589
 *       WSAAsyncGetHostByAddr	(WINSOCK.102)
590 591 592 593
 */
HANDLE16 WINAPI WSAAsyncGetHostByAddr16(HWND16 hWnd, UINT16 uMsg, LPCSTR addr,
                               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 597
	return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,len,addr,type,NULL,
				(void*)sbuf,buflen,
598
				AQ_NUMBER|AQ_COPYPTR1|AQ_WIN16|AQ_GETHOST);
599 600 601
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
602
 *       WSAAsyncGetHostByAddr        (WS2_32.102)
603 604 605 606
 */
HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
                               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 610
	return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,len,addr,type,NULL,sbuf,buflen,
				AQ_NUMBER|AQ_COPYPTR1|AQ_WIN32|AQ_GETHOST));
611 612 613
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
614
 *       WSAAsyncGetHostByName	(WINSOCK.103)
615
 */
616
HANDLE16 WINAPI WSAAsyncGetHostByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
617 618
                                      SEGPTR sbuf, INT16 buflen)
{
619
	TRACE("hwnd %04x, msg %04x, host %s, buffer %i\n",
620
	      hWnd, uMsg, (name)?name:"<null>", (int)buflen );
621 622
	return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,NULL,
				(void*)sbuf,buflen,
623
				AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN16|AQ_GETHOST);
624
}
625 626

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
627
 *       WSAAsyncGetHostByName	(WS2_32.103)
628
 */
629
HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg, LPCSTR name,
630 631
					LPSTR sbuf, INT buflen)
{
632
	TRACE("hwnd %p, msg %08x, host %s, buffer %i\n",
633
	       hWnd, uMsg, (name)?name:"<null>", (int)buflen );
634 635
	return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,sbuf,buflen,
				AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN32|AQ_GETHOST));
636 637 638
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
639
 *       WSAAsyncGetProtoByName	(WINSOCK.105)
640
 */
641
HANDLE16 WINAPI WSAAsyncGetProtoByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
642 643
                                         SEGPTR sbuf, INT16 buflen)
{
644
	TRACE("hwnd %04x, msg %08x, protocol %s\n",
645 646 647
	       hWnd, uMsg, (name)?name:"<null>" );
	return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,NULL,
				(void*)sbuf,buflen,
648
				AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN16|AQ_GETPROTO);
649 650 651
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
652
 *       WSAAsyncGetProtoByName       (WS2_32.105)
653 654 655 656
 */
HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg, LPCSTR name,
                                         LPSTR sbuf, INT buflen)
{
657
	TRACE("hwnd %p, msg %08x, protocol %s\n",
658
	       hWnd, uMsg, (name)?name:"<null>" );
659 660
	return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,NULL,sbuf,buflen,
				AQ_NAME|AQ_DUPLOWPTR1|AQ_WIN32|AQ_GETPROTO));
661 662 663 664
}


/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
665
 *       WSAAsyncGetProtoByNumber	(WINSOCK.104)
666 667 668 669
 */
HANDLE16 WINAPI WSAAsyncGetProtoByNumber16(HWND16 hWnd,UINT16 uMsg,INT16 number,
                                           SEGPTR sbuf, INT16 buflen)
{
670
	TRACE("hwnd %04x, msg %04x, num %i\n", hWnd, uMsg, number );
671 672
	return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,number,NULL,0,NULL,
				(void*)sbuf,buflen,
673
				AQ_GETPROTO|AQ_NUMBER|AQ_WIN16);
674 675 676
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
677
 *       WSAAsyncGetProtoByNumber     (WS2_32.104)
678 679 680 681
 */
HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg, INT number,
                                           LPSTR sbuf, INT buflen)
{
682 683 684
	TRACE("hwnd %p, msg %04x, num %i\n", hWnd, uMsg, number );
	return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,number,NULL,0,NULL,sbuf,buflen,
				AQ_GETPROTO|AQ_NUMBER|AQ_WIN32));
685 686 687
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
688
 *       WSAAsyncGetServByName	(WINSOCK.107)
689
 */
690
HANDLE16 WINAPI WSAAsyncGetServByName16(HWND16 hWnd, UINT16 uMsg, LPCSTR name,
691 692
                                        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 696
	return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,0,name,0,proto,
				(void*)sbuf,buflen,
697
				AQ_GETSERV|AQ_NAME|AQ_DUPLOWPTR1|AQ_DUPLOWPTR2|AQ_WIN16);
698 699 700
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
701
 *       WSAAsyncGetServByName        (WS2_32.107)
702 703 704 705
 */
HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name,
                                        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 709
	return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,0,name,0,proto,sbuf,buflen,
				AQ_GETSERV|AQ_NAME|AQ_DUPLOWPTR1|AQ_DUPLOWPTR2|AQ_WIN32));
710 711 712
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
713
 *       WSAAsyncGetServByPort	(WINSOCK.106)
714
 */
715
HANDLE16 WINAPI WSAAsyncGetServByPort16(HWND16 hWnd, UINT16 uMsg, INT16 port,
716 717
                                        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 721
	return __WSAsyncDBQuery(HWND_32(hWnd),uMsg,port,NULL,0,proto,
				(void*)sbuf,buflen,
722
				AQ_GETSERV|AQ_NUMBER|AQ_DUPLOWPTR2|AQ_WIN16);
723 724 725
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
726
 *       WSAAsyncGetServByPort        (WS2_32.106)
727 728 729 730
 */
HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
                                        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 734
	return WSA_H32( __WSAsyncDBQuery(hWnd,uMsg,port,NULL,0,proto,sbuf,buflen,
				AQ_GETSERV|AQ_NUMBER|AQ_DUPLOWPTR2|AQ_WIN32));
735 736 737
}

/***********************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
738
 *       WSACancelAsyncRequest	(WS2_32.108)
739 740 741
 */
INT WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle)
{
742
    FIXME("(%p),stub\n", hAsyncTaskHandle);
743 744 745
    return 0;
}

Patrik Stridvall's avatar
Patrik Stridvall committed
746 747 748
/***********************************************************************
 *       WSACancelAsyncRequest	(WINSOCK.108)
 */
749 750
INT16 WINAPI WSACancelAsyncRequest16(HANDLE16 hAsyncTaskHandle)
{
751
    return (INT16)WSACancelAsyncRequest(WSA_H32 (hAsyncTaskHandle));
752
}
753 754 755 756

/***********************************************************************
 *       WSApSetPostRoutine	(WS2_32.24)
 */
757
INT WINAPI WSApSetPostRoutine(LPWPUPOSTMESSAGE lpPostRoutine)
758 759 760 761
{
    FIXME("(%p), stub !\n", lpPostRoutine);
    return 0;
}
762 763 764 765 766

/***********************************************************************
 *        (WS2_32.25)
 */
WSAEVENT WINAPI WPUCompleteOverlappedRequest(SOCKET s, LPWSAOVERLAPPED overlapped,
767
                                             DWORD error, DWORD transferred, LPINT errcode)
768
{
769
    FIXME("(0x%08lx,%p,0x%08x,0x%08x,%p), stub !\n", s, overlapped, error, transferred, errcode);
770

771 772
    if (errcode)
        *errcode = WSAEINVAL;
773 774 775

    return NULL;
}