mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
Fixed UDP.
- Header size adjustments corrected. - Added callback specified by caller. - Port allocation added. svn path=/trunk/; revision=11659
This commit is contained in:
parent
9c5da940f0
commit
e280e1272c
1 changed files with 25 additions and 9 deletions
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
BOOLEAN UDPInitialized = FALSE;
|
BOOLEAN UDPInitialized = FALSE;
|
||||||
|
PORT_SET UDPPorts;
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS AddUDPHeaderIPv4(
|
NTSTATUS AddUDPHeaderIPv4(
|
||||||
|
@ -50,6 +51,7 @@ NTSTATUS AddUDPHeaderIPv4(
|
||||||
|
|
||||||
TI_DbgPrint(MAX_TRACE, ("Allocated %d bytes for headers at 0x%X.\n",
|
TI_DbgPrint(MAX_TRACE, ("Allocated %d bytes for headers at 0x%X.\n",
|
||||||
BufferSize, IPPacket->Header));
|
BufferSize, IPPacket->Header));
|
||||||
|
TI_DbgPrint(MAX_TRACE, ("Packet total length %d\n", IPPacket->TotalSize));
|
||||||
|
|
||||||
/* Build IPv4 header */
|
/* Build IPv4 header */
|
||||||
IPHeader = (PIPv4_HEADER)IPPacket->Header;
|
IPHeader = (PIPv4_HEADER)IPPacket->Header;
|
||||||
|
@ -82,7 +84,7 @@ NTSTATUS AddUDPHeaderIPv4(
|
||||||
/* FIXME: Calculate UDP checksum and put it in UDP header */
|
/* FIXME: Calculate UDP checksum and put it in UDP header */
|
||||||
UDPHeader->Checksum = 0;
|
UDPHeader->Checksum = 0;
|
||||||
/* Length of UDP header and data */
|
/* Length of UDP header and data */
|
||||||
UDPHeader->Length = WH2N(DataLength);
|
UDPHeader->Length = WH2N(DataLength + sizeof(UDP_HEADER));
|
||||||
|
|
||||||
IPPacket->Data = ((PCHAR)UDPHeader) + sizeof(UDP_HEADER);
|
IPPacket->Data = ((PCHAR)UDPHeader) + sizeof(UDP_HEADER);
|
||||||
|
|
||||||
|
@ -123,13 +125,12 @@ NTSTATUS BuildUDPPacket(
|
||||||
if (!Packet)
|
if (!Packet)
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
|
||||||
Packet->TotalSize =
|
Packet->TotalSize = sizeof(IPv4_HEADER) + sizeof(UDP_HEADER) + DataLen;
|
||||||
MaxLLHeaderSize + sizeof(IPv4_HEADER) + sizeof(UDP_HEADER) + DataLen;
|
|
||||||
|
|
||||||
/* Prepare packet */
|
/* Prepare packet */
|
||||||
Status = AllocatePacketWithBuffer( &Packet->NdisPacket,
|
Status = AllocatePacketWithBuffer( &Packet->NdisPacket,
|
||||||
NULL,
|
NULL,
|
||||||
Packet->TotalSize );
|
Packet->TotalSize + MaxLLHeaderSize );
|
||||||
|
|
||||||
TI_DbgPrint(MID_TRACE, ("Allocated packet: %x\n", Packet->NdisPacket));
|
TI_DbgPrint(MID_TRACE, ("Allocated packet: %x\n", Packet->NdisPacket));
|
||||||
TI_DbgPrint(MID_TRACE, ("Local Addr : %s\n", A2S(LocalAddress)));
|
TI_DbgPrint(MID_TRACE, ("Local Addr : %s\n", A2S(LocalAddress)));
|
||||||
|
@ -235,7 +236,6 @@ NTSTATUS UDPSendDatagram(
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS UDPReceiveDatagram(
|
NTSTATUS UDPReceiveDatagram(
|
||||||
PADDRESS_FILE AddrFile,
|
PADDRESS_FILE AddrFile,
|
||||||
PTDI_CONNECTION_INFORMATION ConnInfo,
|
PTDI_CONNECTION_INFORMATION ConnInfo,
|
||||||
|
@ -243,7 +243,9 @@ NTSTATUS UDPReceiveDatagram(
|
||||||
ULONG ReceiveLength,
|
ULONG ReceiveLength,
|
||||||
ULONG ReceiveFlags,
|
ULONG ReceiveFlags,
|
||||||
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
PTDI_CONNECTION_INFORMATION ReturnInfo,
|
||||||
PULONG BytesReceived)
|
PULONG BytesReceived,
|
||||||
|
PDATAGRAM_COMPLETION_ROUTINE Complete,
|
||||||
|
PVOID Context)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Attempts to receive an UDP datagram from a remote address
|
* FUNCTION: Attempts to receive an UDP datagram from a remote address
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -294,10 +296,9 @@ NTSTATUS UDPReceiveDatagram(
|
||||||
}
|
}
|
||||||
ReceiveRequest->ReturnInfo = ReturnInfo;
|
ReceiveRequest->ReturnInfo = ReturnInfo;
|
||||||
ReceiveRequest->Buffer = BufferData;
|
ReceiveRequest->Buffer = BufferData;
|
||||||
/* If ReceiveLength is 0, the whole buffer is available to us */
|
|
||||||
ReceiveRequest->BufferSize = ReceiveLength;
|
ReceiveRequest->BufferSize = ReceiveLength;
|
||||||
ReceiveRequest->Complete = NULL;
|
ReceiveRequest->Complete = Complete;
|
||||||
ReceiveRequest->Context = NULL;
|
ReceiveRequest->Context = Context;
|
||||||
|
|
||||||
/* Queue receive request */
|
/* Queue receive request */
|
||||||
InsertTailList(&AddrFile->ReceiveQueue, &ReceiveRequest->ListEntry);
|
InsertTailList(&AddrFile->ReceiveQueue, &ReceiveRequest->ListEntry);
|
||||||
|
@ -422,6 +423,8 @@ NTSTATUS UDPStartup(
|
||||||
RtlZeroMemory(&UDPStats, sizeof(UDP_STATISTICS));
|
RtlZeroMemory(&UDPStats, sizeof(UDP_STATISTICS));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
PortsStartup( &UDPPorts, UDP_STARTING_PORT, UDP_DYNAMIC_PORTS );
|
||||||
|
|
||||||
/* Register this protocol with IP layer */
|
/* Register this protocol with IP layer */
|
||||||
IPRegisterProtocol(IPPROTO_UDP, UDPReceive);
|
IPRegisterProtocol(IPPROTO_UDP, UDPReceive);
|
||||||
|
|
||||||
|
@ -442,10 +445,23 @@ NTSTATUS UDPShutdown(
|
||||||
if (!UDPInitialized)
|
if (!UDPInitialized)
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
|
|
||||||
|
PortsShutdown( &UDPPorts );
|
||||||
|
|
||||||
/* Deregister this protocol with IP layer */
|
/* Deregister this protocol with IP layer */
|
||||||
IPRegisterProtocol(IPPROTO_UDP, NULL);
|
IPRegisterProtocol(IPPROTO_UDP, NULL);
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UINT UDPAllocatePort( UINT HintPort ) {
|
||||||
|
if( HintPort ) {
|
||||||
|
if( AllocatePort( &UDPPorts, HintPort ) ) return HintPort;
|
||||||
|
else return (UINT)-1;
|
||||||
|
} else return AllocateAnyPort( &UDPPorts );
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID UDPFreePort( UINT Port ) {
|
||||||
|
DeallocatePort( &UDPPorts, Port );
|
||||||
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
Loading…
Reference in a new issue