Small changes to debug output in catalog, handle, upcall.

ns.c -- getservbyport contributed by Cameron Palmer.

svn path=/trunk/; revision=10121
This commit is contained in:
Art Yerkes
2004-07-15 02:03:07 +00:00
parent c26b523ad9
commit 9ce1fe0ddb
6 changed files with 176 additions and 9 deletions
+9
View File
@@ -37,11 +37,20 @@ typedef struct _WINSOCK_GETSERVBYNAME_CACHE {
CHAR Data[1];
} WINSOCK_GETSERVBYNAME_CACHE, *PWINSOCK_GETSERVBYNAME_CACHE;
typedef struct _WINSOCK_GETSERVBYPORT_CACHE {
UINT Size;
SERVENT ServerEntry;
PCHAR Aliases[WS2_INTERNAL_MAX_ALIAS];
CHAR Data[1];
} WINSOCK_GETSERVBYPORT_CACHE, *PWINSOCK_GETSERVBYPORT_CACHE;
typedef struct _WINSOCK_THREAD_BLOCK {
INT LastErrorValue; /* Error value from last function that failed */
CHAR Intoa[16]; /* Buffer for inet_ntoa() */
PWINSOCK_GETSERVBYNAME_CACHE
Getservbyname; /* Buffer used by getservbyname */
PWINSOCK_GETSERVBYPORT_CACHE
Getservbyport; /* Buffer used by getservbyname */
} WINSOCK_THREAD_BLOCK, *PWINSOCK_THREAD_BLOCK;
+2 -2
View File
@@ -188,7 +188,7 @@ INT LoadProvider(
{
INT Status;
WS_DbgPrint(MAX_TRACE, ("Loading provider at (0x%X) Name (%wZ).\n",
WS_DbgPrint(MID_TRACE, ("Loading provider at (0x%X) Name (%wZ).\n",
Provider, &Provider->LibraryName));
if (NULL == Provider->hModule)
@@ -221,7 +221,7 @@ INT LoadProvider(
} else
Status = NO_ERROR;
WS_DbgPrint(MAX_TRACE, ("Status (%d).\n", Status));
WS_DbgPrint(MID_TRACE, ("Status (%d).\n", Status));
return Status;
}
+1
View File
@@ -668,6 +668,7 @@ DllMain(HANDLE hInstDll,
p->LastErrorValue = NO_ERROR;
p->Getservbyname = NULL;
p->Getservbyport = NULL;
NtCurrentTeb()->WinSockData = p;
break;
+7 -1
View File
@@ -161,6 +161,8 @@ CreateProviderHandleTable(
NewBlock = (PPROVIDER_HANDLE_BLOCK)HeapAlloc(
GlobalHeap, 0, sizeof(PROVIDER_HANDLE_BLOCK));
WS_DbgPrint(MID_TRACE,("using table entry %x\n", NewBlock));
if (!NewBlock)
return (HANDLE)0;
@@ -209,12 +211,14 @@ ReferenceProviderByHandle(
{
PPROVIDER_HANDLE ProviderHandle;
WS_DbgPrint(MAX_TRACE, ("Handle (0x%X) Provider (0x%X).\n", Handle, Provider));
WS_DbgPrint(MID_TRACE, ("Handle (0x%X) Provider (0x%X).\n", Handle, Provider));
EnterCriticalSection(&ProviderHandleTableLock);
ProviderHandle = GetProviderByHandle(ProviderHandleTable, Handle);
WS_DbgPrint(MID_TRACE, ("ProviderHanddle is %x\n", ProviderHandle));
LeaveCriticalSection(&ProviderHandleTableLock);
if (ProviderHandle) {
@@ -256,6 +260,8 @@ InitProviderHandleTable(VOID)
if (!ProviderHandleTable)
return FALSE;
WS_DbgPrint(MID_TRACE,("Called\n"));
ZeroMemory(ProviderHandleTable, sizeof(PROVIDER_HANDLE_BLOCK));
InitializeListHead(&ProviderHandleTable->Entry);
+156 -5
View File
@@ -7,7 +7,6 @@
* REVISIONS:
* CSH 01/09-2000 Created
*/
#define __NO_CTYPE_INLINES
#include <ctype.h>
#include <ws2_32.h>
@@ -482,6 +481,7 @@ static BOOL DecodeServEntFromString( IN PCHAR ServiceString,
LPSERVENT
EXPORT
getservbyname(
IN CONST CHAR FAR* name,
IN CONST CHAR FAR* proto)
{
@@ -568,8 +568,8 @@ getservbyname(
WS2_INTERNAL_MAX_ALIAS ) &&
!strcmp( ServiceName, name ) &&
(proto ? !strcmp( ProtocolStr, proto ) : TRUE) ) {
WS_DbgPrint(MAX_TRACE,("Found the service entry.\n"));
WS_DbgPrint(MAX_TRACE,("Found the service entry.\n"));
Found = TRUE;
SizeNeeded = sizeof(WINSOCK_GETSERVBYNAME_CACHE) +
(NextLine - ThisLine);
@@ -640,7 +640,7 @@ getservbyname(
/*
* @unimplemented
* @implemented
*/
LPSERVENT
EXPORT
@@ -648,9 +648,160 @@ getservbyport(
IN INT port,
IN CONST CHAR FAR* proto)
{
UNIMPLEMENTED
BOOL Found = FALSE;
HANDLE ServicesFile;
CHAR ServiceDBData[BUFSIZ] = { 0 };
PCHAR SystemDirectory = ServiceDBData; /* Reuse this stack space */
PCHAR ServicesFileLocation = "\\drivers\\etc\\services";
PCHAR ThisLine = 0, NextLine = 0, ServiceName = 0, PortNumberStr = 0,
ProtocolStr = 0, Comment = 0;
PCHAR Aliases[WS2_INTERNAL_MAX_ALIAS] = { 0 };
UINT i,SizeNeeded = 0,
SystemDirSize = sizeof(ServiceDBData) - 1;
DWORD ReadSize = 0, ValidData = 0;
PWINSOCK_THREAD_BLOCK p = NtCurrentTeb()->WinSockData;
if( !p ) {
WSASetLastError( WSANOTINITIALISED );
return NULL;
}
if ( !port ) {
WSASetLastError( WSANO_RECOVERY );
return NULL;
}
if( !GetSystemDirectoryA( SystemDirectory, SystemDirSize ) ) {
WSASetLastError( WSANO_RECOVERY );
WS_DbgPrint(MIN_TRACE, ("Could not get windows system directory.\n"));
return NULL; /* Can't get system directory */
}
strncat( SystemDirectory, ServicesFileLocation, SystemDirSize );
ServicesFile = CreateFileA( SystemDirectory,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_SEQUENTIAL_SCAN,
NULL );
if( ServicesFile == INVALID_HANDLE_VALUE ) {
WSASetLastError( WSANO_RECOVERY );
return NULL;
}
/* Scan the services file ...
*
* We will read up to BUFSIZ bytes per pass, until the buffer does not
* contain a full line, then we will try to read more.
*
* We fall from the loop if the buffer does not have a line terminator.
*/
/* Initial Read */
while( !Found &&
ReadFile( ServicesFile, ServiceDBData + ValidData,
sizeof( ServiceDBData ) - ValidData,
&ReadSize, NULL ) ) {
ValidData += ReadSize;
ReadSize = 0;
NextLine = ThisLine = ServiceDBData;
/* Find the beginning of the next line */
while( NextLine < ServiceDBData + ValidData &&
*NextLine != '\r' && *NextLine != '\n' ) NextLine++;
/* Zero and skip, so we can treat what we have as a string */
if( NextLine >= ServiceDBData + ValidData )
break;
*NextLine = 0; NextLine++;
Comment = strchr( ThisLine, '#' );
if( Comment ) *Comment = 0; /* Terminate at comment start */
if( DecodeServEntFromString( ThisLine,
&ServiceName,
&PortNumberStr,
&ProtocolStr,
Aliases,
WS2_INTERNAL_MAX_ALIAS ) &&
(htons(atoi( PortNumberStr )) == port ) &&
(proto ? !strcmp( ProtocolStr, proto ) : TRUE) ) {
WS_DbgPrint(MAX_TRACE,("Found the port entry.\n"));
Found = TRUE;
SizeNeeded = sizeof(WINSOCK_GETSERVBYPORT_CACHE) +
(NextLine - ThisLine);
break;
}
/* Get rid of everything we read so far */
while( NextLine <= ServiceDBData + ValidData &&
isspace( *NextLine ) ) NextLine++;
WS_DbgPrint(MAX_TRACE,("About to move %d chars\n",
ServiceDBData + ValidData - NextLine));
memmove( ServiceDBData, NextLine,
ServiceDBData + ValidData - NextLine );
ValidData -= NextLine - ServiceDBData;
WS_DbgPrint(MAX_TRACE,("Valid bytes: %d\n", ValidData));
}
/* This we'll do no matter what */
CloseHandle( ServicesFile );
if( !Found ) {
WS_DbgPrint(MAX_TRACE,("Not found\n"));
WSASetLastError( WSANO_DATA );
return NULL;
}
if( !p->Getservbyport || p->Getservbyport->Size < SizeNeeded ) {
/* Free previous getservbyport buffer, allocate bigger */
if( p->Getservbyport )
HeapFree(GlobalHeap, 0, p->Getservbyport);
p->Getservbyport = HeapAlloc(GlobalHeap, 0, SizeNeeded);
if( !p->Getservbyport ) {
WS_DbgPrint(MIN_TRACE,("Couldn't allocate %d bytes\n",
SizeNeeded));
WSASetLastError( WSATRY_AGAIN );
return NULL;
}
p->Getservbyport->Size = SizeNeeded;
}
/* Copy the data */
memmove( p->Getservbyport->Data,
ThisLine,
NextLine - ThisLine );
ADJ_PTR(PortNumberStr,ThisLine,p->Getservbyport->Data);
ADJ_PTR(ProtocolStr,ThisLine,p->Getservbyport->Data);
WS_DbgPrint(MAX_TRACE,
("Port Number: %s, Protocol: %s\n", PortNumberStr, ProtocolStr));
for( i = 0; Aliases[i]; i++ ) {
ADJ_PTR(Aliases[i],ThisLine,p->Getservbyport->Data);
WS_DbgPrint(MAX_TRACE,("Aliases %d: %s\n", i, Aliases[i]));
}
memcpy(p->Getservbyport,Aliases,sizeof(Aliases));
/* Create the struct proper */
p->Getservbyport->ServerEntry.s_name = ServiceName;
p->Getservbyport->ServerEntry.s_aliases = p->Getservbyport->Aliases;
p->Getservbyport->ServerEntry.s_port = port;
p->Getservbyport->ServerEntry.s_proto = ProtocolStr;
WS_DbgPrint(MID_TRACE,("s_name: %s\n", ServiceName));
return &p->Getservbyport->ServerEntry;
return (LPSERVENT)NULL;
}
+1 -1
View File
@@ -131,7 +131,7 @@ WPUModifyIFSHandle(
PCATALOG_ENTRY Provider;
SOCKET Socket;
WS_DbgPrint(MAX_TRACE, ("dwCatalogEntryId (%d) ProposedHandle (0x%X).\n",
WS_DbgPrint(MID_TRACE, ("dwCatalogEntryId (%d) ProposedHandle (0x%X).\n",
dwCatalogEntryId, ProposedHandle));
Provider = LocateProviderById(dwCatalogEntryId);