Commit in reactos/lib/ws2_32 on MAIN
include/ws2_32.h+91.8 -> 1.9
misc/catalog.c+2-21.12 -> 1.13
    /dllmain.c+11.15 -> 1.16
    /handle.c+7-11.4 -> 1.5
    /ns.c+156-51.8 -> 1.9
    /upcall.c+1-11.5 -> 1.6
+176-9
6 modified files
Small changes to debug output in catalog, handle, upcall.
ns.c -- getservbyport contributed by Cameron Palmer.

reactos/lib/ws2_32/include
ws2_32.h 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- ws2_32.h	9 Jun 2004 18:11:39 -0000	1.8
+++ ws2_32.h	15 Jul 2004 02:03:06 -0000	1.9
@@ -37,11 +37,20 @@
     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;
 
 

reactos/lib/ws2_32/misc
catalog.c 1.12 -> 1.13
diff -u -r1.12 -r1.13
--- catalog.c	3 Feb 2004 14:25:38 -0000	1.12
+++ catalog.c	15 Jul 2004 02:03:07 -0000	1.13
@@ -188,7 +188,7 @@
 {
   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 @@
   } else
     Status = NO_ERROR;
 
-  WS_DbgPrint(MAX_TRACE, ("Status (%d).\n", Status));
+  WS_DbgPrint(MID_TRACE, ("Status (%d).\n", Status));
 
   return Status;
 }

reactos/lib/ws2_32/misc
dllmain.c 1.15 -> 1.16
diff -u -r1.15 -r1.16
--- dllmain.c	9 Jun 2004 18:11:39 -0000	1.15
+++ dllmain.c	15 Jul 2004 02:03:07 -0000	1.16
@@ -668,6 +668,7 @@
 
     p->LastErrorValue = NO_ERROR;
     p->Getservbyname  = NULL;
+    p->Getservbyport  = NULL;
 
     NtCurrentTeb()->WinSockData = p;
     break;

reactos/lib/ws2_32/misc
handle.c 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- handle.c	4 Jul 2001 20:40:20 -0000	1.4
+++ handle.c	15 Jul 2004 02:03:07 -0000	1.5
@@ -161,6 +161,8 @@
   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 @@
 {
   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 @@
   if (!ProviderHandleTable)
     return FALSE;
 
+  WS_DbgPrint(MID_TRACE,("Called\n"));
+
   ZeroMemory(ProviderHandleTable, sizeof(PROVIDER_HANDLE_BLOCK));
 
   InitializeListHead(&ProviderHandleTable->Entry);

reactos/lib/ws2_32/misc
ns.c 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- ns.c	3 Jul 2004 17:40:24 -0000	1.8
+++ ns.c	15 Jul 2004 02:03:07 -0000	1.9
@@ -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 @@
 LPSERVENT
 EXPORT
 getservbyname(
+
     IN  CONST CHAR FAR* name, 
     IN  CONST CHAR FAR* proto)
 {
@@ -568,8 +568,8 @@
 				     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 @@
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 LPSERVENT
 EXPORT
@@ -648,9 +648,160 @@
     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;
 }
 
 

reactos/lib/ws2_32/misc
upcall.c 1.5 -> 1.6
diff -u -r1.5 -r1.6
--- upcall.c	10 Jul 2003 21:28:17 -0000	1.5
+++ upcall.c	15 Jul 2004 02:03:07 -0000	1.6
@@ -131,7 +131,7 @@
   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);
CVSspam 0.2.8