This is the wrong way to do it. A Namespace Service Provider should be written for DNS instead. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/win....
DNS is a TCP/IP thing. Other protocols have their own namespace system so ws2_32 should remain generic and not depend on dnsapi.
Casper
_____
From: ros-diffs-bounces@reactos.com [mailto:ros-diffs-bounces@reactos.com] On Behalf Of arty@osexperts.com Sent: 26. november 2004 00:33 To: ros-diffs@reactos.com Subject: [ros-diffs] [CVS reactos] Added gethostbyname implementation written by Adam Kelly (insulanus).
Commit in reactos/lib/ws2_32 on MAIN makefile <> +45 -44 1.18 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/makefile?rev=1.18&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/makefile.diff?r1=text&tr1=1.18&r2=text&tr2=1.19&f=h > 1.19 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/makefile?rev=1.19&content-type=text/x-cvsweb-markup include/ws2_32.h <> +8 1.9 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/include/ws2_32.h?rev=1.9&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/include/ws2_32.h.diff?r1=text&tr1=1.9&r2=text&tr2=1.10&f=h > 1.10 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/include/ws2_32.h?rev=1.10&content-type=text/x-cvsweb-markup misc/dllmain.c <> +11 1.18 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/dllmain.c?rev=1.18&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/dllmain.c.diff?r1=text&tr1=1.18&r2=text&tr2=1.19&f=h > 1.19 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/dllmain.c?rev=1.19&content-type=text/x-cvsweb-markup /event.c <> +6 1.6 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/event.c?rev=1.6&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/event.c.diff?r1=text&tr1=1.6&r2=text&tr2=1.7&f=h > 1.7 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/event.c?rev=1.7&content-type=text/x-cvsweb-markup /ns.c <> +1216 -989 1.9 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/ns.c?rev=1.9&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/ns.c.diff?r1=text&tr1=1.9&r2=text&tr2=1.10&f=h > 1.10 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/ns.c?rev=1.10&content-type=text/x-cvsweb-markup /stubs.c <> +1 -1 1.14 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/stubs.c?rev=1.14&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/stubs.c.diff?r1=text&tr1=1.14&r2=text&tr2=1.15&f=h > 1.15 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/stubs.c?rev=1.15&content-type=text/x-cvsweb-markup +1287 -1034 6 modified files
Added gethostbyname implementation written by Adam Kelly (insulanus).
- Mostly complete, does not support multiple returned a records or hosts file
though
- Relies on dnsapi
- Stores hostent struct in teb->Hostent _____
reactos http://cvs.reactos.com/cgi-bin/cvsweb/reactos /lib http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib /ws2_32 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32
makefile 1.18 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/makefile?rev=1.18&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/makefile.diff?r1=text&tr1=1.18&r2=text&tr2=1.19&f=h > 1.19 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/makefile?rev=1.19&content-type=text/x-cvsweb-markup diff -u -r1.18 -r1.19
--- makefile 17 Nov 2004 05:17:21 -0000 1.18
+++ makefile 25 Nov 2004 23:32:53 -0000 1.19
@@ -1,44 +1,45 @@
-# $Id: makefile,v 1.18 2004/11/17 05:17:21 arty Exp $
-
-PATH_TO_TOP = ../..
-
-TARGET_REGTESTS = yes
-
-TARGET_TYPE = dynlink
-
-TARGET_NAME = ws2_32
-
-TARGET_PCH = include/ws2_32.h
-
-TARGET_BASE = $(TARGET_BASE_LIB_W2_32)
-
-TARGET_CFLAGS = \
- -I./include \
- -Wall \
- -Werror \
- -fno-builtin \
- -DUNICODE \
- -DLE \
- -D__USE_W32API
-
-# require os code to explicitly request A/W version of structs/functions
-TARGET_CFLAGS += -D_DISABLE_TIDENTS
-
-TARGET_LFLAGS = -nostartfiles -nostdlib
-
-TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a
-
-TARGET_OBJECTS = \
- misc/bsd.o misc/catalog.o misc/dllmain.o \
- misc/event.o misc/handle.o misc/ns.o \
- misc/sndrcv.o misc/stubs.o misc/upcall.o
-
-DEP_OBJECTS = $(TARGET_OBJECTS)
-
-include $(PATH_TO_TOP)/rules.mak
-
-include $(TOOLS_PATH)/helper.mk
-
-include $(TOOLS_PATH)/depend.mk
-
-# EOF +# $Id: makefile,v 1.19 2004/11/25 23:32:53 arty Exp $
+
+PATH_TO_TOP = ../..
+
+TARGET_REGTESTS = yes
+
+TARGET_TYPE = dynlink
+
+TARGET_NAME = ws2_32
+
+TARGET_PCH = include/ws2_32.h
+
+TARGET_BASE = $(TARGET_BASE_LIB_W2_32)
+
+TARGET_CFLAGS = \
+ -I./include \
+ -Wall \
+ -Werror \
+ -fno-builtin \
+ -DUNICODE \
+ -DLE \
+ -D__USE_W32API \
+ -D_WIN32_WINNT=0x0500
+
+# require os code to explicitly request A/W version of structs/functions
+TARGET_CFLAGS += -D_DISABLE_TIDENTS
+
+TARGET_LFLAGS = -nostartfiles -nostdlib
+
+TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a dnsapi.a
+
+TARGET_OBJECTS = \
+ misc/bsd.o misc/catalog.o misc/dllmain.o \
+ misc/event.o misc/handle.o misc/ns.o \
+ misc/sndrcv.o misc/stubs.o misc/upcall.o
+
+DEP_OBJECTS = $(TARGET_OBJECTS)
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+include $(TOOLS_PATH)/depend.mk
+
+# EOF _____
reactos http://cvs.reactos.com/cgi-bin/cvsweb/reactos /lib http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib /ws2_32 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32 /include http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/include
ws2_32.h 1.9 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/include/ws2_32.h?rev=1.9&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/include/ws2_32.h.diff?r1=text&tr1=1.9&r2=text&tr2=1.10&f=h > 1.10 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/include/ws2_32.h?rev=1.10&content-type=text/x-cvsweb-markup diff -u -r1.9 -r1.10
--- ws2_32.h 15 Jul 2004 02:03:06 -0000 1.9
+++ ws2_32.h 25 Nov 2004 23:32:54 -0000 1.10
@@ -7,6 +7,7 @@
#ifndef __WS2_32_H
#define __WS2_32_H
+#include <roscfg.h> #include <ddk/ntddk.h>
#include <ddk/ntifs.h>
#include <ntos.h> @@ -17,6 +18,7 @@
#include <windows.h>
#undef assert
#include <debug.h> +#include <WinDNS.h> // DNS_A_DATA
/* Exported by ntdll.dll, but where is the prototype? */
unsigned long strtoul(const char *nptr, char **endptr, int base); @@ -51,6 +53,7 @@
Getservbyname; /* Buffer used by getservbyname */
PWINSOCK_GETSERVBYPORT_CACHE
Getservbyport; /* Buffer used by getservbyname */ + struct hostent* Hostent; } WINSOCK_THREAD_BLOCK, *PWINSOCK_THREAD_BLOCK;
@@ -60,6 +63,11 @@
#define WSASETINITIALIZED (Initialized = TRUE)
+/* ws2_32 internal Functions */
+void check_hostent(struct hostent **he);
+void populate_hostent(struct hostent *he, char* name, DNS_A_DATA addr);
+void free_hostent(struct hostent *he);
+void free_servent(struct servent* s);
#ifdef LE
_____
reactos http://cvs.reactos.com/cgi-bin/cvsweb/reactos /lib http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib /ws2_32 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32 /misc http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc
dllmain.c 1.18 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/dllmain.c?rev=1.18&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/dllmain.c.diff?r1=text&tr1=1.18&r2=text&tr2=1.19&f=h > 1.19 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/dllmain.c?rev=1.19&content-type=text/x-cvsweb-markup diff -u -r1.18 -r1.19
--- dllmain.c 17 Nov 2004 05:17:22 -0000 1.18
+++ dllmain.c 25 Nov 2004 23:32:54 -0000 1.19
@@ -663,6 +663,16 @@
return FALSE;
}
+void free_winsock_thread_block(PWINSOCK_THREAD_BLOCK p) {
+ if(p) {
+ if(p->Hostent) { free_hostent(p->Hostent); p->Hostent = 0; }
+ if(p->Getservbyname){}
+ if(p->Getservbyport) {}
+
+
+ }
+}
+ BOOL
STDCALL
DllMain(HANDLE hInstDll, @@ -708,6 +718,7 @@
return FALSE;
}
+ p->Hostent = NULL; p->LastErrorValue = NO_ERROR;
p->Getservbyname = NULL;
p->Getservbyport = NULL; _____
reactos http://cvs.reactos.com/cgi-bin/cvsweb/reactos /lib http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib /ws2_32 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32 /misc http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc
event.c 1.6 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/event.c?rev=1.6&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/event.c.diff?r1=text&tr1=1.6&r2=text&tr2=1.7&f=h > 1.7 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/event.c?rev=1.7&content-type=text/x-cvsweb-markup diff -u -r1.6 -r1.7
--- event.c 7 Aug 2003 04:03:24 -0000 1.6
+++ event.c 25 Nov 2004 23:32:54 -0000 1.7
@@ -157,6 +157,10 @@
INT Status;
INT Errno;
+ WS_DbgPrint(MID_TRACE,("Called (Socket %x, hEventObject %x, "
+ "lpNetworkEvents %x)\n",
+ s, hEventObject, lpNetworkEvents));
+ if (!lpNetworkEvents) {
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR; @@ -180,6 +184,8 @@
if (Status == SOCKET_ERROR)
WSASetLastError(Errno);
+ WS_DbgPrint(MID_TRACE,("Leaving %x\n", Status));
+ return Status;
}
_____
reactos http://cvs.reactos.com/cgi-bin/cvsweb/reactos /lib http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib /ws2_32 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32 /misc http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc
ns.c 1.9 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/ns.c?rev=1.9&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/ns.c.diff?r1=text&tr1=1.9&r2=text&tr2=1.10&f=h > 1.10 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/ns.c?rev=1.10&content-type=text/x-cvsweb-markup diff -u -r1.9 -r1.10
--- ns.c 15 Jul 2004 02:03:07 -0000 1.9
+++ ns.c 25 Nov 2004 23:32:54 -0000 1.10
@@ -1,989 +1,1216 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS WinSock 2 DLL
- * FILE: misc/ns.c
- * PURPOSE: Namespace APIs
- * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
- * REVISIONS:
- * CSH 01/09-2000 Created
- */
-#include <ctype.h>
-#include <ws2_32.h>
-
-#ifndef BUFSIZ
-#define BUFSIZ 1024
-#endif/*BUFSIZ*/
-
-/* Name resolution APIs */
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAAddressToStringA(
- IN LPSOCKADDR lpsaAddress,
- IN DWORD dwAddressLength,
- IN LPWSAPROTOCOL_INFOA lpProtocolInfo,
- OUT LPSTR lpszAddressString,
- IN OUT LPDWORD lpdwAddressStringLength)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAAddressToStringW(
- IN LPSOCKADDR lpsaAddress,
- IN DWORD dwAddressLength,
- IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
- OUT LPWSTR lpszAddressString,
- IN OUT LPDWORD lpdwAddressStringLength)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAEnumNameSpaceProvidersA(
- IN OUT LPDWORD lpdwBufferLength,
- OUT LPWSANAMESPACE_INFOA lpnspBuffer)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAEnumNameSpaceProvidersW(
- IN OUT LPDWORD lpdwBufferLength,
- OUT LPWSANAMESPACE_INFOW lpnspBuffer)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAGetServiceClassInfoA(
- IN LPGUID lpProviderId,
- IN LPGUID lpServiceClassId,
- IN OUT LPDWORD lpdwBufferLength,
- OUT LPWSASERVICECLASSINFOA lpServiceClassInfo)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAGetServiceClassInfoW(
- IN LPGUID lpProviderId,
- IN LPGUID lpServiceClassId,
- IN OUT LPDWORD lpdwBufferLength,
- OUT LPWSASERVICECLASSINFOW lpServiceClassInfo)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAGetServiceClassNameByClassIdA(
- IN LPGUID lpServiceClassId,
- OUT LPSTR lpszServiceClassName,
- IN OUT LPDWORD lpdwBufferLength)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAGetServiceClassNameByClassIdW(
- IN LPGUID lpServiceClassId,
- OUT LPWSTR lpszServiceClassName,
- IN OUT LPDWORD lpdwBufferLength)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAInstallServiceClassA(
- IN LPWSASERVICECLASSINFOA lpServiceClassInfo)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAInstallServiceClassW(
- IN LPWSASERVICECLASSINFOW lpServiceClassInfo)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSALookupServiceBeginA(
- IN LPWSAQUERYSETA lpqsRestrictions,
- IN DWORD dwControlFlags,
- OUT LPHANDLE lphLookup)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSALookupServiceBeginW(
- IN LPWSAQUERYSETW lpqsRestrictions,
- IN DWORD dwControlFlags,
- OUT LPHANDLE lphLookup)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSALookupServiceEnd(
- IN HANDLE hLookup)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSALookupServiceNextA(
- IN HANDLE hLookup,
- IN DWORD dwControlFlags,
- IN OUT LPDWORD lpdwBufferLength,
- OUT LPWSAQUERYSETA lpqsResults)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSALookupServiceNextW(
- IN HANDLE hLookup,
- IN DWORD dwControlFlags,
- IN OUT LPDWORD lpdwBufferLength,
- OUT LPWSAQUERYSETW lpqsResults)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSARemoveServiceClass(
- IN LPGUID lpServiceClassId)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSASetServiceA(
- IN LPWSAQUERYSETA lpqsRegInfo,
- IN WSAESETSERVICEOP essOperation,
- IN DWORD dwControlFlags)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSASetServiceW(
- IN LPWSAQUERYSETW lpqsRegInfo,
- IN WSAESETSERVICEOP essOperation,
- IN DWORD dwControlFlags)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAStringToAddressA(
- IN LPSTR AddressString,
- IN INT AddressFamily,
- IN LPWSAPROTOCOL_INFOA lpProtocolInfo,
- OUT LPSOCKADDR lpAddress,
- IN OUT LPINT lpAddressLength)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-WSAStringToAddressW(
- IN LPWSTR AddressString,
- IN INT AddressFamily,
- IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
- OUT LPSOCKADDR lpAddress,
- IN OUT LPINT lpAddressLength)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/* WinSock 1.1 compatible name resolution APIs */
-
-/*
- * @unimplemented
- */
-LPHOSTENT
-EXPORT
-gethostbyaddr(
- IN CONST CHAR FAR* addr,
- IN INT len,
- IN INT type)
-{
- UNIMPLEMENTED
-
- return (LPHOSTENT)NULL;
-}
-
-/*
- * @unimplemented
- */
-LPHOSTENT
-EXPORT
-gethostbyname(
- IN CONST CHAR FAR* name)
-{
- UNIMPLEMENTED
-
- return (LPHOSTENT)NULL;
-}
-
-
-/*
- * @unimplemented
- */
-INT
-EXPORT
-gethostname(
- OUT CHAR FAR* name,
- IN INT namelen)
-{
- UNIMPLEMENTED
-
- return 0;
-}
-
-
-/*
- * XXX arty -- Partial implementation pending a better one. This one will
- * do for normal purposes.
- *
- * Return the address of a static LPPROTOENT corresponding to the named
- * protocol. These structs aren't very interesting, so I'm not too ashamed
- * to have this function work on builtins for now.
- *
- * @unimplemented
- */
-LPPROTOENT
-EXPORT
-getprotobyname(
- IN CONST CHAR FAR* name)
-{
- static CHAR *udp_aliases = 0;
- static PROTOENT udp = { "udp", &udp_aliases, 17 };
- static CHAR *tcp_aliases = 0;
- static PROTOENT tcp = { "tcp", &tcp_aliases, 6 };
- if( !_stricmp( name, "udp" ) ) {
- return &udp;
- } else if( !_stricmp( name, "tcp" ) ) {
- return &tcp;
- }
-
- return 0;
-}
-
-/*
- * @unimplemented
- */
-LPPROTOENT
-EXPORT
-getprotobynumber(
- IN INT number)
-{
- UNIMPLEMENTED
-
- return (LPPROTOENT)NULL;
-}
-
-#define SKIPWS(ptr,act) \
-{while(*ptr && isspace(*ptr)) ptr++; if(!*ptr) act;}
-#define SKIPANDMARKSTR(ptr,act) \
-{while(*ptr && !isspace(*ptr)) ptr++; \
- if(!*ptr) {act;} else { *ptr = 0; ptr++; }}
-
-
-static BOOL DecodeServEntFromString( IN PCHAR ServiceString,
- OUT PCHAR *ServiceName,
- OUT PCHAR *PortNumberStr,
- OUT PCHAR *ProtocolStr,
- IN PCHAR *Aliases,
- IN DWORD MaxAlias ) {
- UINT NAliases = 0;
-
- WS_DbgPrint(MAX_TRACE, ("Parsing service ent [%s]\n", ServiceString));
-
- SKIPWS(ServiceString, return FALSE);
- *ServiceName = ServiceString;
- SKIPANDMARKSTR(ServiceString, return FALSE);
- SKIPWS(ServiceString, return FALSE);
- *PortNumberStr = ServiceString;
- SKIPANDMARKSTR(ServiceString, ;);
-
- while( *ServiceString && NAliases < MaxAlias - 1 ) {
- SKIPWS(ServiceString, break);
- if( *ServiceString ) {
- SKIPANDMARKSTR(ServiceString, ;);
- if( strlen(ServiceString) ) {
- WS_DbgPrint(MAX_TRACE, ("Alias: %s\n", ServiceString));
- *Aliases++ = ServiceString;
- NAliases++;
- }
- }
- }
- *Aliases = NULL;
-
- *ProtocolStr = strchr(*PortNumberStr,'/');
- if( !*ProtocolStr ) return FALSE;
- **ProtocolStr = 0; (*ProtocolStr)++;
-
- WS_DbgPrint(MAX_TRACE, ("Parsing done: %s %s %s %d\n",
- *ServiceName, *ProtocolStr, *PortNumberStr,
- NAliases));
-
- return TRUE;
-}
-
-#define ADJ_PTR(p,b1,b2) p = (p - b1) + b2
-
-/*
- * @implemented
- */
-LPSERVENT
-EXPORT
-getservbyname(
-
- IN CONST CHAR FAR* name,
- IN CONST CHAR FAR* proto)
-{
- 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( !name ) {
- 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 ) &&
- !strcmp( ServiceName, name ) &&
- (proto ? !strcmp( ProtocolStr, proto ) : TRUE) ) {
-
- WS_DbgPrint(MAX_TRACE,("Found the service entry.\n"));
- Found = TRUE;
- SizeNeeded = sizeof(WINSOCK_GETSERVBYNAME_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->Getservbyname || p->Getservbyname->Size < SizeNeeded ) {
- /* Free previous getservbyname buffer, allocate bigger */
- if( p->Getservbyname )
- HeapFree(GlobalHeap, 0, p->Getservbyname);
- p->Getservbyname = HeapAlloc(GlobalHeap, 0, SizeNeeded);
- if( !p->Getservbyname ) {
- WS_DbgPrint(MIN_TRACE,("Couldn't allocate %d bytes\n",
- SizeNeeded));
- WSASetLastError( WSATRY_AGAIN );
- return NULL;
- }
- p->Getservbyname->Size = SizeNeeded;
- }
-
- /* Copy the data */
- memmove( p->Getservbyname->Data,
- ThisLine,
- NextLine - ThisLine );
-
- ADJ_PTR(ServiceName,ThisLine,p->Getservbyname->Data);
- ADJ_PTR(ProtocolStr,ThisLine,p->Getservbyname->Data);
- WS_DbgPrint(MAX_TRACE,
- ("ServiceName: %s, Protocol: %s\n", ServiceName, ProtocolStr));
-
- for( i = 0; Aliases[i]; i++ ) {
- ADJ_PTR(Aliases[i],ThisLine,p->Getservbyname->Data);
- WS_DbgPrint(MAX_TRACE,("Aliase %d: %s\n", i, Aliases[i]));
- }
-
- memcpy(p->Getservbyname,Aliases,sizeof(Aliases));
-
- /* Create the struct proper */
- p->Getservbyname->ServerEntry.s_name = ServiceName;
- p->Getservbyname->ServerEntry.s_aliases = p->Getservbyname->Aliases;
- p->Getservbyname->ServerEntry.s_port = htons(atoi(PortNumberStr));
- p->Getservbyname->ServerEntry.s_proto = ProtocolStr;
-
- return &p->Getservbyname->ServerEntry;
-}
-
-
-/*
- * @implemented
- */
-LPSERVENT
-EXPORT
-getservbyport(
- IN INT port,
- IN CONST CHAR FAR* proto)
-{
- 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;
-
-}
-
-
-/*
- * @implemented
- */
-ULONG
-EXPORT
-inet_addr(
- IN CONST CHAR FAR* cp)
-/*
- * FUNCTION: Converts a string containing an IPv4 address to an unsigned long
- * ARGUMENTS:
- * cp = Pointer to string with address to convert
- * RETURNS:
- * Binary representation of IPv4 address, or INADDR_NONE
- */
-{
- UINT i;
- PCHAR p;
- ULONG u = 0;
-
- p = (PCHAR)cp;
-
- if (strlen(p) == 0)
- return INADDR_NONE;
-
- if (strcmp(p, " ") == 0)
- return 0;
-
- for (i = 0; i <= 3; i++) {
- u += (strtoul(p, &p, 0) << (i * 8));
-
- if (strlen(p) == 0)
- return u;
-
- if (p[0] != '.')
- return INADDR_NONE;
-
- p++;
- }
-
- return u;
-}
-
-
-/*
- * @implemented
- */
-CHAR FAR*
-EXPORT
-inet_ntoa(
- IN IN_ADDR in)
-{
- CHAR b[10];
- PCHAR p;
-
- p = ((PWINSOCK_THREAD_BLOCK)NtCurrentTeb()->WinSockData)->Intoa;
- _itoa(in.S_un.S_addr & 0xFF, b, 10);
- strcpy(p, b);
- _itoa((in.S_un.S_addr >> 8) & 0xFF, b, 10);
- strcat(p, ".");
- strcat(p, b);
- _itoa((in.S_un.S_addr >> 16) & 0xFF, b, 10);
- strcat(p, ".");
- strcat(p, b);
- _itoa((in.S_un.S_addr >> 24) & 0xFF, b, 10);
- strcat(p, ".");
- strcat(p, b);
- return (CHAR FAR*)p;
-}
-
-
-/*
- * @unimplemented
- */
-HANDLE
-EXPORT
-WSAAsyncGetHostByAddr(
- IN HWND hWnd,
- IN UINT wMsg,
- IN CONST CHAR FAR* addr,
- IN INT len,
- IN INT type,
- OUT CHAR FAR* buf,
- IN INT buflen)
-{
- UNIMPLEMENTED
-
- return (HANDLE)0;
-}
-
-
-/*
- * @unimplemented
- */
-HANDLE
-EXPORT
-WSAAsyncGetHostByName(
- IN HWND hWnd,
- IN UINT wMsg,
- IN CONST CHAR FAR* name,
- OUT CHAR FAR* buf,
- IN INT buflen)
-{
- UNIMPLEMENTED
-
- return (HANDLE)0;
-}
-
-
-/*
- * @unimplemented
- */
-HANDLE
-EXPORT
-WSAAsyncGetProtoByName(
- IN HWND hWnd,
- IN UINT wMsg,
- IN CONST CHAR FAR* name,
- OUT CHAR FAR* buf,
- IN INT buflen)
-{
- UNIMPLEMENTED
-
- return (HANDLE)0;
-}
-
-
-/*
- * @unimplemented
- */
-HANDLE
-EXPORT
-WSAAsyncGetProtoByNumber(
- IN HWND hWnd,
- IN UINT wMsg,
- IN INT number,
- OUT CHAR FAR* buf,
- IN INT buflen)
-{
- UNIMPLEMENTED
-
- return (HANDLE)0;
-}
-
-
-/*
- * @unimplemented
- */
-HANDLE
-EXPORT
-WSAAsyncGetServByName(
- IN HWND hWnd,
- IN UINT wMsg,
- IN CONST CHAR FAR* name,
- IN CONST CHAR FAR* proto,
- OUT CHAR FAR* buf,
- IN INT buflen)
-{
- UNIMPLEMENTED
-
- return (HANDLE)0;
-}
-
-
-/*
- * @unimplemented
- */
-HANDLE
-EXPORT
-WSAAsyncGetServByPort(
- IN HWND hWnd,
- IN UINT wMsg,
- IN INT port,
- IN CONST CHAR FAR* proto,
- OUT CHAR FAR* buf,
- IN INT buflen)
-{
- UNIMPLEMENTED
-
- return (HANDLE)0;
-}
-
-/* EOF */ +/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS WinSock 2 DLL
+ * FILE: misc/ns.c
+ * PURPOSE: Namespace APIs
+ * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
+ * REVISIONS:
[truncated at 1000 lines; 1209 more skipped] _____
reactos http://cvs.reactos.com/cgi-bin/cvsweb/reactos /lib http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib /ws2_32 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32 /misc http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc
stubs.c 1.14 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/stubs.c?rev=1.14&content-type=text/x-cvsweb-markup - http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/stubs.c.diff?r1=text&tr1=1.14&r2=text&tr2=1.15&f=h > 1.15 http://cvs.reactos.com/cgi-bin/cvsweb/reactos/lib/ws2_32/misc/stubs.c?rev=1.15&content-type=text/x-cvsweb-markup diff -u -r1.14 -r1.15
--- stubs.c 17 Nov 2004 05:17:22 -0000 1.14
+++ stubs.c 25 Nov 2004 23:32:54 -0000 1.15
@@ -147,7 +147,7 @@
* @implemented
*/
INT -EXPORT +EXPORT __stdcall setsockopt(
IN SOCKET s,
IN INT level, CVSspam http://www.badgers-in-foil.co.uk/projects/cvsspam/ 0.2.8
On Fri, 26 Nov 2004 09:13:09 +0100 "Casper Hornstrup" chorns@users.sourceforge.net wrote:
This is the wrong way to do it. A Namespace Service Provider should be written for DNS instead. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/win....
DNS is a TCP/IP thing. Other protocols have their own namespace system so ws2_32 should remain generic and not depend on dnsapi.
Casper
I don't doubt that the approach could be improved, but nobody else stepped up to code this. My basic opinion is that functionality is better than vapor, especially when it helps us exercise other parts of the system.
I don't doubt that the approach could be improved, but nobody else stepped up to code this. My basic opinion is that functionality is better than vapor, especially when it helps us exercise other parts of the system.
In the past we've tried hard to implement ReactOS the way Windows is documented to be and I don't see why we should change that now. The WinSock stack is layered and can handle multiple protocols so I don't see why you would want to put such TCP/IP specifics into ws2_32.dll which is (or used to be) just a dumb dispatcher to WinSock Service Providers.
Casper
Hi Casper,
--- Casper Hornstrup chorns@users.sourceforge.net wrote:
I don't see why you would want to put such TCP/IP specifics into ws2_32.dll which is (or used to be) just a dumb dispatcher to WinSock Service Providers.
Its not a matter of wanting to do it that way ot not. Art just said it was not correct as in the Microsoft way of doing it. Its just no one wrote a correct implementation and most of us want to tcpip networking mostly working ASAP. The way I see it, its better to slightly break the design short term if it means more developers coming in to help.
Thanks Steven
__________________________________ Do you Yahoo!? The all-new My Yahoo! - What will yours do? http://my.yahoo.com
On Fri, 26 Nov 2004 12:36:23 +0100 "Casper Hornstrup" chorns@users.sourceforge.net wrote:
I don't doubt that the approach could be improved, but nobody else stepped up to code this. My basic opinion is that functionality is better than vapor, especially when it helps us exercise other parts of the system.
In the past we've tried hard to implement ReactOS the way Windows is documented to be and I don't see why we should change that now. The WinSock stack is layered and can handle multiple protocols so I don't see why you would want to put such TCP/IP specifics into ws2_32.dll which is (or used to be) just a dumb dispatcher to WinSock Service Providers.
We're in agreement that it should be moved to use a layered provider, but I think we disagree about how important it is at the moment. In any case, I'm willing to put up some money to get this done as it's difficult to get volunteers. I'll get to it eventually if nobody else does but it definately won't be this year.
Well if anybody is willing to take me up on the bounty and implement it earlier, I'm offering $50.
Art