Work on winsock stack and indentation corrections.

svn path=/trunk/; revision=1849
This commit is contained in:
Casper Hornstrup 2001-05-01 22:44:07 +00:00
parent 72c2af4ca7
commit 1debf1a12d
26 changed files with 976 additions and 703 deletions

View file

@ -12,12 +12,14 @@
#ifdef DBG
/* See debug.h for debug/trace constants */
DWORD DebugTraceLevel = MAX_TRACE;
DWORD DebugTraceLevel = MIN_TRACE;
#endif /* DBG */
NTSTATUS AfdFileSystemControl(
NTSTATUS
STDCALL
AfdFileSystemControl(
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
@ -29,7 +31,9 @@ NTSTATUS AfdFileSystemControl(
}
NTSTATUS AfdDispatch(
NTSTATUS
STDCALL
AfdDispatch(
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
/*
@ -46,8 +50,8 @@ NTSTATUS AfdDispatch(
IrpSp = IoGetCurrentIrpStackLocation(Irp);
AFD_DbgPrint(MAX_TRACE, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X).\n",
DeviceObject, Irp));
AFD_DbgPrint(MAX_TRACE, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X), IrpSp->FileObject (0x%X).\n",
DeviceObject, Irp, IrpSp->FileObject));
Irp->IoStatus.Information = 0;
@ -99,9 +103,7 @@ VOID AfdUnload(
NTSTATUS
#ifndef _MSC_VER
STDCALL
#endif
DriverEntry(
PDRIVER_OBJECT DriverObject,
PUNICODE_STRING RegistryPath)
@ -130,7 +132,7 @@ DriverEntry(
FALSE,
&DeviceObject);
if (!NT_SUCCESS(Status)) {
AFD_DbgPrint(MIN_TRACE, ("Could not create device (0x%X).\n", Status));
AFD_DbgPrint(MIN_TRACE, ("Could not create device (0x%X).\n", Status));
return Status;
}

View file

@ -121,6 +121,10 @@ NTSTATUS AfdDispSendTo(
PFILE_REQUEST_SENDTO Request;
PFILE_REPLY_SENDTO Reply;
PAFDFCB FCB;
PVOID SystemVirtualAddress;
ULONG BufferSize;
ULONG BytesCopied;
PMDL Mdl;
InputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
@ -128,14 +132,114 @@ NTSTATUS AfdDispSendTo(
/* Validate parameters */
if ((InputBufferLength >= sizeof(FILE_REQUEST_SENDTO)) &&
(OutputBufferLength >= sizeof(FILE_REPLY_SENDTO))) {
FCB = IrpSp->FileObject->FsContext;
AFD_DbgPrint(MAX_TRACE, ("FileObject at (0x%X).\n", IrpSp->FileObject));
AFD_DbgPrint(MAX_TRACE, ("FCB at (0x%X).\n", IrpSp->FileObject->FsContext));
AFD_DbgPrint(MAX_TRACE, ("CCB at (0x%X).\n", IrpSp->FileObject->FsContext2));
FCB = IrpSp->FileObject->FsContext;
Request = (PFILE_REQUEST_SENDTO)Irp->AssociatedIrp.SystemBuffer;
Reply = (PFILE_REPLY_SENDTO)Irp->AssociatedIrp.SystemBuffer;
BufferSize = WSABufferSize(Request->Buffers, Request->BufferCount);
Status = TdiSend(FCB->TdiAddressObject, Request);
if (BufferSize != 0) {
AFD_DbgPrint(MAX_TRACE, ("Allocating %d bytes for send buffer.\n", BufferSize));
SystemVirtualAddress = ExAllocatePool(NonPagedPool, BufferSize);
if (!SystemVirtualAddress) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
return STATUS_INSUFFICIENT_RESOURCES;
}
Reply->NumberOfBytesSent = Request->ToLen;
Status = MergeWSABuffers(
Request->Buffers,
Request->BufferCount,
SystemVirtualAddress,
BufferSize,
&BytesCopied);
if (!NT_SUCCESS(Status)) {
AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
return Status;
}
} else {
SystemVirtualAddress = NULL;
BytesCopied = 0;
}
AFD_DbgPrint(MAX_TRACE, ("KeGetCurrentIrql() 1 (%d).\n", KeGetCurrentIrql()));
Mdl = IoAllocateMdl(
SystemVirtualAddress, /* Virtual address of buffer */
BufferSize, /* Length of buffer */
FALSE, /* Not secondary */
FALSE, /* Don't charge quota */
NULL); /* Don't use IRP */
if (!Mdl) {
AFD_DbgPrint(MIN_TRACE, ("IoAllocateMdl() failed.\n"));
ExFreePool(SystemVirtualAddress);
return STATUS_INSUFFICIENT_RESOURCES;
}
AFD_DbgPrint(MAX_TRACE, ("KeGetCurrentIrql() 2 (%d).\n", KeGetCurrentIrql()));
AFD_DbgPrint(MIN_TRACE, ("NDIS data buffer MdlFlags 1 is (0x%X).\n", Mdl->MdlFlags));
MmBuildMdlForNonPagedPool(Mdl);
AFD_DbgPrint(MAX_TRACE, ("KeGetCurrentIrql() 3 (%d).\n", KeGetCurrentIrql()));
AFD_DbgPrint(MAX_TRACE, ("System virtual address is (0x%X).\n", SystemVirtualAddress));
AFD_DbgPrint(MAX_TRACE, ("MDL for data buffer is at (0x%X).\n", Mdl));
AFD_DbgPrint(MAX_TRACE, ("AFD.SYS: NDIS data buffer is at (0x%X).\n", Mdl));
AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer MdlFlags is (0x%X).\n", Mdl->MdlFlags));
AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer Next is at (0x%X).\n", Mdl->Next));
AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer Size is (0x%X).\n", Mdl->Size));
AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer MappedSystemVa is (0x%X).\n", Mdl->MappedSystemVa));
AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer StartVa is (0x%X).\n", Mdl->StartVa));
AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer ByteCount is (0x%X).\n", Mdl->ByteCount));
AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer ByteOffset is (0x%X).\n", Mdl->ByteOffset));
#if 0
#ifdef _MSC_VER
try {
#endif
MmProbeAndLockPages(Mdl, KernelMode, IoModifyAccess);
#ifdef _MSC_VER
} except(EXCEPTION_EXECUTE_HANDLER) {
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
IoFreeMdl(Mdl);
if (BufferSize != 0) {
ExFreePool(SystemVirtualAddress);
}
return STATUS_UNSUCCESSFUL;
}
#endif
#endif
DisplayBuffer(SystemVirtualAddress, BufferSize);
Status = STATUS_SUCCESS;
/* Status = TdiSendDatagram(FCB->TdiAddressObject,
&Request->To,
Mdl,
BufferSize);*/
/* FIXME: Assumes synchronous operation */
#if 0
MmUnlockPages(Mdl);
#endif
IoFreeMdl(Mdl);
AFD_DbgPrint(MAX_TRACE, ("KeGetCurrentIrql() 4 (%d).\n", KeGetCurrentIrql()));
if (BufferSize != 0) {
ExFreePool(SystemVirtualAddress);
}
AFD_DbgPrint(MAX_TRACE, ("KeGetCurrentIrql() 5 (%d).\n", KeGetCurrentIrql()));
Reply->NumberOfBytesSent = BufferSize;
Reply->Status = Status;
} else
Status = STATUS_INVALID_PARAMETER;

View file

@ -41,6 +41,8 @@ PAFDFCB AfdInitializeFCB(
if (FileObject)
FileObject->FsContext = (PVOID)&NewFCB->NTRequiredFCB;
AFD_DbgPrint(MAX_TRACE, ("FCB created for file object (0x%X) at (0x%X).\n", FileObject, NewFCB));
return NewFCB;
}
@ -66,11 +68,15 @@ PAFDCCB AfdInitializeCCB(
InsertTailList(&FCB->CCBListHead, &NewCCB->ListEntry);
AFD_DbgPrint(MAX_TRACE, ("CCB created for file object (0x%X) at (0x%X).\n", FileObject, NewCCB));
return NewCCB;
}
NTSTATUS AfdCreate(
NTSTATUS
STDCALL
AfdCreate(
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
@ -87,6 +93,8 @@ NTSTATUS AfdCreate(
AFD_DbgPrint(MIN_TRACE, ("Called.\n"));
assert(DeviceObject);
DeviceExt = DeviceObject->DeviceExtension;
EaInfo = Irp->AssociatedIrp.SystemBuffer;
@ -114,17 +122,45 @@ NTSTATUS AfdCreate(
/* FIXME: File/socket could already be open, do a search for it */
FCB = AfdInitializeFCB(DeviceExt, FileObject);
CCB = AfdInitializeCCB(FCB, FileObject);
if (CCB && FCB) {
FCB->AddressFamily = SocketInfo->AddressFamily;
FCB->SocketType = SocketInfo->SocketType;
FCB->Protocol = SocketInfo->Protocol;
FCB->HelperContext = SocketInfo->HelperContext;
FCB->NotificationEvents = SocketInfo->NotificationEvents;
RtlCopyUnicodeString(&FCB->TdiDeviceName, &SocketInfo->TdiDeviceName);
} else {
if (RtlCreateUnicodeString(&FCB->TdiDeviceName, SocketInfo->TdiDeviceName.Buffer)) {
/* RtlInitUnicodeString(&FCB->TdiDeviceName, NULL);
FCB->TdiDeviceName.MaximumLength = SocketInfo->TdiDeviceName.Length + sizeof(WCHAR);
FCB->TdiDeviceName.Buffer = ExAllocatePool(NonPagedPool, FCB->TdiDeviceName.MaximumLength);*/
RtlCopyUnicodeString(&FCB->TdiDeviceName, &SocketInfo->TdiDeviceName);
AFD_DbgPrint(MAX_TRACE, ("TDI device name is (%wZ).\n", &FCB->TdiDeviceName));
/* Open address file now for raw sockets */
if (FCB->SocketType == SOCK_RAW) {
AFD_DbgPrint(MAX_TRACE, ("Opening raw socket.\n"));
Status = TdiOpenAddressFile(
&FCB->TdiDeviceName,
&SocketInfo->Name,
&FCB->TdiAddressObjectHandle,
&FCB->TdiAddressObject);
AFD_DbgPrint(MAX_TRACE, ("Status of open operation (0x%X).\n", Status));
if (NT_SUCCESS(Status))
FCB->State = SOCKET_STATE_BOUND;
} else
Status = STATUS_SUCCESS;
} else
Status = STATUS_INSUFFICIENT_RESOURCES;
} else
Status = STATUS_INSUFFICIENT_RESOURCES;
}
if (!NT_SUCCESS(Status)) {
/* FIXME: Cleanup */
@ -141,7 +177,9 @@ NTSTATUS AfdCreate(
}
NTSTATUS AfdClose(
NTSTATUS
STDCALL
AfdClose(
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
@ -151,11 +189,14 @@ NTSTATUS AfdClose(
PAFDFCB FCB;
PAFDCCB CCB;
AFD_DbgPrint(MIN_TRACE, ("Called.\n"));
assert(DeviceObject);
assert(FileObject);
FCB = FileObject->FsContext;
CCB = FileObject->FsContext2;
AFD_DbgPrint(MIN_TRACE, ("Called.\n"));
switch (IrpSp->MajorFunction) {
/* Close a file object */
case IRP_MJ_CLOSE:

View file

@ -25,7 +25,9 @@ NTSTATUS AfdReadFile(
}
NTSTATUS AfdRead(
NTSTATUS
STDCALL
AfdRead(
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
@ -58,7 +60,9 @@ NTSTATUS AfdRead(
}
NTSTATUS AfdWrite(
NTSTATUS
STDCALL
AfdWrite(
PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{

View file

@ -0,0 +1,78 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Ancillary Function Driver
* FILE: afd/routines.c
* PURPOSE: Support routines
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
* REVISIONS:
* CSH 01/02-2001 Created
*/
#include <afd.h>
ULONG WSABufferSize(
LPWSABUF Buffers,
DWORD BufferCount)
{
ULONG i;
LPWSABUF p;
ULONG Count = 0;
p = Buffers;
for (i = 0; i < BufferCount; i++) {
Count += p->len;
p++;
}
AFD_DbgPrint(MAX_TRACE, ("Buffer is %d bytes.\n", Count));
return Count;
}
NTSTATUS MergeWSABuffers(
LPWSABUF Buffers,
DWORD BufferCount,
PVOID Destination,
ULONG MaxLength,
PULONG BytesCopied)
{
NTSTATUS Status;
ULONG Length;
LPWSABUF p;
ULONG i;
*BytesCopied = 0;
if (BufferCount == 0)
return STATUS_SUCCESS;
p = Buffers;
AFD_DbgPrint(MAX_TRACE, ("Destination is 0x%X\n", Destination));
AFD_DbgPrint(MAX_TRACE, ("p is 0x%X\n", p));
for (i = 0; i < BufferCount; i++) {
Length = p->len;
if (Length > MaxLength)
/* Don't copy out of bounds */
Length = MaxLength;
RtlCopyMemory(Destination, p->buf, Length);
Destination += Length;
AFD_DbgPrint(MAX_TRACE, ("Destination is 0x%X\n", Destination));
p++;
AFD_DbgPrint(MAX_TRACE, ("p is 0x%X\n", p));
*BytesCopied += Length;
MaxLength -= Length;
if (MaxLength == 0)
/* Destination buffer is full */
break;
}
return STATUS_SUCCESS;
}
/* EOF */

View file

@ -9,6 +9,35 @@
*/
#include <afd.h>
#ifdef DBG
VOID DisplayBuffer(
PVOID Buffer,
ULONG Size)
{
ULONG i;
PCHAR p;
if ((DebugTraceLevel & MAX_TRACE) == 0)
return;
if (!Buffer) {
AFD_DbgPrint(MIN_TRACE, ("Cannot display null buffer.\n"));
return;
}
AFD_DbgPrint(MIN_TRACE, ("Displaying buffer at (0x%X) Size (%d).\n", Buffer, Size));
p = (PCHAR)Buffer;
for (i = 0; i < Size; i++) {
if (i % 16 == 0)
DbgPrint("\n");
DbgPrint("%02X ", (p[i]) & 0xFF);
}
DbgPrint("\n");
}
#endif /* DBG */
inline DWORD TdiAddressSizeFromName(
LPSOCKADDR Name)
/*
@ -120,6 +149,8 @@ NTSTATUS TdiCall(
Events[0] = StopEvent;
Events[1] = &Event;
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
KeInitializeEvent(&Event, NotificationEvent, FALSE);
Irp->UserEvent = &Event;
Irp->UserIosb = IoStatusBlock;
@ -179,6 +210,8 @@ NTSTATUS TdiOpenDevice(
IO_STATUS_BLOCK Iosb;
NTSTATUS Status;
AFD_DbgPrint(MAX_TRACE, ("Called. DeviceName (%wZ)\n", DeviceName));
InitializeObjectAttributes(&Attr, /* Attribute buffer */
DeviceName, /* Device name */
OBJ_CASE_INSENSITIVE, /* Attributes */
@ -210,7 +243,6 @@ NTSTATUS TdiOpenDevice(
} else {
AFD_DbgPrint(MIN_TRACE, ("ZwCreateFile() failed with status (0x%X)\n", Status));
}
return Status;
}
@ -219,6 +251,9 @@ NTSTATUS TdiCloseDevice(
HANDLE Handle,
PFILE_OBJECT FileObject)
{
AFD_DbgPrint(MAX_TRACE, ("Called. Handle (0x%X) FileObject (0x%X)\n",
Handle, FileObject));
if (FileObject)
ObDereferenceObject(FileObject);
@ -250,6 +285,9 @@ NTSTATUS TdiOpenAddressFileIPv4(
NTSTATUS Status;
ULONG EaLength;
AFD_DbgPrint(MAX_TRACE, ("Called. DeviceName (%wZ) Name (0x%X)\n",
DeviceName, Name));
EaLength = sizeof(FILE_FULL_EA_INFORMATION) +
TDI_TRANSPORT_ADDRESS_LENGTH +
sizeof(TA_ADDRESS_IP);
@ -267,7 +305,6 @@ NTSTATUS TdiOpenAddressFileIPv4(
EaInfo->EaValueLength = sizeof(TA_ADDRESS_IP);
Address = (PTA_ADDRESS_IP)(EaInfo->EaName + TDI_TRANSPORT_ADDRESS_LENGTH);
TdiBuildAddressIPv4(Address, Name);
Status = TdiOpenDevice(DeviceName,
EaLength,
EaInfo,
@ -278,6 +315,36 @@ NTSTATUS TdiOpenAddressFileIPv4(
}
NTSTATUS TdiOpenAddressFile(
PUNICODE_STRING DeviceName,
LPSOCKADDR Name,
PHANDLE AddressHandle,
PFILE_OBJECT *AddressObject)
/*
* FUNCTION: Opens an address file object
* ARGUMENTS:
* DeviceName = Pointer to counted string with name of device
* Name = Pointer to socket name
* AddressHandle = Address of buffer to place address file handle
* AddressObject = Address of buffer to place address file object
* RETURNS:
* Status of operation
*/
{
NTSTATUS Status;
switch (Name->sa_family) {
case AF_INET:
Status = TdiOpenAddressFileIPv4(DeviceName, Name, AddressHandle, AddressObject);
break;
default:
Status = STATUS_INVALID_PARAMETER;
}
return Status;
}
NTSTATUS TdiSetEventHandler(
PFILE_OBJECT FileObject,
LONG EventType,
@ -301,6 +368,8 @@ NTSTATUS TdiSetEventHandler(
NTSTATUS Status;
PIRP Irp;
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
DeviceObject = IoGetRelatedDeviceObject(FileObject);
Irp = TdiBuildInternalDeviceControlIrp(TDI_SET_EVENT_HANDLER, /* Sub function */
@ -555,34 +624,35 @@ NTSTATUS TdiQueryAddress(
NTSTATUS TdiSend(
PFILE_OBJECT TransportObject,
PFILE_REQUEST_SENDTO Request)
PVOID Buffer,
ULONG BufferSize)
/*
* FUNCTION: Sends a block of data
* ARGUMENTS:
* TransportObject = Pointer to transport object
* Request = Pointer to request
* Buffer = Pointer to buffer with data to send
* BufferSize = Length of Buffer
* RETURNS:
* Status of operation
*/
{
#if 0
PTDI_CONNECTION_INFORMATION ConnectInfo;
PDEVICE_OBJECT DeviceObject;
IO_STATUS_BLOCK Iosb;
DWORD TdiAddressSize;
ULONG BufferSize;
PVOID BaseAddress;
NTSTATUS Status;
PIRP Irp;
PMDL Mdl;
/* FIXME: Connectionless only */
DeviceObject = IoGetRelatedDeviceObject(TransportObject);
if (!DeviceObject) {
AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
return STATUS_INVALID_PARAMETER;
}
TdiAddressSize = TdiAddressSizeFromName(&Request->To);
TdiAddressSize = TdiAddressSizeFromName(Address);
ConnectInfo = (PTDI_CONNECTION_INFORMATION)
ExAllocatePool(NonPagedPool,
@ -599,10 +669,10 @@ NTSTATUS TdiSend(
TdiAddressSize);
ConnectInfo->RemoteAddressLength = TdiAddressSize;
ConnectInfo->RemoteAddress = (PVOID)
ConnectInfo->RemoteAddress = (PVOID)
(ConnectInfo + sizeof(TDI_CONNECTION_INFORMATION));
TdiBuildAddress(ConnectInfo->RemoteAddress, &Request->To);
TdiBuildAddress(ConnectInfo->RemoteAddress, Address);
Irp = TdiBuildInternalDeviceControlIrp(TDI_SEND_DATAGRAM, /* Sub function */
DeviceObject, /* Device object */
@ -615,6 +685,9 @@ NTSTATUS TdiSend(
return STATUS_INSUFFICIENT_RESOURCES;
}
DisplayBuffer(Request->Buffers->buf, Request->Buffers->len);
/* FIXME: There may be more than one buffer */
BufferSize = Request->Buffers->len;
Mdl = IoAllocateMdl(
@ -644,6 +717,12 @@ NTSTATUS TdiSend(
}
#endif
CP
BaseAddress = MmMapLockedPages(Mdl, KernelMode);
AFD_DbgPrint(MAX_TRACE, ("Mapped user mode buffer at 0x%X.\n", BaseAddress));
CP
TdiBuildSendDatagram(Irp, /* I/O Request Packet */
DeviceObject, /* Device object */
TransportObject, /* File object */
@ -654,25 +733,33 @@ NTSTATUS TdiSend(
ConnectInfo); /* Connection information */
Status = TdiCall(Irp, DeviceObject, &Iosb, FALSE, NULL);
CP
MmUnmapLockedPages(BaseAddress, Mdl);
CP
MmUnlockPages(Mdl);
CP
IoFreeMdl(Mdl);
CP
ExFreePool(ConnectInfo);
return Status;
#endif
return STATUS_SUCCESS;
}
NTSTATUS TdiSendDatagram(
PFILE_OBJECT TransportObject,
LPSOCKADDR Address,
PVOID Buffer,
PMDL Mdl,
ULONG BufferSize)
/*
* FUNCTION: Sends a datagram
* ARGUMENTS:
* TransportObject = Pointer to transport object
* Address = Remote address
* Buffer = Pointer to buffer with data to send
* BufferSize = Length of Buffer
* Address = Remote address to send data to
* Mdl = MDL of buffer to send
* BufferSize = Length of buffer
* RETURNS:
* Status of operation
*/
@ -683,26 +770,33 @@ NTSTATUS TdiSendDatagram(
DWORD TdiAddressSize;
NTSTATUS Status;
PIRP Irp;
PMDL Mdl;
CP
DeviceObject = IoGetRelatedDeviceObject(TransportObject);
if (!DeviceObject) {
AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
return STATUS_INVALID_PARAMETER;
}
CP
TdiAddressSize = TdiAddressSizeFromName(Address);
ConnectInfo = (PTDI_CONNECTION_INFORMATION)
AFD_DbgPrint(MIN_TRACE, ("TdiAddressSize %d.\n", TdiAddressSize));
CP
ConnectInfo = (PTDI_CONNECTION_INFORMATION)
ExAllocatePool(NonPagedPool,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
AFD_DbgPrint(MIN_TRACE, ("ConnectInfo 0x%X.\n", ConnectInfo));
CP
if (!ConnectInfo) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
return STATUS_INSUFFICIENT_RESOURCES;
}
CP
RtlZeroMemory(ConnectInfo,
sizeof(TDI_CONNECTION_INFORMATION) +
TdiAddressSize);
@ -710,20 +804,22 @@ NTSTATUS TdiSendDatagram(
ConnectInfo->RemoteAddressLength = TdiAddressSize;
ConnectInfo->RemoteAddress = (PVOID)
(ConnectInfo + sizeof(TDI_CONNECTION_INFORMATION));
CP
TdiBuildAddress(ConnectInfo->RemoteAddress, Address);
CP
Irp = TdiBuildInternalDeviceControlIrp(TDI_SEND_DATAGRAM, /* Sub function */
DeviceObject, /* Device object */
TransportObject, /* File object */
NULL, /* Event */
NULL); /* Return buffer */
CP
if (!Irp) {
AFD_DbgPrint(MIN_TRACE, ("TdiBuildInternalDeviceControlIrp() failed.\n"));
ExFreePool(ConnectInfo);
return STATUS_INSUFFICIENT_RESOURCES;
}
#if 0
Mdl = IoAllocateMdl(Buffer, /* Virtual address of buffer */
BufferSize, /* Length of buffer */
FALSE, /* Not secondary */
@ -735,7 +831,6 @@ NTSTATUS TdiSendDatagram(
ExFreePool(ConnectInfo);
return STATUS_INSUFFICIENT_RESOURCES;
}
#ifdef _MSC_VER
try {
#endif
@ -743,12 +838,13 @@ NTSTATUS TdiSendDatagram(
#ifdef _MSC_VER
} except(EXCEPTION_EXECUTE_HANDLER) {
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
IoFreeMdl(Mdl);
IoFreeIrp(Irp);
ExFreePool(ConnectInfo);
return STATUS_UNSUCCESSFUL;
}
#endif
#endif
CP
TdiBuildSendDatagram(Irp, /* I/O Request Packet */
DeviceObject, /* Device object */
@ -758,11 +854,17 @@ NTSTATUS TdiSendDatagram(
Mdl, /* Descriptor for data buffer */
BufferSize, /* Size of data to send */
ConnectInfo); /* Connection information */
CP
Status = TdiCall(Irp, DeviceObject, &Iosb, FALSE, NULL);
CP
#if 0
MmUnlockPages(Mdl);
CP
IoFreeMdl(Mdl);
#endif
CP
ExFreePool(ConnectInfo);
CP
return Status;
}
@ -893,8 +995,11 @@ NTSTATUS TdiReceiveDatagram(
*BufferSize = Iosb.Information;
TdiBuildName(Address, ReturnInfo->RemoteAddress);
}
CP
MmUnlockPages(Mdl);
CP
IoFreeMdl(Mdl);
CP
ExFreePool(ReceiveInfo);
return Status;

View file

@ -76,6 +76,7 @@ typedef struct _AFDFCB {
DWORD NotificationEvents;
UNICODE_STRING TdiDeviceName;
DWORD State;
PVOID SendBuffer;
} AFDFCB, *PAFDFCB;
/* Socket states */
@ -210,15 +211,11 @@ NTSTATUS AfdDeregisterEventHandlers(
/* Prototypes from opnclose.c */
NTSTATUS AfdCreate(
NTSTATUS STDCALL AfdCreate(
PDEVICE_OBJECT DeviceObject,
PIRP Irp);
NTSTATUS AfdCreateNamedPipe(
PDEVICE_OBJECT DeviceObject,
PIRP Irp);
NTSTATUS AfdClose(
NTSTATUS STDCALL AfdClose(
PDEVICE_OBJECT DeviceObject,
PIRP Irp);
@ -237,14 +234,27 @@ NTSTATUS AfdEventReceiveDatagramHandler(
IN PVOID Tsdu,
OUT PIRP * IoRequestPacket);
NTSTATUS AfdRead(
NTSTATUS STDCALL AfdRead(
PDEVICE_OBJECT DeviceObject,
PIRP Irp);
NTSTATUS AfdWrite(
NTSTATUS STDCALL AfdWrite(
PDEVICE_OBJECT DeviceObject,
PIRP Irp);
/* Prototypes from routines.c */
ULONG WSABufferSize(
LPWSABUF Buffers,
DWORD BufferCount);
NTSTATUS MergeWSABuffers(
LPWSABUF Buffers,
DWORD BufferCount,
PVOID Destination,
ULONG MaxLength,
PULONG BytesCopied);
/* Prototypes from tdi.c */
NTSTATUS TdiCloseDevice(
@ -257,6 +267,12 @@ NTSTATUS TdiOpenAddressFileIPv4(
PHANDLE AddressHandle,
PFILE_OBJECT *AddressObject);
NTSTATUS TdiOpenAddressFile(
PUNICODE_STRING DeviceName,
LPSOCKADDR Name,
PHANDLE AddressHandle,
PFILE_OBJECT *AddressObject);
NTSTATUS TdiSetEventHandler(
PFILE_OBJECT FileObject,
LONG EventType,
@ -288,12 +304,13 @@ NTSTATUS TdiQueryAddress(
NTSTATUS TdiSend(
PFILE_OBJECT TransportObject,
PFILE_REQUEST_SENDTO Request);
PVOID Buffer,
ULONG BufferSize);
NTSTATUS TdiSendDatagram(
PFILE_OBJECT TransportObject,
LPSOCKADDR Address,
PVOID Buffer,
PMDL Mdl,
ULONG BufferSize);
#endif /*__AFD_H */

View file

@ -15,8 +15,8 @@
#define MID_TRACE 0x00000002
#define MAX_TRACE 0x00000003
#define DEBUG_IRP 0x00000100
#define DEBUG_CHECK 0x00000100
#define DEBUG_IRP 0x00000200
#define DEBUG_ULTRA 0xFFFFFFFF
#ifdef DBG
@ -85,7 +85,9 @@ extern DWORD DebugTraceLevel;
#define CHECKPOINT \
do { AFD_DbgPrint(MIN_TRACE, ("%s:%d\n", __FILE__, __LINE__)); } while(0);
AFD_DbgPrint(DEBUG_CHECK, ("\n"));
#define CP CHECKPOINT
#endif /* __DEBUG_H */

View file

@ -4,10 +4,11 @@ PATH_TO_TOP = ../../..
TARGETNAME=afd
CFLAGS = -I./include
CFLAGS = -I./include -DDBG
RESOURCE_OBJECT = $(TARGETNAME).coff
AFD_OBJECTS = afd/afd.o afd/dispatch.o afd/event.o afd/opnclose.o afd/rdwr.o afd/tdi.o
AFD_OBJECTS = afd/afd.o afd/dispatch.o afd/event.o afd/opnclose.o afd/rdwr.o \
afd/routines.o afd/tdi.o
all: $(TARGETNAME).sys
@ -17,10 +18,10 @@ OBJECTS = $(AFD_OBJECTS) $(RESOURCE_OBJECT) ../../../ntoskrnl/ntoskrnl.a
ifeq ($(DOSCLI),yes)
CLEAN_FILES = *.o afd\*.o $(TARGETNAME).coff $(TARGETNAME).o \
CLEAN_FILES = afd\*.o $(TARGETNAME).coff \
junk.tmp base.tmp temp.exp $(TARGETNAME).sys $(TARGETNAME).sym
else
CLEAN_FILES = *.o afd/*.o $(TARGETNAME).coff $(TARGETNAME).o \
CLEAN_FILES = afd/*.o $(TARGETNAME).coff $ \
junk.tmp base.tmp temp.exp $(TARGETNAME).sys $(TARGETNAME).sym
endif

View file

@ -4,7 +4,7 @@ PATH_TO_TOP = ../../..
TARGETNAME=ndis
CFLAGS = -I./include -DNDIS_WRAPPER -DBINARY_COMPATIBLE=1
CFLAGS = -I./include -DNDIS_WRAPPER -DBINARY_COMPATIBLE=1 -DDBG
RESOURCE_OBJECT = $(TARGETNAME).coff
NDIS_OBJECTS = ndis/main.o ndis/40gone.o ndis/50gone.o ndis/buffer.o ndis/cl.o \

View file

@ -88,6 +88,8 @@ extern DWORD DebugTraceLevel;
#define CHECKPOINT \
do { NDIS_DbgPrint(MIN_TRACE, ("(%s:%d)\n", __FILE__, __LINE__)); } while(0);
#define CP CHECKPOINT
#endif /* __DEBUG_H */
/* EOF */

View file

@ -35,14 +35,10 @@ VOID HandleDeferredProcessing(
Adapter->MiniportBusy = TRUE;
KeReleaseSpinLockFromDpcLevel(&Adapter->NdisMiniportBlock.Lock);
NDIS_DbgPrint(MAX_TRACE, ("Before HandleInterruptHandler.\n"));
/* Call the deferred interrupt service handler for this adapter */
(*Adapter->Miniport->Chars.HandleInterruptHandler)(
Adapter->NdisMiniportBlock.MiniportAdapterContext);
NDIS_DbgPrint(MAX_TRACE, ("After HandleInterruptHandler.\n"));
KeAcquireSpinLockAtDpcLevel(&Adapter->NdisMiniportBlock.Lock);
if ((!WasBusy) && (Adapter->WorkQueueHead)) {
KeInsertQueueDpc(&Adapter->MiniportDpc, NULL, NULL);

View file

@ -49,22 +49,25 @@ MiniDisplayPacket(
{
ULONG i, Length;
UCHAR Buffer[64];
#if 0
if ((DebugTraceLevel | DEBUG_PACKET) > 0) {
Length = CopyPacketToBuffer(
(PUCHAR)&Buffer,
Packet,
0,
64);
Length = CopyPacketToBuffer(
(PUCHAR)&Buffer,
Packet,
0,
64);
DbgPrint("*** PACKET START ***");
NDIS_DbgPrint(DEBUG_PACKET, ("*** PACKET START ***"));
for (i = 0; i < Length; i++) {
if (i % 12 == 0)
DbgPrint("\n%04X ", i);
DbgPrint("%02X ", Buffer[i]);
}
for (i = 0; i < Length; i++) {
if (i % 12 == 0)
DbgPrint("\n%04X ", i);
DbgPrint("%02X ", Buffer[i]);
DbgPrint("*** PACKET STOP ***\n");
}
NDIS_DbgPrint(DEBUG_PACKET, ("*** PACKET STOP ***\n"));
#endif
}
#endif /* DBG */
@ -99,12 +102,13 @@ MiniIndicateData(
Adapter, HeaderBuffer, HeaderBufferSize, LookaheadBuffer, LookaheadBufferSize));
#ifdef DBG
if (DebugTraceLevel | DEBUG_PACKET) {
#if 0
if ((DebugTraceLevel | DEBUG_PACKET) > 0) {
ULONG i, Length;
PUCHAR p;
NDIS_DbgPrint(DEBUG_PACKET, ("*** RECEIVE PACKET START ***\n"));
NDIS_DbgPrint(DEBUG_PACKET, ("HEADER:"));
DbgPrint("*** RECEIVE PACKET START ***\n");
DbgPrint("HEADER:");
p = HeaderBuffer;
for (i = 0; i < HeaderBufferSize; i++) {
if (i % 12 == 0)
@ -113,7 +117,7 @@ MiniIndicateData(
(ULONG_PTR)p += 1;
}
NDIS_DbgPrint(DEBUG_PACKET, ("\nFRAME:"));
DbgPrint("\nFRAME:\n");
p = LookaheadBuffer;
Length = (LookaheadBufferSize < 64)? LookaheadBufferSize : 64;
@ -124,8 +128,9 @@ MiniIndicateData(
(ULONG_PTR)p += 1;
}
NDIS_DbgPrint(DEBUG_PACKET, ("*** RECEIVE PACKET STOP ***\n"));
DbgPrint("\n*** RECEIVE PACKET STOP ***\n");
}
#endif
#endif /* DBG */
KeAcquireSpinLock(&Adapter->NdisMiniportBlock.Lock, &OldIrql);
@ -327,7 +332,8 @@ MiniAdapterHasAddress(
break;
default:
NDIS_DbgPrint(MIN_TRACE, ("Adapter has unsupported media type (0x%X).\n", Adapter->NdisMiniportBlock.MediaType));
NDIS_DbgPrint(MIN_TRACE, ("Adapter has unsupported media type (0x%X).\n",
Adapter->NdisMiniportBlock.MediaType));
return FALSE;
}

View file

@ -23,8 +23,8 @@
/* Name of UDP device */
//#define UDP_DEVICE_NAME L"\\Device\\Udp"
#define UDP_DEVICE_NAME L"\\Device\\NTUdp"
#define UDP_DEVICE_NAME L"\\Device\\Udp"
//#define UDP_DEVICE_NAME L"\\Device\\NTUdp"
#ifdef i386

View file

@ -29,8 +29,10 @@ endif
$(TARGETNAME).sys: $(OBJECTS)
$(CC) \
-nostartfiles -nostdlib \
--subsystem=native \
-mdll \
-specs=../../svc_specs \
--dll \
-Wl,-e,_DriverEntry@8 \
-Wl,--base-file,base.tmp \
-Wl,--defsym,_end=end \
@ -45,8 +47,10 @@ $(TARGETNAME).sys: $(OBJECTS)
--output-exp temp.exp
- $(RM) base.tmp
$(CC) \
-nostartfiles -nostdlib \
--subsystem=native \
-mdll \
-specs=../../svc_specs \
--dll \
-Wl,--image-base,0x10000 \
-Wl,-e,_DriverEntry@8 \
-Wl,temp.exp \

View file

@ -186,8 +186,8 @@ NTSTATUS TdiOpenTransport(
ULONG EaLength;
EaLength = sizeof(FILE_FULL_EA_INFORMATION) +
sizeof(TdiTransportAddress) +
sizeof(TA_ADDRESS_IP) + 1;
TDI_TRANSPORT_ADDRESS_LENGTH +
sizeof(TA_ADDRESS_IP);
EaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePool(NonPagedPool, EaLength);
if (!EaInfo) {
TDI_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
@ -196,13 +196,13 @@ NTSTATUS TdiOpenTransport(
RtlZeroMemory(EaInfo, EaLength);
EaInfo->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
RtlCopyMemory (EaInfo->EaName,
TdiTransportAddress,
sizeof(TdiTransportAddress));
RtlCopyMemory(EaInfo->EaName,
TdiTransportAddress,
TDI_TRANSPORT_ADDRESS_LENGTH);
EaInfo->EaValueLength = sizeof(TA_ADDRESS_IP);
Address = (PTA_ADDRESS_IP)(EaInfo->EaName + sizeof(TdiTransportAddress));
Address = (PTA_ADDRESS_IP)(EaInfo->EaName + TDI_TRANSPORT_ADDRESS_LENGTH);
Address->TAAddressCount = 1;
Address->Address[0].AddressLength = sizeof(TDI_ADDRESS_IP);
Address->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
Address->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
Address->Address[0].Address[0].sin_port = WH2N(Port);
Address->Address[0].Address[0].in_addr = 0;

View file

@ -15,6 +15,7 @@
#define MID_TRACE 0x00000002
#define MAX_TRACE 0x00000003
#define DEBUG_CHECK 0x00000100
#define DEBUG_ULTRA 0xFFFFFFFF
#ifdef DBG
@ -58,7 +59,7 @@ extern DWORD DebugTraceLevel;
AFD_DbgPrint(MIN_TRACE, ("is unimplemented, please try again later.\n"));
#define CHECKPOINT \
AFD_DbgPrint(MIN_TRACE, ("\n"));
AFD_DbgPrint(DEBUG_CHECK, ("\n"));
#define CP CHECKPOINT

View file

@ -2,7 +2,7 @@
PATH_TO_TOP = ../..
CFLAGS = -I./include -DUNICODE
CFLAGS = -I./include -DUNICODE -DDBG
TARGETNAME=msafd

View file

@ -13,7 +13,7 @@
#ifdef DBG
/* See debug.h for debug/trace constants */
DWORD DebugTraceLevel = MAX_TRACE;
DWORD DebugTraceLevel = MIN_TRACE;
#endif /* DBG */
@ -43,7 +43,7 @@ NTSTATUS OpenSocket(
* SocketType = Type of socket
* Protocol = Protocol type
* HelperContext = Pointer to context information for helper DLL
* NotificationEvents = Events for which helper DLL is to be notified
* NotificationEvents = Events for which helper DLL is to be notified
* TdiDeviceName = Pointer to name of TDI device to use
* RETURNS:
* Status of operation
@ -57,13 +57,15 @@ NTSTATUS OpenSocket(
HANDLE FileHandle;
NTSTATUS Status;
ULONG EaLength;
ULONG EaShort;
CP
AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
EaLength = sizeof(FILE_FULL_EA_INFORMATION) +
AFD_SOCKET_LENGTH +
sizeof(AFD_SOCKET_INFORMATION) +
TdiDeviceName->Length + 1;
EaShort = sizeof(FILE_FULL_EA_INFORMATION) +
AFD_SOCKET_LENGTH +
sizeof(AFD_SOCKET_INFORMATION);
EaLength = EaShort + TdiDeviceName->Length + sizeof(WCHAR);
EaInfo = (PFILE_FULL_EA_INFORMATION)HeapAlloc(GlobalHeap, 0, EaLength);
if (!EaInfo) {
@ -71,8 +73,6 @@ NTSTATUS OpenSocket(
return STATUS_INSUFFICIENT_RESOURCES;
}
CP
RtlZeroMemory(EaInfo, EaLength);
EaInfo->EaNameLength = AFD_SOCKET_LENGTH;
RtlCopyMemory(EaInfo->EaName,
@ -80,8 +80,6 @@ NTSTATUS OpenSocket(
AFD_SOCKET_LENGTH);
EaInfo->EaValueLength = sizeof(AFD_SOCKET_INFORMATION);
CP
SocketInfo = (PAFD_SOCKET_INFORMATION)(EaInfo->EaName + AFD_SOCKET_LENGTH);
SocketInfo->AddressFamily = AddressFamily;
@ -89,53 +87,43 @@ NTSTATUS OpenSocket(
SocketInfo->Protocol = Protocol;
SocketInfo->HelperContext = HelperContext;
SocketInfo->NotificationEvents = NotificationEvents;
/* Zeroed above so initialized to a wildcard address if a raw socket */
SocketInfo->Name.sa_family = AddressFamily;
/* Store TDI device name last in buffer */
SocketInfo->TdiDeviceName.Buffer = (PWCHAR)(EaInfo + EaLength);
//SocketInfo->TdiDeviceName.Length = TdiDeviceName.Length;
SocketInfo->TdiDeviceName.MaximumLength = TdiDeviceName->Length;
SocketInfo->TdiDeviceName.Buffer = (PWCHAR)(EaInfo + EaShort);
SocketInfo->TdiDeviceName.MaximumLength = TdiDeviceName->Length + sizeof(WCHAR);
RtlCopyUnicodeString(&SocketInfo->TdiDeviceName, TdiDeviceName);
/*RtlCopyMemory(SocketInfo->TdiDeviceName.Buffer,
TdiDeviceName.Buffer,
TdiDeviceName.Length + 1);*/
AFD_DbgPrint(MAX_TRACE, ("EaInfo at (0x%X) EaLength is (%d).\n", (UINT)EaInfo, (INT)EaLength));
RtlInitUnicodeString(&DeviceName, L"\\Device\\Afd");
InitializeObjectAttributes(&ObjectAttributes,
InitializeObjectAttributes(&ObjectAttributes,
&DeviceName,
0,
NULL,
NULL);
CP
Status = NtCreateFile(&FileHandle,
FILE_GENERIC_READ | FILE_GENERIC_WRITE,
&ObjectAttributes,
&Iosb,
NULL,
0,
0,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_ALERT,
0,
0,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_ALERT,
EaInfo,
EaLength);
CP
HeapFree(GlobalHeap, 0, EaInfo);
CP
if (!NT_SUCCESS(Status)) {
AFD_DbgPrint(MIN_TRACE, ("Error opening device (Status 0x%X).\n", (UINT)Status));
return STATUS_INSUFFICIENT_RESOURCES;
AFD_DbgPrint(MIN_TRACE, ("Error opening device (Status 0x%X).\n", (UINT)Status));
return STATUS_INSUFFICIENT_RESOURCES;
}
CP
*Socket = (SOCKET)FileHandle;
return STATUS_SUCCESS;
@ -192,18 +180,16 @@ WSPSocket(
ProtocolInfo.iProtocol = protocol;
}
CP
HelperDLL = LocateHelperDLL(lpProtocolInfo);
if (!HelperDLL) {
*lpErrno = WSAEAFNOSUPPORT;
return INVALID_SOCKET;
}
CP
AddressFamily = lpProtocolInfo->iAddressFamily;
SocketType = lpProtocolInfo->iSocketType;
Protocol = lpProtocolInfo->iProtocol;
CP
Status = HelperDLL->EntryTable.lpWSHOpenSocket2(&AddressFamily,
&SocketType,
&Protocol,
@ -216,7 +202,7 @@ WSPSocket(
*lpErrno = Status;
return INVALID_SOCKET;
}
CP
NtStatus = OpenSocket(&Socket,
AddressFamily,
SocketType,
@ -224,17 +210,17 @@ WSPSocket(
HelperContext,
NotificationEvents,
&TdiDeviceName);
CP
RtlFreeUnicodeString(&TdiDeviceName);
if (!NT_SUCCESS(NtStatus)) {
CP
*lpErrno = RtlNtStatusToDosError(Status);
return INVALID_SOCKET;
}
CP
/* FIXME: Assumes catalog entry id to be 1 */
Socket2 = Upcalls.lpWPUModifyIFSHandle(1, Socket, lpErrno);
CP
if (Socket2 == INVALID_SOCKET) {
/* FIXME: Cleanup */
AFD_DbgPrint(MIN_TRACE, ("FIXME: Cleanup.\n"));
@ -268,7 +254,7 @@ WSPCloseSocket(
AFD_DbgPrint(MAX_TRACE, ("s (0x%X).\n", s));
Status = NtClose((HANDLE)s);
CP
if (NT_SUCCESS(Status)) {
*lpErrno = NO_ERROR;
return NO_ERROR;
@ -297,18 +283,18 @@ WSPBind(
* 0, or SOCKET_ERROR if the socket could not be bound
*/
{
AFD_DbgPrint(MAX_TRACE, ("s (0x%X) name (0x%X) namelen (%d).\n", s, name, namelen));
AFD_DbgPrint(MAX_TRACE, ("s (0x%X) name (0x%X) namelen (%d).\n", s, name, namelen));
#if 0
FILE_REQUEST_BIND Request;
FILE_REPLY_BIND Reply;
IO_STATUS_BLOCK Iosb;
NTSTATUS Status;
FILE_REQUEST_BIND Request;
FILE_REPLY_BIND Reply;
IO_STATUS_BLOCK Iosb;
NTSTATUS Status;
RtlCopyMemory(&Request.Name, name, sizeof(SOCKADDR));
RtlCopyMemory(&Request.Name, name, sizeof(SOCKADDR));
Status = NtDeviceIoControlFile((HANDLE)s,
NULL,
Status = NtDeviceIoControlFile((HANDLE)s,
NULL,
NULL,
NULL,
&Iosb,
@ -320,15 +306,15 @@ WSPBind(
if (Status == STATUS_PENDING) {
if (!NT_SUCCESS(NtWaitForSingleObject((HANDLE)s, FALSE, NULL))) {
/* FIXME: What error code should be returned? */
/* FIXME: What error code should be returned? */
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
}
}
}
if (!NT_SUCCESS(Status)) {
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
if (!NT_SUCCESS(Status)) {
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
}
#endif
return 0;
@ -361,12 +347,22 @@ WSPSelect(
AFD_DbgPrint(MAX_TRACE, ("readfds (0x%X) writefds (0x%X) exceptfds (0x%X).\n",
readfds, writefds, exceptfds));
/* FIXME: For now, all reads are timed out immediately */
if (readfds != NULL) {
AFD_DbgPrint(MIN_TRACE, ("Timing out read query.\n"));
*lpErrno = WSAETIMEDOUT;
return SOCKET_ERROR;
}
/* FIXME: For now, always allow write */
if (writefds != NULL) {
AFD_DbgPrint(MAX_TRACE, ("Setting one socket writeable.\n"));
AFD_DbgPrint(MIN_TRACE, ("Setting one socket writeable.\n"));
*lpErrno = NO_ERROR;
return 1;
}
*lpErrno = NO_ERROR;
return 0;
}
@ -405,22 +401,19 @@ WSPStartup(
Status = WSAVERNOTSUPPORTED;
CP
hWS2_32 = GetModuleHandle(L"ws2_32.dll");
CP
if (hWS2_32) {
CP
if (hWS2_32 != NULL) {
lpWPUCompleteOverlappedRequest = (LPWPUCOMPLETEOVERLAPPEDREQUEST)
GetProcAddress(hWS2_32, "WPUCompleteOverlappedRequest");
CP
if (lpWPUCompleteOverlappedRequest) {
if (lpWPUCompleteOverlappedRequest != NULL) {
Status = NO_ERROR;
StartupCount++;
CP
}
CP
} else {
AFD_DbgPrint(MIN_TRACE, ("GetModuleHandle() failed for ws2_32.dll\n"));
}
} else {
Status = NO_ERROR;
@ -429,8 +422,9 @@ WSPStartup(
//LeaveCriticalSection(&InitCriticalSection);
AFD_DbgPrint(MIN_TRACE, ("WSPSocket() is at 0x%X\n", WSPSocket));
if (Status == NO_ERROR) {
CP
lpProcTable->lpWSPAccept = WSPAccept;
lpProcTable->lpWSPAddressToString = WSPAddressToString;
lpProcTable->lpWSPAsyncSelect = WSPAsyncSelect;
@ -464,7 +458,6 @@ WSPStartup(
lpWSPData->wVersion = MAKEWORD(2, 2);
lpWSPData->wHighVersion = MAKEWORD(2, 2);
CP
}
AFD_DbgPrint(MIN_TRACE, ("Status (%d).\n", Status));
@ -501,8 +494,6 @@ WSPCleanup(
*lpErrno = NO_ERROR;
CP
return 0;
}
@ -517,13 +508,10 @@ DllMain(HANDLE hInstDll,
switch (dwReason) {
case DLL_PROCESS_ATTACH:
CP
/* Don't need thread attach notifications
so disable them to improve performance */
DisableThreadLibraryCalls(hInstDll);
CP
//InitializeCriticalSection(&InitCriticalSection);
GlobalHeap = GetProcessHeap();
@ -533,11 +521,7 @@ DllMain(HANDLE hInstDll,
return FALSE;
}
CP
CreateHelperDLLDatabase();
CP
break;
case DLL_THREAD_ATTACH:
@ -547,14 +531,13 @@ DllMain(HANDLE hInstDll,
break;
case DLL_PROCESS_DETACH:
CP
DestroyHelperDLLDatabase();
//HeapDestroy(GlobalHeap);
//DeleteCriticalSection(&InitCriticalSection);
break;
}
CP
return TRUE;
}

View file

@ -50,16 +50,12 @@ INT DestroyHelperDLL(
RemoveEntryList(&HelperDLL->ListEntry);
//LeaveCriticalSection(&HelperDLLDatabaseLock);
CP
if (HelperDLL->hModule) {
Status = UnloadHelperDLL(HelperDLL);
} else {
Status = NO_ERROR;
}
CP
if (HelperDLL->Mapping)
HeapFree(GlobalHeap, 0, HelperDLL->Mapping);
@ -67,8 +63,6 @@ INT DestroyHelperDLL(
HeapFree(GlobalHeap, 0, HelperDLL);
CP
return Status;
}
@ -108,35 +102,36 @@ PWSHELPER_DLL LocateHelperDLL(
}
#define GET_ENTRY_POINT(helper, name) { \
#define GET_ENTRY_POINT(helper, exportname, identifier) { \
PVOID entry; \
\
entry = GetProcAddress(helper->hModule, "##name"); \
entry = GetProcAddress(helper->hModule, exportname); \
if (!entry) \
return ERROR_BAD_PROVIDER; \
(*(PULONG*)helper->EntryTable.lp##name) = entry; \
((PVOID)helper->EntryTable.##identifier) = entry; \
}
INT GetHelperDLLEntries(
PWSHELPER_DLL HelperDLL)
{
GET_ENTRY_POINT(HelperDLL, WSHAddressToString);
GET_ENTRY_POINT(HelperDLL, WSHEnumProtocols);
GET_ENTRY_POINT(HelperDLL, WSHGetBroadcastSockaddr);
GET_ENTRY_POINT(HelperDLL, WSHGetProviderGuid);
GET_ENTRY_POINT(HelperDLL, WSHGetSockaddrType);
GET_ENTRY_POINT(HelperDLL, WSHGetSocketInformation);
GET_ENTRY_POINT(HelperDLL, WSHGetWildcardSockaddr);
GET_ENTRY_POINT(HelperDLL, WSHGetWinsockMapping);
GET_ENTRY_POINT(HelperDLL, WSHGetWSAProtocolInfo);
GET_ENTRY_POINT(HelperDLL, WSHIoctl);
GET_ENTRY_POINT(HelperDLL, WSHJoinLeaf);
GET_ENTRY_POINT(HelperDLL, WSHNotify);
GET_ENTRY_POINT(HelperDLL, WSHOpenSocket);
GET_ENTRY_POINT(HelperDLL, WSHOpenSocket2);
GET_ENTRY_POINT(HelperDLL, WSHSetSocketInformation);
GET_ENTRY_POINT(HelperDLL, WSHStringToAddress);
GET_ENTRY_POINT(HelperDLL, "WSHAddressToString", lpWSHAddressToString);
GET_ENTRY_POINT(HelperDLL, "WSHEnumProtocols", lpWSHEnumProtocols);
GET_ENTRY_POINT(HelperDLL, "WSHGetBroadcastSockaddr", lpWSHGetBroadcastSockaddr);
GET_ENTRY_POINT(HelperDLL, "WSHGetProviderGuid", lpWSHGetProviderGuid);
GET_ENTRY_POINT(HelperDLL, "WSHGetSockaddrType", lpWSHGetSockaddrType);
GET_ENTRY_POINT(HelperDLL, "WSHGetSocketInformation", lpWSHGetSocketInformation);
GET_ENTRY_POINT(HelperDLL, "WSHGetWildcardSockaddr", lpWSHGetWildcardSockaddr);
GET_ENTRY_POINT(HelperDLL, "WSHGetWinsockMapping", lpWSHGetWinsockMapping);
GET_ENTRY_POINT(HelperDLL, "WSHGetWSAProtocolInfo", lpWSHGetWSAProtocolInfo);
GET_ENTRY_POINT(HelperDLL, "WSHIoctl", lpWSHIoctl);
GET_ENTRY_POINT(HelperDLL, "WSHJoinLeaf", lpWSHJoinLeaf);
GET_ENTRY_POINT(HelperDLL, "WSHNotify", lpWSHNotify);
GET_ENTRY_POINT(HelperDLL, "WSHOpenSocket", lpWSHOpenSocket);
GET_ENTRY_POINT(HelperDLL, "WSHOpenSocket2", lpWSHOpenSocket2);
GET_ENTRY_POINT(HelperDLL, "WSHSetSocketInformation", lpWSHSetSocketInformation);
GET_ENTRY_POINT(HelperDLL, "WSHStringToAddress", lpWSHStringToAddress);
return NO_ERROR;
}
@ -151,6 +146,9 @@ INT LoadHelperDLL(
if (!HelperDLL->hModule) {
/* DLL is not loaded so load it now */
HelperDLL->hModule = LoadLibrary(HelperDLL->LibraryName);
AFD_DbgPrint(MAX_TRACE, ("hModule is (0x%X).\n", HelperDLL->hModule));
if (HelperDLL->hModule) {
Status = GetHelperDLLEntries(HelperDLL);
} else
@ -169,11 +167,13 @@ INT UnloadHelperDLL(
{
INT Status = NO_ERROR;
AFD_DbgPrint(MAX_TRACE, ("HelperDLL (0x%X).\n", HelperDLL));
AFD_DbgPrint(MAX_TRACE, ("HelperDLL (0x%X) hModule (0x%X).\n", HelperDLL, HelperDLL->hModule));
if (HelperDLL->hModule) {
if (!FreeLibrary(HelperDLL->hModule))
if (!FreeLibrary(HelperDLL->hModule)) {
CP
Status = GetLastError();
}
HelperDLL->hModule = NULL;
}
@ -186,8 +186,6 @@ VOID CreateHelperDLLDatabase(VOID)
{
PWSHELPER_DLL HelperDLL;
CP
//InitializeCriticalSection(&HelperDLLDatabaseLock);
InitializeListHead(&HelperDLLDatabaseListHead);
@ -199,27 +197,19 @@ VOID CreateHelperDLLDatabase(VOID)
return;
}
CP
HelperDLL->Mapping = HeapAlloc(GlobalHeap, 0, sizeof(WINSOCK_MAPPING) + 3 * sizeof(DWORD));
if (!HelperDLL->Mapping) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient memory.\n"));
return;
}
CP
HelperDLL->Mapping->Rows = 1;
HelperDLL->Mapping->Columns = 3;
HelperDLL->Mapping->Mapping[0].AddressFamily = AF_INET;
HelperDLL->Mapping->Mapping[0].SocketType = SOCK_RAW;
HelperDLL->Mapping->Mapping[0].Protocol = 0;
CP
LoadHelperDLL(HelperDLL);
CP
}
@ -229,8 +219,6 @@ VOID DestroyHelperDLLDatabase(VOID)
PLIST_ENTRY NextEntry;
PWSHELPER_DLL HelperDLL;
CP
CurrentEntry = HelperDLLDatabaseListHead.Flink;
while (CurrentEntry != &HelperDLLDatabaseListHead) {
NextEntry = CurrentEntry->Flink;
@ -243,8 +231,6 @@ VOID DestroyHelperDLLDatabase(VOID)
CurrentEntry = NextEntry;
}
CP
//DeleteCriticalSection(&HelperDLLDatabaseLock);
}

View file

@ -18,9 +18,9 @@ WSPAsyncSelect(
IN LONG lEvent,
OUT LPINT lpErrno)
{
UNIMPLEMENTED
UNIMPLEMENTED
return 0;
return 0;
}
@ -37,9 +37,9 @@ WSPRecv(
IN LPWSATHREADID lpThreadId,
OUT LPINT lpErrno)
{
UNIMPLEMENTED
UNIMPLEMENTED
return 0;
return 0;
}
@ -50,12 +50,11 @@ WSPRecvDisconnect(
OUT LPWSABUF lpInboundDisconnectData,
OUT LPINT lpErrno)
{
UNIMPLEMENTED
UNIMPLEMENTED
return 0;
return 0;
}
INT
WSPAPI
WSPRecvFrom(
@ -71,37 +70,37 @@ WSPRecvFrom(
IN LPWSATHREADID lpThreadId,
OUT LPINT lpErrno)
{
PFILE_REQUEST_RECVFROM Request;
FILE_REPLY_RECVFROM Reply;
IO_STATUS_BLOCK Iosb;
NTSTATUS Status;
DWORD Size;
PFILE_REQUEST_RECVFROM Request;
FILE_REPLY_RECVFROM Reply;
IO_STATUS_BLOCK Iosb;
NTSTATUS Status;
DWORD Size;
AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
Size = dwBufferCount * sizeof(WSABUF);
Size = dwBufferCount * sizeof(WSABUF);
Request = (PFILE_REQUEST_RECVFROM)HeapAlloc(
GlobalHeap, 0, sizeof(FILE_REQUEST_RECVFROM) + Size);
if (!Request) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
}
Request = (PFILE_REQUEST_RECVFROM)HeapAlloc(
GlobalHeap, 0, sizeof(FILE_REQUEST_RECVFROM) + Size);
if (!Request) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
}
/* Put buffer pointers after request structure */
Request->Buffers = (LPWSABUF)(Request + sizeof(FILE_REQUEST_RECVFROM));
Request->BufferCount = dwBufferCount;
Request->Flags = lpFlags;
Request->From = lpFrom;
Request->FromLen = lpFromLen;
/* Put buffer pointers after request structure */
Request->Buffers = (LPWSABUF)(Request + sizeof(FILE_REQUEST_RECVFROM));
Request->BufferCount = dwBufferCount;
Request->Flags = lpFlags;
Request->From = lpFrom;
Request->FromLen = lpFromLen;
RtlCopyMemory(Request->Buffers, lpBuffers, Size);
RtlCopyMemory(Request->Buffers, lpBuffers, Size);
Status = NtDeviceIoControlFile((HANDLE)s,
NULL,
NULL,
Status = NtDeviceIoControlFile((HANDLE)s,
NULL,
NULL,
NULL,
&Iosb,
IOCTL_AFD_RECVFROM,
Request,
@ -109,28 +108,28 @@ WSPRecvFrom(
&Reply,
sizeof(FILE_REPLY_RECVFROM));
HeapFree(GlobalHeap, 0, Request);
HeapFree(GlobalHeap, 0, Request);
if (Status == STATUS_PENDING) {
AFD_DbgPrint(MAX_TRACE, ("Waiting on transport.\n"));
/* FIXME: Wait only for blocking sockets */
AFD_DbgPrint(MAX_TRACE, ("Waiting on transport.\n"));
/* FIXME: Wait only for blocking sockets */
if (!NT_SUCCESS(NtWaitForSingleObject((HANDLE)s, FALSE, NULL))) {
AFD_DbgPrint(MAX_TRACE, ("Wait failed.\n"));
/* FIXME: What error code should be returned? */
AFD_DbgPrint(MIN_TRACE, ("Wait failed.\n"));
/* FIXME: What error code should be returned? */
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
}
}
}
if (!NT_SUCCESS(Status)) {
AFD_DbgPrint(MIN_TRACE, ("Status (0x%X).\n", Status));
if (!NT_SUCCESS(Status)) {
AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
return SOCKET_ERROR;
}
AFD_DbgPrint(MAX_TRACE, ("Receive successful.\n"));
AFD_DbgPrint(MAX_TRACE, ("Receive successful.\n"));
return 0;
return 0;
}
@ -147,9 +146,9 @@ WSPSend(
IN LPWSATHREADID lpThreadId,
OUT LPINT lpErrno)
{
UNIMPLEMENTED
UNIMPLEMENTED
return 0;
return 0;
}
@ -160,9 +159,9 @@ WSPSendDisconnect(
IN LPWSABUF lpOutboundDisconnectData,
OUT LPINT lpErrno)
{
UNIMPLEMENTED
UNIMPLEMENTED
return 0;
return 0;
}
@ -181,36 +180,36 @@ WSPSendTo(
IN LPWSATHREADID lpThreadId,
OUT LPINT lpErrno)
{
PFILE_REQUEST_SENDTO Request;
FILE_REPLY_SENDTO Reply;
IO_STATUS_BLOCK Iosb;
NTSTATUS Status;
DWORD Size;
PFILE_REQUEST_SENDTO Request;
FILE_REPLY_SENDTO Reply;
IO_STATUS_BLOCK Iosb;
NTSTATUS Status;
DWORD Size;
AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
Size = dwBufferCount * sizeof(WSABUF);
Size = dwBufferCount * sizeof(WSABUF);
Request = (PFILE_REQUEST_SENDTO)HeapAlloc(
GlobalHeap, 0, sizeof(FILE_REQUEST_SENDTO) + Size);
if (!Request) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
}
Request = (PFILE_REQUEST_SENDTO)HeapAlloc(
GlobalHeap, 0, sizeof(FILE_REQUEST_SENDTO) + Size);
if (!Request) {
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
}
/* Put buffer pointers after request structure */
Request->Buffers = (LPWSABUF)(Request + sizeof(FILE_REQUEST_SENDTO));
Request->BufferCount = dwBufferCount;
Request->Flags = dwFlags;
Request->ToLen = iToLen;
/* Put buffer pointers after request structure */
Request->Buffers = (LPWSABUF)(Request + sizeof(FILE_REQUEST_SENDTO));
Request->BufferCount = dwBufferCount;
Request->Flags = dwFlags;
Request->ToLen = iToLen;
RtlCopyMemory(&Request->To, lpTo, sizeof(SOCKADDR));
RtlCopyMemory(&Request->To, lpTo, sizeof(SOCKADDR));
RtlCopyMemory(Request->Buffers, lpBuffers, Size);
RtlCopyMemory(Request->Buffers, lpBuffers, Size);
Status = NtDeviceIoControlFile((HANDLE)s,
NULL,
Status = NtDeviceIoControlFile((HANDLE)s,
NULL,
NULL,
NULL,
&Iosb,
@ -220,28 +219,28 @@ WSPSendTo(
&Reply,
sizeof(FILE_REPLY_SENDTO));
HeapFree(GlobalHeap, 0, Request);
HeapFree(GlobalHeap, 0, Request);
if (Status == STATUS_PENDING) {
AFD_DbgPrint(MAX_TRACE, ("Waiting on transport.\n"));
/* FIXME: Wait only for blocking sockets */
AFD_DbgPrint(MAX_TRACE, ("Waiting on transport.\n"));
/* FIXME: Wait only for blocking sockets */
if (!NT_SUCCESS(NtWaitForSingleObject((HANDLE)s, FALSE, NULL))) {
AFD_DbgPrint(MAX_TRACE, ("Wait failed.\n"));
/* FIXME: What error code should be returned? */
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
AFD_DbgPrint(MAX_TRACE, ("Wait failed.\n"));
/* FIXME: What error code should be returned? */
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
}
}
}
if (!NT_SUCCESS(Status)) {
AFD_DbgPrint(MIN_TRACE, ("Status (0x%X).\n", Status));
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
}
if (!NT_SUCCESS(Status)) {
AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
*lpErrno = WSAENOBUFS;
return SOCKET_ERROR;
}
AFD_DbgPrint(MAX_TRACE, ("Send successful.\n"));
AFD_DbgPrint(MAX_TRACE, ("Send successful.\n"));
return 0;
return 0;
}
/* EOF */

View file

@ -15,6 +15,7 @@
#define MID_TRACE 0x00000002
#define MAX_TRACE 0x00000003
#define DEBUG_CHECK 0x00000100
#define DEBUG_ULTRA 0xFFFFFFFF
#ifdef DBG
@ -58,7 +59,7 @@ extern DWORD DebugTraceLevel;
WS_DbgPrint(MIN_TRACE, ("is unimplemented, please try again later.\n"));
#define CHECKPOINT \
WS_DbgPrint(MIN_TRACE, ("\n"));
WS_DbgPrint(DEBUG_CHECK, ("\n"));
#define CP CHECKPOINT

View file

@ -42,6 +42,9 @@ VOID DereferenceProviderByPointer(
//LeaveCriticalSection(&Provider->Lock);
if (Provider->ReferenceCount == 0) {
WS_DbgPrint(MAX_TRACE, ("Provider at 0x%X has reference count 0 (unloading).\n",
Provider));
DestroyCatalogEntry(Provider);
}
}
@ -50,140 +53,129 @@ VOID DereferenceProviderByPointer(
PCATALOG_ENTRY CreateCatalogEntry(
LPWSTR LibraryName)
{
PCATALOG_ENTRY Provider;
PCATALOG_ENTRY Provider;
WS_DbgPrint(MAX_TRACE, ("LibraryName (%S).\n", LibraryName));
Provider = HeapAlloc(GlobalHeap, 0, sizeof(CATALOG_ENTRY));
if (!Provider) {
WS_DbgPrint(MIN_TRACE, ("Insufficient memory.\n"));
return NULL;
Provider = HeapAlloc(GlobalHeap, 0, sizeof(CATALOG_ENTRY));
if (!Provider) {
WS_DbgPrint(MIN_TRACE, ("Insufficient memory.\n"));
return NULL;
}
CP
ZeroMemory(Provider, sizeof(CATALOG_ENTRY));
ZeroMemory(Provider, sizeof(CATALOG_ENTRY));
Provider->ReferenceCount = 1;
CP
Provider->ReferenceCount = 1;
InitializeCriticalSection(&Provider->Lock);
Provider->hModule = (HMODULE)INVALID_HANDLE_VALUE;
//InitializeCriticalSection(&Provider->Lock);
CP
Provider->hModule = NULL;
CP
lstrcpyW(Provider->LibraryName, LibraryName);
CP
Provider->Mapping = NULL;
Provider->Mapping = NULL;
CP
//EnterCriticalSection(&CatalogLock);
CP
InsertTailList(&CatalogListHead, &Provider->ListEntry);
CP
//LeaveCriticalSection(&CatalogLock);
CP
//EnterCriticalSection(&CatalogLock);
return Provider;
InsertTailList(&CatalogListHead, &Provider->ListEntry);
//LeaveCriticalSection(&CatalogLock);
return Provider;
}
INT DestroyCatalogEntry(
PCATALOG_ENTRY Provider)
{
INT Status;
INT Status;
WS_DbgPrint(MAX_TRACE, ("Provider (0x%X).\n", Provider));
WS_DbgPrint(MAX_TRACE, ("Provider (0x%X).\n", Provider));
CP
//EnterCriticalSection(&CatalogLock);
RemoveEntryList(&Provider->ListEntry);
//LeaveCriticalSection(&CatalogLock);
CP
HeapFree(GlobalHeap, 0, Provider->Mapping);
CP
if (Provider->hModule) {
CP
Status = UnloadProvider(Provider);
CP
} else {
Status = NO_ERROR;
}
CP
//DeleteCriticalSection(&Provider->Lock);
//EnterCriticalSection(&CatalogLock);
RemoveEntryList(&Provider->ListEntry);
//LeaveCriticalSection(&CatalogLock);
HeapFree(GlobalHeap, 0, Provider);
CP
return Status;
HeapFree(GlobalHeap, 0, Provider->Mapping);
if (Provider->hModule) {
Status = UnloadProvider(Provider);
} else {
Status = NO_ERROR;
}
//DeleteCriticalSection(&Provider->Lock);
HeapFree(GlobalHeap, 0, Provider);
return Status;
}
PCATALOG_ENTRY LocateProvider(
LPWSAPROTOCOL_INFOW lpProtocolInfo)
{
PLIST_ENTRY CurrentEntry;
PCATALOG_ENTRY Provider;
UINT i;
PLIST_ENTRY CurrentEntry;
PCATALOG_ENTRY Provider;
UINT i;
WS_DbgPrint(MAX_TRACE, ("lpProtocolInfo (0x%X).\n", lpProtocolInfo));
WS_DbgPrint(MAX_TRACE, ("lpProtocolInfo (0x%X).\n", lpProtocolInfo));
//EnterCriticalSection(&CatalogLock);
CurrentEntry = CatalogListHead.Flink;
while (CurrentEntry != &CatalogListHead) {
Provider = CONTAINING_RECORD(CurrentEntry,
CATALOG_ENTRY,
ListEntry);
//EnterCriticalSection(&CatalogLock);
for (i = 0; i < Provider->Mapping->Rows; i++) {
if ((lpProtocolInfo->iAddressFamily == Provider->Mapping->Mapping[i].AddressFamily) &&
(lpProtocolInfo->iSocketType == Provider->Mapping->Mapping[i].SocketType) &&
((lpProtocolInfo->iProtocol == Provider->Mapping->Mapping[i].Protocol) ||
(lpProtocolInfo->iSocketType == SOCK_RAW))) {
//LeaveCriticalSection(&CatalogLock);
CurrentEntry = CatalogListHead.Flink;
while (CurrentEntry != &CatalogListHead) {
Provider = CONTAINING_RECORD(CurrentEntry,
CATALOG_ENTRY,
ListEntry);
for (i = 0; i < Provider->Mapping->Rows; i++) {
if ((lpProtocolInfo->iAddressFamily == Provider->Mapping->Mapping[i].AddressFamily) &&
(lpProtocolInfo->iSocketType == Provider->Mapping->Mapping[i].SocketType) &&
((lpProtocolInfo->iProtocol == Provider->Mapping->Mapping[i].Protocol) ||
(lpProtocolInfo->iSocketType == SOCK_RAW))) {
//LeaveCriticalSection(&CatalogLock);
WS_DbgPrint(MID_TRACE, ("Returning provider at (0x%X).\n", Provider));
return Provider;
}
}
CurrentEntry = CurrentEntry->Flink;
return Provider;
}
}
//LeaveCriticalSection(&CatalogLock);
WS_DbgPrint(MID_TRACE, ("Provider was not found.\n"));
CurrentEntry = CurrentEntry->Flink;
}
return NULL;
LeaveCriticalSection(&CatalogLock);
return NULL;
}
PCATALOG_ENTRY LocateProviderById(
DWORD CatalogEntryId)
{
PLIST_ENTRY CurrentEntry;
PCATALOG_ENTRY Provider;
UINT i;
PLIST_ENTRY CurrentEntry;
PCATALOG_ENTRY Provider;
UINT i;
WS_DbgPrint(MAX_TRACE, ("CatalogEntryId (%d).\n", CatalogEntryId));
WS_DbgPrint(MAX_TRACE, ("CatalogEntryId (%d).\n", CatalogEntryId));
//EnterCriticalSection(&CatalogLock);
CurrentEntry = CatalogListHead.Flink;
while (CurrentEntry != &CatalogListHead) {
Provider = CONTAINING_RECORD(CurrentEntry,
CATALOG_ENTRY,
ListEntry);
//EnterCriticalSection(&CatalogLock);
CurrentEntry = CatalogListHead.Flink;
while (CurrentEntry != &CatalogListHead) {
Provider = CONTAINING_RECORD(CurrentEntry,
CATALOG_ENTRY,
ListEntry);
if (Provider->ProtocolInfo.dwCatalogEntryId == CatalogEntryId) {
//LeaveCriticalSection(&CatalogLock);
WS_DbgPrint(MID_TRACE, ("Returning provider at (0x%X) Name (%s).\n",
Provider, Provider->LibraryName));
return Provider;
}
CurrentEntry = CurrentEntry->Flink;
if (Provider->ProtocolInfo.dwCatalogEntryId == CatalogEntryId) {
//LeaveCriticalSection(&CatalogLock);
WS_DbgPrint(MID_TRACE, ("Returning provider at (0x%X) Name (%s).\n",
Provider, Provider->LibraryName));
return Provider;
}
//LeaveCriticalSection(&CatalogLock);
CurrentEntry = CurrentEntry->Flink;
}
//LeaveCriticalSection(&CatalogLock);
WS_DbgPrint(MID_TRACE, ("Provider was not found.\n"));
return NULL;
return NULL;
}
@ -191,133 +183,114 @@ INT LoadProvider(
PCATALOG_ENTRY Provider,
LPWSAPROTOCOL_INFOW lpProtocolInfo)
{
INT Status;
INT Status;
WS_DbgPrint(MAX_TRACE, ("Loading provider at (0x%X) Name (%S).\n",
Provider, Provider->LibraryName));
WS_DbgPrint(MAX_TRACE, ("Loading provider at (0x%X) Name (%S).\n",
Provider, Provider->LibraryName));
if (!Provider->hModule) {
CP
/* DLL is not loaded so load it now */
Provider->hModule = LoadLibrary(Provider->LibraryName);
if (!Provider->hModule) {
/* DLL is not loaded so load it now */
Provider->hModule = LoadLibrary(Provider->LibraryName);
CP
if (Provider->hModule) {
CP
Provider->WSPStartup = (LPWSPSTARTUP)GetProcAddress(Provider->hModule,
"WSPStartup");
CP
if (Provider->WSPStartup) {
WS_DbgPrint(MAX_TRACE, ("Calling WSPStartup at (0x%X).\n", Provider->WSPStartup));
Status = Provider->WSPStartup(MAKEWORD(2, 2),
&Provider->WSPData,
lpProtocolInfo,
UpcallTable,
&Provider->ProcTable);
CP
} else
Status = ERROR_BAD_PROVIDER;
} else
Status = ERROR_DLL_NOT_FOUND;
if (Provider->hModule) {
Provider->WSPStartup = (LPWSPSTARTUP)GetProcAddress(Provider->hModule,
"WSPStartup");
if (Provider->WSPStartup) {
WS_DbgPrint(MAX_TRACE, ("Calling WSPStartup at (0x%X).\n", Provider->WSPStartup));
Status = Provider->WSPStartup(MAKEWORD(2, 2),
&Provider->WSPData,
lpProtocolInfo,
UpcallTable,
&Provider->ProcTable);
} else
Status = ERROR_BAD_PROVIDER;
} else
Status = NO_ERROR;
Status = ERROR_DLL_NOT_FOUND;
} else
Status = NO_ERROR;
WS_DbgPrint(MAX_TRACE, ("Status (%d).\n", Status));
WS_DbgPrint(MAX_TRACE, ("Status (%d).\n", Status));
return Status;
return Status;
}
INT UnloadProvider(
PCATALOG_ENTRY Provider)
{
INT Status = NO_ERROR;
INT Status = NO_ERROR;
WS_DbgPrint(MAX_TRACE, ("Unloading provider at (0x%X)\n", Provider));
WS_DbgPrint(MAX_TRACE, ("Unloading provider at (0x%X)\n", Provider));
if (Provider->hModule) {
WS_DbgPrint(MAX_TRACE, ("Calling WSPCleanup at (0x%X).\n",
Provider->ProcTable.lpWSPCleanup));
Provider->ProcTable.lpWSPCleanup(&Status);
if (Provider->hModule) {
WS_DbgPrint(MAX_TRACE, ("Calling WSPCleanup at (0x%X).\n",
Provider->ProcTable.lpWSPCleanup));
Provider->ProcTable.lpWSPCleanup(&Status);
if (!FreeLibrary(Provider->hModule)) {
WS_DbgPrint(MIN_TRACE, ("Could not free library.\n"));
Status = GetLastError();
}
Provider->hModule = (HMODULE)INVALID_HANDLE_VALUE;
if (!FreeLibrary(Provider->hModule)) {
WS_DbgPrint(MIN_TRACE, ("Could not free library.\n"));
Status = GetLastError();
}
WS_DbgPrint(MAX_TRACE, ("Status (%d).\n", Status));
Provider->hModule = (HMODULE)INVALID_HANDLE_VALUE;
}
return Status;
WS_DbgPrint(MAX_TRACE, ("Status (%d).\n", Status));
return Status;
}
VOID CreateCatalog(VOID)
{
PCATALOG_ENTRY Provider;
PCATALOG_ENTRY Provider;
CP
InitializeCriticalSection(&CatalogLock);
// FIXME: Crash
//InitializeCriticalSection(&CatalogLock);
InitializeListHead(&CatalogListHead);
CP
InitializeListHead(&CatalogListHead);
CP
/* FIXME: Read service provider catalog from registry */
/* FIXME: Read service provider catalog from registry */
#if 1
Provider = CreateCatalogEntry(L"msafd.dll");
if (!Provider) {
WS_DbgPrint(MIN_TRACE, ("Could not create catalog entry.\n"));
return;
}
/* Assume one Service Provider with id 1 */
Provider->ProtocolInfo.dwCatalogEntryId = 1;
CP
/* Assume one Service Provider with id 1 */
Provider->ProtocolInfo.dwCatalogEntryId = 1;
CP
Provider->Mapping = HeapAlloc(GlobalHeap, 0, sizeof(WINSOCK_MAPPING) + 3 * sizeof(DWORD));
if (!Provider->Mapping) {
WS_DbgPrint(MIN_TRACE, ("Insufficient memory.\n"));
return;
Provider->Mapping = HeapAlloc(GlobalHeap, 0, sizeof(WINSOCK_MAPPING) + 3 * sizeof(DWORD));
if (!Provider->Mapping) {
WS_DbgPrint(MIN_TRACE, ("Insufficient memory.\n"));
return;
}
CP
Provider->Mapping->Rows = 1;
Provider->Mapping->Columns = 3;
Provider->Mapping->Mapping[0].AddressFamily = AF_INET;
Provider->Mapping->Mapping[0].SocketType = SOCK_RAW;
Provider->Mapping->Mapping[0].Protocol = 0;
CP
Provider->Mapping->Rows = 1;
Provider->Mapping->Columns = 3;
Provider->Mapping->Mapping[0].AddressFamily = AF_INET;
Provider->Mapping->Mapping[0].SocketType = SOCK_RAW;
Provider->Mapping->Mapping[0].Protocol = 0;
#endif
}
VOID DestroyCatalog(VOID)
{
PLIST_ENTRY CurrentEntry;
PLIST_ENTRY CurrentEntry;
PLIST_ENTRY NextEntry;
PCATALOG_ENTRY Provider;
PCATALOG_ENTRY Provider;
CurrentEntry = CatalogListHead.Flink;
while (CurrentEntry != &CatalogListHead) {
NextEntry = CurrentEntry->Flink;
Provider = CONTAINING_RECORD(CurrentEntry,
CATALOG_ENTRY,
ListEntry);
DestroyCatalogEntry(Provider);
CurrentEntry = NextEntry;
}
//DeleteCriticalSection(&CatalogLock);
CurrentEntry = CatalogListHead.Flink;
while (CurrentEntry != &CatalogListHead) {
NextEntry = CurrentEntry->Flink;
Provider = CONTAINING_RECORD(CurrentEntry,
CATALOG_ENTRY,
ListEntry);
DestroyCatalogEntry(Provider);
CurrentEntry = NextEntry;
}
//DeleteCriticalSection(&CatalogLock);
}
/* EOF */

View file

@ -15,7 +15,7 @@
#ifdef DBG
/* See debug.h for debug/trace constants */
DWORD DebugTraceLevel = MAX_TRACE;
DWORD DebugTraceLevel = MIN_TRACE;
#endif /* DBG */
@ -31,14 +31,14 @@ INT
EXPORT
WSAGetLastError(VOID)
{
PWINSOCK_THREAD_BLOCK p = NtCurrentTeb()->WinSockData;
PWINSOCK_THREAD_BLOCK p = NtCurrentTeb()->WinSockData;
if (p) {
return p->LastErrorValue;
} else {
/* FIXME: What error code should we use here? Can this even happen? */
return ERROR_BAD_ENVIRONMENT;
}
if (p) {
return p->LastErrorValue;
} else {
/* FIXME: What error code should we use here? Can this even happen? */
return ERROR_BAD_ENVIRONMENT;
}
}
@ -47,10 +47,10 @@ EXPORT
WSASetLastError(
IN INT iError)
{
PWINSOCK_THREAD_BLOCK p = NtCurrentTeb()->WinSockData;
PWINSOCK_THREAD_BLOCK p = NtCurrentTeb()->WinSockData;
if (p)
p->LastErrorValue = iError;
if (p)
p->LastErrorValue = iError;
}
@ -60,26 +60,19 @@ WSAStartup(
IN WORD wVersionRequested,
OUT LPWSADATA lpWSAData)
{
WS_DbgPrint(MAX_TRACE, ("WSAStartup of ws2_32.dll\n"));
WS_DbgPrint(MAX_TRACE, ("WSAStartup of ws2_32.dll\n"));
lpWSAData->wVersion = wVersionRequested;
lpWSAData->wHighVersion = 2;
CP
lstrcpyA(lpWSAData->szDescription, "WinSock 2.0");
CP
lstrcpyA(lpWSAData->szSystemStatus, "Running");
CP
lpWSAData->iMaxSockets = 0;
lpWSAData->iMaxUdpDg = 0;
lpWSAData->lpVendorInfo = NULL;
lpWSAData->wVersion = wVersionRequested;
lpWSAData->wHighVersion = 2;
lstrcpyA(lpWSAData->szDescription, "WinSock 2.0");
lstrcpyA(lpWSAData->szSystemStatus, "Running");
lpWSAData->iMaxSockets = 0;
lpWSAData->iMaxUdpDg = 0;
lpWSAData->lpVendorInfo = NULL;
CP
WSASETINITIALIZED;
WSASETINITIALIZED;
CP
return NO_ERROR;
return NO_ERROR;
}
@ -87,16 +80,14 @@ INT
EXPORT
WSACleanup(VOID)
{
WS_DbgPrint(MAX_TRACE, ("WSACleanup of ws2_32.dll\n"));
WS_DbgPrint(MAX_TRACE, ("WSACleanup of ws2_32.dll\n"));
if (!WSAINITIALIZED) {
CP
WSASetLastError(WSANOTINITIALISED);
return WSANOTINITIALISED;
}
if (!WSAINITIALIZED) {
WSASetLastError(WSANOTINITIALISED);
return WSANOTINITIALISED;
}
CP
return NO_ERROR;
return NO_ERROR;
}
@ -113,39 +104,33 @@ WSASocketA(
* FUNCTION: Creates a new socket
*/
{
WSAPROTOCOL_INFOW ProtocolInfoW;
LPWSAPROTOCOL_INFOW p;
UNICODE_STRING StringU;
ANSI_STRING StringA;
WSAPROTOCOL_INFOW ProtocolInfoW;
LPWSAPROTOCOL_INFOW p;
UNICODE_STRING StringU;
ANSI_STRING StringA;
WS_DbgPrint(MAX_TRACE, ("af (%d) type (%d) protocol (%d).\n",
af, type, protocol));
af, type, protocol));
if (lpProtocolInfo) {
CP
memcpy(&ProtocolInfoW,
lpProtocolInfo,
sizeof(WSAPROTOCOL_INFOA) -
sizeof(CHAR) * (WSAPROTOCOL_LEN + 1));
CP
RtlInitAnsiString(&StringA, (LPSTR)lpProtocolInfo->szProtocol);
CP
RtlInitUnicodeString(&StringU, (LPWSTR)&ProtocolInfoW.szProtocol);
CP
RtlAnsiStringToUnicodeString(&StringU, &StringA, FALSE);
CP
p = &ProtocolInfoW;
CP
} else {
p = NULL;
}
if (lpProtocolInfo) {
memcpy(&ProtocolInfoW,
lpProtocolInfo,
sizeof(WSAPROTOCOL_INFOA) -
sizeof(CHAR) * (WSAPROTOCOL_LEN + 1));
RtlInitAnsiString(&StringA, (LPSTR)lpProtocolInfo->szProtocol);
RtlInitUnicodeString(&StringU, (LPWSTR)&ProtocolInfoW.szProtocol);
RtlAnsiStringToUnicodeString(&StringU, &StringA, FALSE);
p = &ProtocolInfoW;
} else {
p = NULL;
}
return WSASocketW(af,
type,
protocol,
p,
g,
dwFlags);
return WSASocketW(af,
type,
protocol,
p,
g,
dwFlags);
}
@ -171,54 +156,57 @@ WSASocketW(
* Created socket descriptor, or INVALID_SOCKET if it could not be created
*/
{
INT Status;
SOCKET Socket;
PCATALOG_ENTRY Provider;
WSAPROTOCOL_INFOW ProtocolInfo;
INT Status;
SOCKET Socket;
PCATALOG_ENTRY Provider;
WSAPROTOCOL_INFOW ProtocolInfo;
WS_DbgPrint(MAX_TRACE, ("af (%d) type (%d) protocol (%d).\n",
af, type, protocol));
WS_DbgPrint(MAX_TRACE, ("af (%d) type (%d) protocol (%d).\n",
af, type, protocol));
if (!WSAINITIALIZED) {
WSASetLastError(WSANOTINITIALISED);
return INVALID_SOCKET;
}
if (!WSAINITIALIZED) {
WSASetLastError(WSANOTINITIALISED);
return INVALID_SOCKET;
}
if (!lpProtocolInfo) {
lpProtocolInfo = &ProtocolInfo;
ZeroMemory(&ProtocolInfo, sizeof(WSAPROTOCOL_INFOW));
if (!lpProtocolInfo) {
lpProtocolInfo = &ProtocolInfo;
ZeroMemory(&ProtocolInfo, sizeof(WSAPROTOCOL_INFOW));
ProtocolInfo.iAddressFamily = af;
ProtocolInfo.iSocketType = type;
ProtocolInfo.iProtocol = protocol;
}
ProtocolInfo.iAddressFamily = af;
ProtocolInfo.iSocketType = type;
ProtocolInfo.iProtocol = protocol;
}
Provider = LocateProvider(lpProtocolInfo);
if (!Provider) {
WSASetLastError(WSAEAFNOSUPPORT);
return INVALID_SOCKET;
}
Provider = LocateProvider(lpProtocolInfo);
if (!Provider) {
WSASetLastError(WSAEAFNOSUPPORT);
return INVALID_SOCKET;
}
Status = LoadProvider(Provider, lpProtocolInfo);
Status = LoadProvider(Provider, lpProtocolInfo);
if (Status != NO_ERROR) {
WSASetLastError(Status);
return INVALID_SOCKET;
}
if (Status != NO_ERROR) {
WSASetLastError(Status);
return INVALID_SOCKET;
}
Socket = Provider->ProcTable.lpWSPSocket(af,
type,
protocol,
lpProtocolInfo,
g,
dwFlags,
&Status);
if (Status != NO_ERROR) {
WSASetLastError(Status);
return INVALID_SOCKET;
}
WS_DbgPrint(MAX_TRACE, ("Calling WSPSocket at (0x%X).\n", Provider->ProcTable.lpWSPSocket));
return Socket;
Socket = Provider->ProcTable.lpWSPSocket(af,
type,
protocol,
lpProtocolInfo,
g,
dwFlags,
&Status);
if (Status != NO_ERROR) {
WSASetLastError(Status);
return INVALID_SOCKET;
}
return Socket;
}
@ -234,31 +222,31 @@ closesocket(
* 0, or SOCKET_ERROR if an error ocurred
*/
{
PCATALOG_ENTRY Provider;
INT Errno;
INT Code;
PCATALOG_ENTRY Provider;
INT Errno;
INT Code;
WS_DbgPrint(MAX_TRACE, ("s (0x%X).\n", s));
WS_DbgPrint(MAX_TRACE, ("s (0x%X).\n", s));
if (!WSAINITIALIZED) {
WSASetLastError(WSANOTINITIALISED);
return SOCKET_ERROR;
}
if (!WSAINITIALIZED) {
WSASetLastError(WSANOTINITIALISED);
return SOCKET_ERROR;
}
if (!ReferenceProviderByHandle((HANDLE)s, &Provider)) {
WSASetLastError(WSAENOTSOCK);
return SOCKET_ERROR;
}
if (!ReferenceProviderByHandle((HANDLE)s, &Provider)) {
WSASetLastError(WSAENOTSOCK);
return SOCKET_ERROR;
}
CloseProviderHandle((HANDLE)s);
CloseProviderHandle((HANDLE)s);
DereferenceProviderByPointer(Provider);
DereferenceProviderByPointer(Provider);
Code = Provider->ProcTable.lpWSPCloseSocket(s, &Errno);
if (Code == SOCKET_ERROR)
WSASetLastError(Errno);
Code = Provider->ProcTable.lpWSPCloseSocket(s, &Errno);
if (Code == SOCKET_ERROR)
WSASetLastError(Errno);
return 0;
return 0;
}
@ -283,52 +271,55 @@ select(
* Number of ready socket descriptors, or SOCKET_ERROR if an error ocurred
*/
{
PCATALOG_ENTRY Provider;
INT Count;
INT Errno;
ULONG i;
PCATALOG_ENTRY Provider;
INT Count;
INT Errno;
ULONG i;
WS_DbgPrint(MAX_TRACE, ("readfds (0x%X) writefds (0x%X) exceptfds (0x%X).\n",
readfds, writefds, exceptfds));
WS_DbgPrint(MAX_TRACE, ("readfds (0x%X) writefds (0x%X) exceptfds (0x%X).\n",
readfds, writefds, exceptfds));
if (!WSAINITIALIZED) {
WSASetLastError(WSANOTINITIALISED);
return SOCKET_ERROR;
if (!WSAINITIALIZED) {
WSASetLastError(WSANOTINITIALISED);
return SOCKET_ERROR;
}
/* FIXME: Sockets in FD_SETs should be sorted by their provider */
/* FIXME: For now, assume only one service provider */
if ((readfds != NULL) && (readfds->fd_count > 0)) {
if (!ReferenceProviderByHandle((HANDLE)readfds->fd_array[0], &Provider)) {
WSASetLastError(WSAENOTSOCK);
return SOCKET_ERROR;
}
/* FIXME: Sockets in FD_SETs should be sorted by their provider */
/* FIXME: For now, assume only one service provider */
if ((readfds != NULL) && (readfds->fd_count > 0)) {
if (!ReferenceProviderByHandle((HANDLE)readfds->fd_array[0], &Provider)) {
WSASetLastError(WSAENOTSOCK);
return SOCKET_ERROR;
}
} else if ((writefds != NULL) && (writefds->fd_count > 0)) {
if (!ReferenceProviderByHandle((HANDLE)writefds->fd_array[0], &Provider)) {
WSASetLastError(WSAENOTSOCK);
return SOCKET_ERROR;
}
} else if ((exceptfds != NULL) && (exceptfds->fd_count > 0)) {
if (!ReferenceProviderByHandle((HANDLE)exceptfds->fd_array[0], &Provider)) {
WSASetLastError(WSAENOTSOCK);
return SOCKET_ERROR;
}
} else {
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
} else if ((writefds != NULL) && (writefds->fd_count > 0)) {
if (!ReferenceProviderByHandle((HANDLE)writefds->fd_array[0], &Provider)) {
WSASetLastError(WSAENOTSOCK);
return SOCKET_ERROR;
}
} else if ((exceptfds != NULL) && (exceptfds->fd_count > 0)) {
if (!ReferenceProviderByHandle((HANDLE)exceptfds->fd_array[0], &Provider)) {
WSASetLastError(WSAENOTSOCK);
return SOCKET_ERROR;
}
} else {
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
}
Count = Provider->ProcTable.lpWSPSelect(nfds, readfds, writefds, exceptfds, timeout, &Errno);
Count = Provider->ProcTable.lpWSPSelect(
nfds, readfds, writefds, exceptfds, timeout, &Errno);
DereferenceProviderByPointer(Provider);
WS_DbgPrint(MAX_TRACE, ("Provider (0x%X).\n", Provider));
WSASetLastError(Errno);
DereferenceProviderByPointer(Provider);
if (Errno != NO_ERROR)
return SOCKET_ERROR;
WSASetLastError(Errno);
return Count;
if (Errno != NO_ERROR)
return SOCKET_ERROR;
return Count;
}
@ -338,29 +329,23 @@ DllMain(HANDLE hInstDll,
ULONG dwReason,
LPVOID lpReserved)
{
WS_DbgPrint(MAX_TRACE, ("DllMain of ws2_32.dll.\n"));
PWINSOCK_THREAD_BLOCK p;
CP
WS_DbgPrint(MAX_TRACE, ("DllMain of ws2_32.dll.\n"));
switch (dwReason) {
case DLL_PROCESS_ATTACH: {
CP
GlobalHeap = GetProcessHeap();
//GlobalHeap = HeapCreate(0, 0, 0);
if (!GlobalHeap) {
WS_DbgPrint(MIN_TRACE, ("Insufficient memory.\n"));
switch (dwReason) {
case DLL_PROCESS_ATTACH:
GlobalHeap = GetProcessHeap();
//GlobalHeap = HeapCreate(0, 0, 0);
if (!GlobalHeap) {
WS_DbgPrint(MIN_TRACE, ("Insufficient memory.\n"));
return FALSE;
}
CP
CreateCatalog();
CreateCatalog();
InitProviderHandleTable();
CP
InitProviderHandleTable();
CP
/* FIXME: Causes trap
UpcallTable.lpWPUCloseEvent = WPUCloseEvent;
UpcallTable.lpWPUCloseSocketHandle = WPUCloseSocketHandle;
@ -377,64 +362,46 @@ DllMain(HANDLE hInstDll,
UpcallTable.lpWPUSetEvent = WPUSetEvent;
UpcallTable.lpWPUOpenCurrentThread = WPUOpenCurrentThread;
UpcallTable.lpWPUCloseThread = WPUCloseThread;*/
/* Fall through to thread attachment handler */
case DLL_THREAD_ATTACH:
p = HeapAlloc(GlobalHeap, 0, sizeof(WINSOCK_THREAD_BLOCK));
WS_DbgPrint(MAX_TRACE, ("Thread block at 0x%X.\n", p));
if (!p) {
WS_DbgPrint(MIN_TRACE, ("Insufficient memory.\n"));
return FALSE;
}
case DLL_THREAD_ATTACH: {
PWINSOCK_THREAD_BLOCK p;
p->LastErrorValue = NO_ERROR;
p->Initialized = FALSE;
CP
NtCurrentTeb()->WinSockData = p;
break;
p = HeapAlloc(GlobalHeap, 0, sizeof(WINSOCK_THREAD_BLOCK));
CP
if (!p) {
WS_DbgPrint(MIN_TRACE, ("Insufficient memory.\n"));
return FALSE;
}
case DLL_PROCESS_DETACH:
p = NtCurrentTeb()->WinSockData;
CP
p->LastErrorValue = NO_ERROR;
p->Initialized = FALSE;
CP
if (p)
HeapFree(GlobalHeap, 0, p);
NtCurrentTeb()->WinSockData = p;
DestroyCatalog();
break;
}
FreeProviderHandleTable();
case DLL_PROCESS_DETACH: {
CP
//HeapDestroy(GlobalHeap);
break;
HeapFree(GlobalHeap, 0, NtCurrentTeb()->WinSockData);
case DLL_THREAD_DETACH:
p = NtCurrentTeb()->WinSockData;
DestroyCatalog();
if (p)
HeapFree(GlobalHeap, 0, p);
break;
}
CP
FreeProviderHandleTable();
CP
//HeapDestroy(GlobalHeap);
break;
}
case DLL_THREAD_DETACH: {
PWINSOCK_THREAD_BLOCK p = NtCurrentTeb()->WinSockData;
CP
if (p)
HeapFree(GlobalHeap, 0, p);
break;
}
}
CP
return TRUE;
return TRUE;
}
/* EOF */

View file

@ -261,7 +261,10 @@ InitProviderHandleTable(VOID)
return FALSE;
}
WS_DbgPrint(MIN_TRACE, ("ProviderHandleTable at 0x%X.\n", ProviderHandleTable));
ZeroMemory(ProviderHandleTable, sizeof(PROVIDER_HANDLE_BLOCK));
InitializeListHead(&ProviderHandleTable->Entry);
//InitializeCriticalSection(&ProviderHandleTableLock);

View file

@ -371,8 +371,6 @@ inet_addr(
PCHAR p;
ULONG u = 0;
/* FIXME: Little endian version only */
p = (PCHAR)cp;
if (strlen(p) == 0)
@ -381,7 +379,7 @@ inet_addr(
if (strcmp(p, " ") == 0)
return 0;
for (i = 3; i >= 0; i--) {
for (i = 0; i <= 3; i++) {
u += (strtoul(p, &p, 0) << (i * 8));
if (strlen(p) == 0)
@ -406,11 +404,11 @@ inet_ntoa(
PCHAR p;
p = ((PWINSOCK_THREAD_BLOCK)NtCurrentTeb()->WinSockData)->Intoa;
_itoa(in.S_un.S_addr >> 24, b, 10);
_itoa((in.S_un.S_addr >> 24) & 0xFF, b, 10);
strcpy(p, b);
_itoa(in.S_un.S_addr >> 16, b, 10);
_itoa((in.S_un.S_addr >> 16) & 0xFF, b, 10);
strcat(p, b);
_itoa(in.S_un.S_addr >> 8, b, 10);
_itoa((in.S_un.S_addr >> 8) & 0xFF, b, 10);
strcat(p, b);
_itoa(in.S_un.S_addr & 0xFF, b, 10);
strcat(p, b);