ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

getxbyxx.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS WinSock 2 API
00004  * FILE:        getxbyy.c
00005  * PURPOSE:     Get X by Y Functions for Name Resolution.
00006  * PROGRAMMER:  Alex Ionescu (alex@relsoft.net)
00007  */
00008 
00009 /* INCLUDES ******************************************************************/
00010 #include "ws2_32.h"
00011 
00012 //#define NDEBUG
00013 #include <debug.h>
00014 
00015 /* DATA **********************************************************************/
00016 
00017 AFPROTOCOLS afp[2] = {{AF_INET, IPPROTO_UDP}, {AF_INET, IPPROTO_TCP}};
00018                      
00019 /* FUNCTIONS *****************************************************************/
00020 
00021 VOID
00022 WSAAPI
00023 FixList(PCHAR **List, 
00024         ULONG_PTR Base)
00025 {
00026     /* Make sure it's valid */
00027     if(*List)
00028     {
00029         PCHAR *Addr;
00030 
00031         /* Get the right base */
00032         Addr = *List = (PCHAR*)(((ULONG_PTR)*List + Base));
00033 
00034         /* Loop the pointers */
00035         while(*Addr)
00036         {
00037             /* Rebase them too */
00038             *Addr = (PCHAR)(((ULONG_PTR)*Addr + Base));
00039             Addr++;
00040         }
00041     }
00042 }
00043 
00044 VOID
00045 WSAAPI
00046 UnpackServEnt(PSERVENT Servent)
00047 {
00048     ULONG_PTR ServentPtr = (ULONG_PTR)Servent;
00049 
00050     /* Convert all the List Offsets to Pointers */
00051     FixList(&Servent->s_aliases, ServentPtr);
00052 
00053     /* Convert the Name and Protocol Offesets to Pointers */
00054     Servent->s_name = (PCHAR)(Servent->s_name + ServentPtr);
00055     Servent->s_proto = (PCHAR)(Servent->s_proto + ServentPtr);
00056 }
00057 
00058 VOID
00059 WSAAPI
00060 UnpackHostEnt(PHOSTENT Hostent)
00061 {
00062     ULONG_PTR HostentPtr = (ULONG_PTR)Hostent;
00063 
00064     /* Convert the Name Offset to a Pointer */
00065     if(Hostent->h_name) Hostent->h_name = (PCHAR)(Hostent->h_name + HostentPtr);
00066 
00067     /* Convert all the List Offsets to Pointers */
00068     FixList(&Hostent->h_aliases, HostentPtr);
00069     FixList(&Hostent->h_addr_list, HostentPtr);
00070 }
00071 
00072 VOID
00073 WSAAPI
00074 Local_Ip4AddresstoString(IN PCHAR AddressBuffer,
00075                          IN PCHAR Address)
00076 {
00077     /* Convert the address into IPv4 format */
00078     sprintf(AddressBuffer, "%u.%u.%u.%u",
00079             ((unsigned)Address[0] & 0xff),
00080             ((unsigned)Address[1] & 0xff),
00081             ((unsigned)Address[2] & 0xff),
00082             ((unsigned)Address[3] & 0xff));
00083 }
00084 
00085 VOID
00086 WSAAPI
00087 Local_Ip6AddresstoString(IN PCHAR AddressBuffer,
00088                          IN PCHAR Address)
00089 {
00090     DWORD i;
00091 
00092     /* Convert the address into IPv6 format */
00093     for (i = 0; i < 8; i++)
00094     {
00095         sprintf(AddressBuffer, "%x:",
00096                 ((unsigned)Address[0] & 0xff));
00097     }
00098 }
00099 
00100 LPBLOB
00101 WSAAPI
00102 getxyDataEnt(IN OUT PCHAR *Results,
00103              IN DWORD Length,
00104              IN LPSTR Name,
00105              IN LPCGUID Type,
00106              IN LPSTR *NewName)
00107 {
00108     PWSAQUERYSETA WsaQuery = (PWSAQUERYSETA)*Results;
00109     INT ErrorCode;
00110     HANDLE RnRHandle;
00111     LPBLOB Blob = NULL;
00112     PVOID NewResults;
00113 
00114     /* Assume empty return name */
00115     if (NewName) *NewName = NULL;
00116 
00117     /* Set up the Winsock Service Query */
00118     RtlZeroMemory(WsaQuery, sizeof(*WsaQuery));
00119     WsaQuery->dwSize = sizeof(*WsaQuery);
00120     WsaQuery->lpszServiceInstanceName = Name;
00121     WsaQuery->lpServiceClassId = (LPGUID)Type;
00122     WsaQuery->dwNameSpace = NS_ALL;
00123     WsaQuery->dwNumberOfProtocols = 2;
00124     WsaQuery->lpafpProtocols = &afp[0];
00125 
00126     /* Send the Query Request to find a Service */
00127     ErrorCode = WSALookupServiceBeginA(WsaQuery,
00128                                        LUP_RETURN_BLOB | LUP_RETURN_NAME,
00129                                        &RnRHandle);
00130 
00131     if(ErrorCode == ERROR_SUCCESS) 
00132     {
00133         while (TRUE)
00134         {
00135             /* Service was found, send the real query */
00136             ErrorCode = WSALookupServiceNextA(RnRHandle,
00137                                               0,
00138                                               &Length,
00139                                               WsaQuery);
00140 
00141             /* Return the information requested */
00142             if(ErrorCode == ERROR_SUCCESS) 
00143             {
00144                 /* Get the Blob and check if we have one */
00145                 Blob = WsaQuery->lpBlob;
00146                 if(Blob) 
00147                 {
00148                     /* Did they want the name back? */
00149                     if(NewName) *NewName = WsaQuery->lpszServiceInstanceName;
00150                 } 
00151                 else 
00152                 {
00153                     /* Check if this was a Hostname lookup */
00154                     if (Type == &HostnameGuid)
00155                     {
00156                         /* Return the name anyways */
00157                         if(NewName) *NewName = WsaQuery->lpszServiceInstanceName;
00158                     }
00159                     else
00160                     {
00161                         /* We don't have a blob, sorry */
00162                         ErrorCode = WSANO_DATA;
00163                     }
00164                 }
00165             } 
00166             else 
00167             {
00168                 /* WSALookupServiceEnd will set its own error, so save ours */
00169                 ErrorCode = GetLastError();
00170 
00171                 /* Check if we failed because of missing buffer space */
00172                 if ((ErrorCode == WSAEFAULT) && (Length > RNR_BUFFER_SIZE))
00173                 {
00174                     /* Allocate a new buffer */
00175                     NewResults = HeapAlloc(WsSockHeap, 0, Length);
00176                     if (NewResults)
00177                     {
00178                         /* Tell the caller his new buffer */
00179                         *Results = NewResults;
00180 
00181                         /* Update the WSA Query's location */
00182                         WsaQuery = (PWSAQUERYSETA)NewResults;
00183 
00184                         /* Loop again */
00185                         continue;
00186                     }
00187                     else
00188                     {
00189                         /* No memory to allocate the new buffer */
00190                         ErrorCode = WSA_NOT_ENOUGH_MEMORY;
00191                     }
00192                 }
00193             }
00194         
00195             /* Finish the Query Request */
00196             WSALookupServiceEnd(RnRHandle);
00197 
00198             /* Now set the Last Error */
00199             if(ErrorCode != ERROR_SUCCESS) SetLastError(ErrorCode);
00200 
00201             /* Leave the loop */
00202             break;
00203         }
00204     }
00205 
00206     /* Return the blob */
00207     return Blob;
00208 }
00209 
00210 /*
00211  * @implemented
00212  */
00213 PHOSTENT
00214 WSAAPI
00215 gethostbyname(IN const char FAR * name)
00216 {
00217     PHOSTENT Hostent;
00218     LPBLOB Blob;
00219     INT ErrorCode;
00220     CHAR ResultsBuffer[RNR_BUFFER_SIZE];
00221     PCHAR Results = ResultsBuffer;
00222     CHAR szLocalName[200];
00223     PCHAR pszName;
00224     PWSPROCESS Process;
00225     PWSTHREAD Thread;
00226     DPRINT("gethostbyname: %s\n", name);
00227 
00228     /* Enter prolog */
00229     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00230     {
00231         /* Leave now */
00232         SetLastError(ErrorCode);
00233         return NULL;
00234     }
00235 
00236     /* Check if no name was given */
00237     if(!name || !*name) 
00238     {
00239         /* This means we should do a local lookup first */
00240         if(gethostname(szLocalName, 200) != NO_ERROR) return(NULL);
00241         pszName = szLocalName;
00242     } 
00243     else 
00244     {
00245         /* Use the name tha twas given to us */
00246         pszName = (PCHAR)name;
00247     }
00248 
00249     /* Get the Hostname in a Blob Structure */
00250     Blob = getxyDataEnt(&Results,
00251                         RNR_BUFFER_SIZE,
00252                         pszName,
00253                         &HostAddrByNameGuid,
00254                         0);
00255     
00256     /* Check if we didn't get a blob, or if we got an empty name */
00257     if (!(Blob) && (!(name) || !(*name)))
00258     {
00259         /* Try a new query */
00260         Blob = getxyDataEnt(&Results,
00261                             RNR_BUFFER_SIZE,
00262                             NULL,
00263                             &HostAddrByNameGuid,
00264                             0);
00265     }
00266 
00267     /* Check if we got a blob */
00268     if(Blob) 
00269     {
00270         /* Copy the blob to our buffer and convert it */
00271         Hostent = WsThreadBlobToHostent(Thread, Blob);
00272 
00273         /* Unpack the hostent */
00274         if(Hostent) UnpackHostEnt(Hostent);
00275     } 
00276     else 
00277     {
00278         /* We failed, so zero it out */
00279         Hostent = 0;
00280 
00281         /* Normalize the error message */
00282         if(GetLastError() == WSASERVICE_NOT_FOUND) 
00283         {
00284             SetLastError(WSAHOST_NOT_FOUND);
00285         }
00286     }
00287 
00288     /* Check if we received a newly allocated buffer; free it. */
00289     if (Results != ResultsBuffer) HeapFree(WsSockHeap, 0, Results);
00290 
00291     /* Notify RAS Auto-dial helper */
00292     if (Hostent) WSNoteSuccessfulHostentLookup(name, *Hostent->h_addr);
00293 
00294     /* Return the hostent */
00295     return Hostent;
00296 }
00297 
00298 /*
00299  * @implemented
00300  */
00301 PHOSTENT
00302 WSAAPI
00303 gethostbyaddr(IN const char FAR * addr,
00304               IN int len,
00305               IN int type)
00306 {
00307     CHAR AddressBuffer[100];
00308     PHOSTENT Hostent;
00309     LPBLOB Blob;
00310     CHAR ResultsBuffer[RNR_BUFFER_SIZE];
00311     PCHAR Results = ResultsBuffer;
00312     PWSPROCESS Process;
00313     PWSTHREAD Thread;
00314     INT ErrorCode;
00315     DPRINT("gethostbyaddr: %s\n", addr);
00316 
00317     /* Enter prolog */
00318     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00319     {
00320         /* Leave now */
00321         SetLastError(ErrorCode);
00322         return NULL;
00323     }
00324 
00325     /* Check for valid address pointer */
00326     if (!addr)
00327     {
00328         /* Fail */
00329         SetLastError(WSAEINVAL);
00330         return NULL;
00331     }
00332 
00333     /* Check which type it is */
00334     if (type == AF_INET)
00335     {
00336         /* Use IPV4 Address to String */
00337         Local_Ip4AddresstoString(AddressBuffer, (PCHAR)addr);
00338     }
00339     else if (type == AF_INET6)
00340     {
00341         /* Use IPV6 Address to String */
00342         Local_Ip6AddresstoString(AddressBuffer, (PCHAR)addr);
00343     }
00344     else
00345     {
00346         /* Invalid address type; fail */
00347         SetLastError(WSAEINVAL);
00348         return NULL;
00349     }
00350 
00351     /* Get the Hostname in a Blob Structure */
00352     Blob = getxyDataEnt(&Results,
00353                         RNR_BUFFER_SIZE,
00354                         AddressBuffer,
00355                         &AddressGuid,
00356                         0);
00357     
00358     /* Check if we got a blob */
00359     if(Blob) 
00360     {
00361         /* Copy the blob to our buffer and convert it */
00362         Hostent = WsThreadBlobToHostent(Thread, Blob);
00363 
00364         /* Unpack the hostent */
00365         if(Hostent) UnpackHostEnt(Hostent);
00366     } 
00367     else 
00368     {
00369         /* We failed, so zero it out */
00370         Hostent = 0;
00371 
00372         /* Normalize the error message */
00373         if(GetLastError() == WSASERVICE_NOT_FOUND) 
00374         {
00375             SetLastError(WSAHOST_NOT_FOUND);
00376         }
00377     }
00378 
00379     /* Check if we received a newly allocated buffer; free it. */
00380     if (Results != ResultsBuffer) HeapFree(WsSockHeap, 0, Results);
00381 
00382     /* Return the hostent */
00383     return Hostent;
00384 }
00385 
00386 /*
00387  * @implemented
00388  */
00389 INT
00390 WSAAPI
00391 gethostname(OUT char FAR * name,
00392             IN int namelen)
00393 {
00394     PCHAR Name;
00395     CHAR ResultsBuffer[RNR_BUFFER_SIZE];
00396     PCHAR Results = ResultsBuffer;
00397     DPRINT("gethostname: %p\n", name);
00398 
00399     /* Get the Hostname in a String */
00400     if(getxyDataEnt(&Results, RNR_BUFFER_SIZE, NULL, &HostnameGuid, &Name))
00401     {
00402         /* Copy it */
00403         strcpy((LPSTR)name, Name);
00404     }
00405 
00406     /* Check if we received a newly allocated buffer; free it. */
00407     if (Results != ResultsBuffer) HeapFree(WsSockHeap, 0, Results);
00408 
00409     /* Return success */
00410     return ERROR_SUCCESS;
00411 }
00412 
00413 /*
00414  * @implemented
00415  */
00416 PSERVENT
00417 WSAAPI
00418 getservbyport(IN int port,
00419               IN const char FAR * proto)
00420 {
00421     PSERVENT Servent;
00422     LPBLOB Blob;
00423     CHAR ResultsBuffer[RNR_BUFFER_SIZE];
00424     PCHAR Results = ResultsBuffer;
00425     PCHAR PortName;
00426     PWSPROCESS Process;
00427     PWSTHREAD Thread;
00428     INT ErrorCode;
00429     DPRINT("getservbyport: %s\n", proto);
00430 
00431     /* Enter prolog */
00432     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00433     {
00434         /* Leave now */
00435         SetLastError(ErrorCode);
00436         return NULL;
00437     }
00438 
00439     /* No protocol specifed */
00440     if(!proto) proto = "";
00441 
00442     /* Allocate memory for the port name */
00443     PortName = HeapAlloc(WsSockHeap, 0, strlen(proto) + 1 + 1 + 5);
00444     if (!PortName)
00445     {
00446         /* Fail */
00447         SetLastError(WSA_NOT_ENOUGH_MEMORY);
00448         return NULL;
00449     }
00450 
00451     /* Put it into the right syntax */
00452     sprintf(PortName, "%d/%s", (port & 0xffff), proto);
00453 
00454     /* Get the Service in a Blob */
00455     Blob = getxyDataEnt(&Results, RNR_BUFFER_SIZE, PortName, &IANAGuid, 0);
00456 
00457     /* Free the string we sent */
00458     HeapFree(WsSockHeap, 0, PortName);
00459 
00460     /* Check if we got a blob */
00461     if(Blob) 
00462     {
00463         /* Copy the blob to our buffer and convert it */
00464         Servent = WsThreadBlobToServent(Thread, Blob);
00465 
00466         /* Unpack the hostent */
00467         if(Servent) UnpackServEnt(Servent);
00468     } 
00469     else 
00470     {
00471         /* We failed, so zero it out */
00472         Servent = 0;
00473 
00474         /* Normalize the error message */
00475         if(GetLastError() == WSATYPE_NOT_FOUND) SetLastError(WSANO_DATA);
00476     }
00477 
00478     /* Check if we received a newly allocated buffer; free it. */
00479     if (Results != ResultsBuffer) HeapFree(WsSockHeap, 0, Results);
00480 
00481     /* Return the hostent */
00482     return Servent;
00483 }
00484 
00485 /*
00486  * @implemented
00487  */
00488 PSERVENT
00489 WSAAPI
00490 getservbyname(IN const char FAR * name,
00491               IN const char FAR * proto)
00492 {
00493     PSERVENT Servent;
00494     LPBLOB Blob;
00495     CHAR ResultsBuffer[RNR_BUFFER_SIZE];
00496     PCHAR Results = ResultsBuffer;
00497     PCHAR PortName;
00498     PWSPROCESS Process;
00499     PWSTHREAD Thread;
00500     INT ErrorCode;
00501     DPRINT("getservbyname: %s\n", name);
00502 
00503     /* Enter prolog */
00504     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00505     {
00506         /* Leave now */
00507         SetLastError(ErrorCode);
00508         return NULL;
00509     }
00510 
00511     /* No protocol specifed */
00512     if(!proto) proto = "";
00513 
00514     /* Allocate buffer for it */
00515     PortName = HeapAlloc(WsSockHeap, 0, strlen(proto) + 1 + strlen(name) + 1);
00516     if (!PortName)
00517     {
00518         /* Fail */
00519         SetLastError(WSA_NOT_ENOUGH_MEMORY);
00520         return NULL;
00521     }
00522 
00523     /* Put it into the right syntax */
00524     sprintf(PortName, "%s/%s", name, proto);
00525 
00526     /* Get the Service in a Blob */
00527     Blob = getxyDataEnt(&Results, RNR_BUFFER_SIZE, PortName, &IANAGuid, 0);
00528 
00529     /* Free the string we sent */
00530     HeapFree(WsSockHeap, 0, PortName);
00531 
00532     /* Check if we got a blob */
00533     if(Blob) 
00534     {
00535         /* Copy the blob to our buffer and convert it */
00536         Servent = WsThreadBlobToServent(Thread, Blob);
00537 
00538         /* Unpack the hostent */
00539         if(Servent) UnpackServEnt(Servent);
00540     } 
00541     else 
00542     {
00543         /* We failed, so zero it out */
00544         Servent = 0;
00545 
00546         /* Normalize the error message */
00547         if(GetLastError() == WSATYPE_NOT_FOUND) SetLastError(WSANO_DATA);
00548     }
00549 
00550     /* Check if we received a newly allocated buffer; free it. */
00551     if (Results != ResultsBuffer) HeapFree(WsSockHeap, 0, Results);
00552 
00553     /* Return the hostent */
00554     return Servent;
00555 }
00556 
00557 /*
00558  * @implemented
00559  */
00560 HANDLE
00561 WSAAPI
00562 WSAAsyncGetHostByAddr(IN HWND hWnd,
00563                       IN UINT wMsg,
00564                       IN CONST CHAR FAR *Address, 
00565                       IN INT Length,
00566                       IN INT Type, 
00567                       OUT CHAR FAR *Buffer, 
00568                       IN INT BufferLength)
00569 {
00570     HANDLE TaskHandle;
00571     PWSPROCESS Process;
00572     PWSTHREAD Thread;
00573     PVOID AddressCopy;
00574     PWSASYNCBLOCK AsyncBlock;
00575     INT ErrorCode;
00576     DPRINT("WSAAsyncGetHostByAddr: %lx, %lx, %s\n", hWnd, wMsg, Address);
00577 
00578     /* Enter prolog */
00579     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00580     {
00581         /* Leave now */
00582         SetLastError(ErrorCode);
00583         return NULL;
00584     }
00585 
00586     /* Initialize the Async Thread */
00587     if (!WsAsyncCheckAndInitThread())
00588     {
00589         /* Fail */
00590         SetLastError(WSAENOBUFS);
00591         return NULL;
00592     }
00593 
00594     /* Allocate an async block */
00595     if (!(AsyncBlock = WsAsyncAllocateBlock(Length)))
00596     {
00597         /* Fail */
00598         SetLastError(WSAENOBUFS);
00599         return NULL;
00600     }
00601 
00602     /* Make a copy of the address */
00603     AddressCopy = AsyncBlock + 1;
00604     RtlMoveMemory(AddressCopy, Address, Length);
00605 
00606     /* Initialize the Async Block */
00607     AsyncBlock->Operation = WsAsyncGetHostByAddr;
00608     AsyncBlock->GetHost.hWnd = hWnd;
00609     AsyncBlock->GetHost.wMsg = wMsg;
00610     AsyncBlock->GetHost.ByWhat = AddressCopy;
00611     AsyncBlock->GetHost.Length = Length;
00612     AsyncBlock->GetHost.Type = Type;
00613     AsyncBlock->GetHost.Buffer = Buffer;
00614     AsyncBlock->GetHost.BufferLength = BufferLength;
00615 
00616     /* Save the task handle and queue the request */
00617     TaskHandle = AsyncBlock->TaskHandle;
00618     WsAsyncQueueRequest(AsyncBlock);
00619 
00620     /* Return the task handle */
00621     return TaskHandle;
00622 }
00623 
00624 /*
00625  * @implemented
00626  */
00627 HANDLE
00628 WSAAPI
00629 WSAAsyncGetHostByName(IN HWND hWnd, 
00630                       IN UINT wMsg,  
00631                       IN CONST CHAR FAR *Name, 
00632                       OUT CHAR FAR *Buffer, 
00633                       IN INT BufferLength)
00634 {
00635     HANDLE TaskHandle;
00636     PWSPROCESS Process;
00637     PWSTHREAD Thread;
00638     PWSASYNCBLOCK AsyncBlock;
00639     INT ErrorCode;
00640     PVOID NameCopy;
00641     DPRINT("WSAAsyncGetProtoByNumber: %lx, %lx, %s\n", hWnd, wMsg, Name);
00642 
00643     /* Enter prolog */
00644     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00645     {
00646         /* Leave now */
00647         SetLastError(ErrorCode);
00648         return NULL;
00649     }
00650 
00651     /* Initialize the Async Thread */
00652     if (!WsAsyncCheckAndInitThread())
00653     {
00654         /* Fail */
00655         SetLastError(WSAENOBUFS);
00656         return NULL;
00657     }
00658 
00659     /* Allocate an async block */
00660     if (!(AsyncBlock = WsAsyncAllocateBlock(strlen(Name) + sizeof(CHAR))))
00661     {
00662         /* Fail */
00663         SetLastError(WSAENOBUFS);
00664         return NULL;
00665     }
00666 
00667     /* Make a copy of the address */
00668     NameCopy = AsyncBlock + 1;
00669     strcpy(NameCopy, Name);
00670 
00671     /* Initialize the Async Block */
00672     AsyncBlock->Operation = WsAsyncGetHostByName;
00673     AsyncBlock->GetHost.hWnd = hWnd;
00674     AsyncBlock->GetHost.wMsg = wMsg;
00675     AsyncBlock->GetHost.ByWhat = NameCopy;
00676     AsyncBlock->GetHost.Buffer = Buffer;
00677     AsyncBlock->GetHost.BufferLength = BufferLength;
00678 
00679     /* Save the task handle and queue the request */
00680     TaskHandle = AsyncBlock->TaskHandle;
00681     WsAsyncQueueRequest(AsyncBlock);
00682 
00683     /* Return the task handle */
00684     return TaskHandle;
00685 }
00686 
00687 /*
00688  * @implemented
00689  */
00690 HANDLE
00691 WSAAPI
00692 WSAAsyncGetProtoByName(IN HWND hWnd,
00693                        IN UINT wMsg,
00694                        IN CONST CHAR FAR *Name,
00695                        OUT CHAR FAR *Buffer,
00696                        IN INT BufferLength)
00697 {
00698     HANDLE TaskHandle;
00699     PWSPROCESS Process;
00700     PWSTHREAD Thread;
00701     PWSASYNCBLOCK AsyncBlock;
00702     INT ErrorCode;
00703     PVOID NameCopy;
00704     DPRINT("WSAAsyncGetProtoByName: %lx, %lx, %s\n", hWnd, wMsg, Name);
00705 
00706     /* Enter prolog */
00707     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00708     {
00709         /* Leave now */
00710         SetLastError(ErrorCode);
00711         return NULL;
00712     }
00713 
00714     /* Initialize the Async Thread */
00715     if (!WsAsyncCheckAndInitThread())
00716     {
00717         /* Fail */
00718         SetLastError(WSAENOBUFS);
00719         return NULL;
00720     }
00721 
00722     /* Allocate an async block */
00723     if (!(AsyncBlock = WsAsyncAllocateBlock(strlen(Name) + sizeof(CHAR))))
00724     {
00725         /* Fail */
00726         SetLastError(WSAENOBUFS);
00727         return NULL;
00728     }
00729 
00730     /* Make a copy of the address */
00731     NameCopy = AsyncBlock + 1;
00732     strcpy(NameCopy, Name);
00733 
00734     /* Initialize the Async Block */
00735     AsyncBlock->Operation = WsAsyncGetProtoByName;
00736     AsyncBlock->GetProto.hWnd = hWnd;
00737     AsyncBlock->GetProto.wMsg = wMsg;
00738     AsyncBlock->GetProto.ByWhat = NameCopy;
00739     AsyncBlock->GetProto.Buffer = Buffer;
00740     AsyncBlock->GetProto.BufferLength = BufferLength;
00741 
00742     /* Save the task handle and queue the request */
00743     TaskHandle = AsyncBlock->TaskHandle;
00744     WsAsyncQueueRequest(AsyncBlock);
00745 
00746     /* Return the task handle */
00747     return TaskHandle;
00748 }
00749 
00750 /*
00751  * @implemented
00752  */
00753 HANDLE
00754 WSAAPI
00755 WSAAsyncGetProtoByNumber(IN HWND hWnd,
00756                          IN UINT wMsg,
00757                          IN INT Number,
00758                          OUT CHAR FAR* Buffer,
00759                          IN INT BufferLength)
00760 {
00761     HANDLE TaskHandle;
00762     PWSPROCESS Process;
00763     PWSTHREAD Thread;
00764     PWSASYNCBLOCK AsyncBlock;
00765     INT ErrorCode;
00766     DPRINT("WSAAsyncGetProtoByNumber: %lx, %lx, %lx\n", hWnd, wMsg, Number);
00767     
00768     /* Enter prolog */
00769     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00770     {
00771         /* Leave now */
00772         SetLastError(ErrorCode);
00773         return NULL;
00774     }
00775 
00776     /* Initialize the Async Thread */
00777     if (!WsAsyncCheckAndInitThread())
00778     {
00779         /* Fail */
00780         SetLastError(WSAENOBUFS);
00781         return NULL;
00782     }
00783 
00784     /* Allocate an async block */
00785     if (!(AsyncBlock = WsAsyncAllocateBlock(0)))
00786     {
00787         /* Fail */
00788         SetLastError(WSAENOBUFS);
00789         return NULL;
00790     }
00791 
00792     /* Initialize the Async Block */
00793     AsyncBlock->Operation = WsAsyncGetProtoByNumber;
00794     AsyncBlock->GetProto.hWnd = hWnd;
00795     AsyncBlock->GetProto.wMsg = wMsg;
00796     AsyncBlock->GetProto.ByWhat = UlongToPtr(Number);
00797     AsyncBlock->GetProto.Buffer = Buffer;
00798     AsyncBlock->GetProto.BufferLength = BufferLength;
00799 
00800     /* Save the task handle and queue the request */
00801     TaskHandle = AsyncBlock->TaskHandle;
00802     WsAsyncQueueRequest(AsyncBlock);
00803 
00804     /* Return the task handle */
00805     return TaskHandle;
00806 }
00807 
00808 /*
00809  * @implemented
00810  */
00811 HANDLE
00812 WSAAPI
00813 WSAAsyncGetServByName(IN HWND hWnd,
00814                       IN UINT wMsg,
00815                       IN CONST CHAR FAR *Name,
00816                       IN CONST CHAR FAR *Protocol,
00817                       OUT CHAR FAR *Buffer,
00818                       IN INT BufferLength)
00819 {
00820     HANDLE TaskHandle;
00821     PWSPROCESS Process;
00822     PWSTHREAD Thread;
00823     PWSASYNCBLOCK AsyncBlock;
00824     INT ErrorCode;
00825     PVOID NameCopy;
00826     DPRINT("WSAAsyncGetProtoByNumber: %lx, %lx, %s\n", hWnd, wMsg, Name);
00827     
00828     /* Enter prolog */
00829     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00830     {
00831         /* Leave now */
00832         SetLastError(ErrorCode);
00833         return NULL;
00834     }
00835 
00836     /* Initialize the Async Thread */
00837     if (!WsAsyncCheckAndInitThread())
00838     {
00839         /* Fail */
00840         SetLastError(WSAENOBUFS);
00841         return NULL;
00842     }
00843 
00844     /* Allocate an async block */
00845     if (!(AsyncBlock = WsAsyncAllocateBlock(strlen(Name) + sizeof(CHAR))))
00846     {
00847         /* Fail */
00848         SetLastError(WSAENOBUFS);
00849         return NULL;
00850     }
00851 
00852     /* Make a copy of the address */
00853     NameCopy = AsyncBlock + 1;
00854     strcpy(NameCopy, Name);
00855 
00856     /* Initialize the Async Block */
00857     AsyncBlock->Operation = WsAsyncGetProtoByName;
00858     AsyncBlock->GetServ.hWnd = hWnd;
00859     AsyncBlock->GetServ.wMsg = wMsg;
00860     AsyncBlock->GetServ.ByWhat = NameCopy;
00861     AsyncBlock->GetServ.Protocol = (PCHAR)Protocol;
00862     AsyncBlock->GetServ.Buffer = Buffer;
00863     AsyncBlock->GetServ.BufferLength = BufferLength;
00864 
00865     /* Save the task handle and queue the request */
00866     TaskHandle = AsyncBlock->TaskHandle;
00867     WsAsyncQueueRequest(AsyncBlock);
00868 
00869     /* Return the task handle */
00870     return TaskHandle;
00871 }
00872 
00873 /*
00874  * @implemented
00875  */
00876 HANDLE
00877 WSAAPI
00878 WSAAsyncGetServByPort(IN HWND hWnd,
00879                       IN UINT wMsg,
00880                       IN INT Port,
00881                       IN CONST CHAR FAR *Protocol,
00882                       OUT CHAR FAR *Buffer,
00883                       IN INT BufferLength)
00884 {
00885     HANDLE TaskHandle;
00886     PWSPROCESS Process;
00887     PWSTHREAD Thread;
00888     PWSASYNCBLOCK AsyncBlock;
00889     INT ErrorCode;
00890     DPRINT("WSAAsyncGetProtoByNumber: %lx, %lx, %lx\n", hWnd, wMsg, Port);
00891     
00892     /* Enter prolog */
00893     if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
00894     {
00895         /* Leave now */
00896         SetLastError(ErrorCode);
00897         return NULL;
00898     }
00899 
00900     /* Initialize the Async Thread */
00901     if (!WsAsyncCheckAndInitThread())
00902     {
00903         /* Fail */
00904         SetLastError(WSAENOBUFS);
00905         return NULL;
00906     }
00907 
00908     /* Allocate an async block */
00909     if (!(AsyncBlock = WsAsyncAllocateBlock(0)))
00910     {
00911         /* Fail */
00912         SetLastError(WSAENOBUFS);
00913         return NULL;
00914     }
00915 
00916     /* Initialize the Async Block */
00917     AsyncBlock->Operation = WsAsyncGetServByPort;
00918     AsyncBlock->GetServ.hWnd = hWnd;
00919     AsyncBlock->GetServ.wMsg = wMsg;
00920     AsyncBlock->GetServ.ByWhat = UlongToPtr(Port);
00921     AsyncBlock->GetServ.Protocol = (PCHAR)Protocol;
00922     AsyncBlock->GetServ.Buffer = Buffer;
00923     AsyncBlock->GetServ.BufferLength = BufferLength;
00924 
00925     /* Save the task handle and queue the request */
00926     TaskHandle = AsyncBlock->TaskHandle;
00927     WsAsyncQueueRequest(AsyncBlock);
00928 
00929     /* Return the task handle */
00930     return TaskHandle;
00931 }
00932 
00933 /*
00934  * @implemented
00935  */
00936 INT
00937 WSAAPI
00938 WSACancelAsyncRequest(IN HANDLE hAsyncTaskHandle)
00939 {
00940     PWSPROCESS Process;
00941     PWSTHREAD Thread;
00942     INT ErrorCode;
00943     DPRINT("WSACancelAsyncRequest: %lx\n", hAsyncTaskHandle);
00944     
00945     /* Enter prolog */
00946     if ((ErrorCode = WsApiProlog(&Process, &Thread)) == ERROR_SUCCESS)
00947     {
00948         /* Call the Async code */
00949         ErrorCode = WsAsyncCancelRequest(hAsyncTaskHandle);
00950 
00951         /* Return */
00952         if (ErrorCode == ERROR_SUCCESS) return ERROR_SUCCESS;
00953     }
00954     
00955     /* Fail */
00956     SetLastError(ErrorCode);
00957     return SOCKET_ERROR;
00958 }

Generated on Sun May 27 2012 04:27:09 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.