-/****************************************************************************
- * 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.
- *
- * FIXME:
- * - errorhandling not verified.
- */
-static DWORD WINAPI _async_queryfun(LPVOID arg) {
- async_query *aq = (async_query*)arg;
- int size = 0;
- WORD fail = 0;
- char *targetptr = (HB_WIN32(aq)?(char*)aq->sbuf:0/*(char*)MapSL(aq->sbuf)*/);
-
- switch (aq->flags & AQ_GETMASK) {
- case AQ_GETHOST: {
- struct hostent *he;
- char *copy_hostent = targetptr;
- char buf[100];
- if( !(aq->host_name)) {
- aq->host_name = buf;
- if( gethostname( buf, 100) == -1) {
- fail = WSAENOBUFS; /* appropriate ? */
- break;
- }
- }
- he = (aq->flags & AQ_NAME) ?
- gethostbyname(aq->host_name):
- gethostbyaddr(aq->host_addr,aq->host_len,aq->host_type);
- if (!he) fail = WSAGetLastError();
- if (he) {
- size = WS_copy_he(copy_hostent,(char*)aq->sbuf,aq->sbuflen,he,aq->flags);
- if (size < 0) {
- fail = WSAENOBUFS;
- size = -size;
- }
- }
- }
- break;
- case AQ_GETPROTO: {
-#if defined(HAVE_GETPROTOBYNAME) && defined(HAVE_GETPROTOBYNUMBER)
- struct protoent *pe;
- char *copy_protoent = targetptr;
- pe = (aq->flags & AQ_NAME)?
- getprotobyname(aq->proto_name) :
- getprotobynumber(aq->proto_number);
- if (pe) {
- size = WS_copy_pe(copy_protoent,(char*)aq->sbuf,aq->sbuflen,pe,aq->flags);
- if (size < 0) {
- fail = WSAENOBUFS;
- size = -size;
- }
- } else {
- 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;
- }
-#else
- fail = WSANO_DATA;
-#endif
- }
- break;
- case AQ_GETSERV: {
- struct servent *se;
- char *copy_servent = targetptr;
- se = (aq->flags & AQ_NAME)?
- getservbyname(aq->serv_name,aq->serv_proto) :
-#ifdef HAVE_GETSERVBYPORT
- getservbyport(aq->serv_port,aq->serv_proto);
-#else
- NULL;
-#endif
- if (se) {
- size = WS_copy_se(copy_servent,(char*)aq->sbuf,aq->sbuflen,se,aq->flags);
- if (size < 0) {
- fail = WSAENOBUFS;
- size = -size;
- }
- } else {
- 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) ,
- aq->serv_proto ? debugstr_a(aq->serv_proto ):"*");
- else
- MESSAGE("service on port %d protocol %s not found; You might want to add "
- "this to /etc/services\n", aq->serv_port,
- aq->serv_proto ? debugstr_a(aq->serv_proto ):"*");
- fail = WSANO_DATA;
- }
- }
- break;
- }
- PostMessageA(HWND_32(aq->hWnd),aq->uMsg,(WPARAM) aq->async_handle,size|(fail<<16));
- HeapFree(GetProcessHeap(),0,arg);
- return 0;