#else
#include <ddk/ntddk.h>
#include <net/ndis.h>
+#define NdisReinitializePacket(Packet) \
+{ \
+ (Packet)->Private.Head = (PNDIS_BUFFER)NULL; \
+ (Packet)->Private.ValidCounts = FALSE; \
+}
+
#endif
#include "debug.h"
//-------------------------------------------------------------------
+
NTSTATUS
-//STDCALL
NPF_Write(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
UINT i;
NDIS_STATUS Status;
-
- IF_LOUD(DbgPrint("Packet: SendAdapter\n");)
+ IF_LOUD(DbgPrint("NPF_Write\n");)
IrpSp = IoGetCurrentIrpStackLocation(Irp);
Open=IrpSp->FileObject->FsContext;
- // Check the length of the packet to avoid to use an empty packet
- if(IrpSp->Parameters.Write.Length==0)
+ IF_LOUD(DbgPrint("Max frame size = %d\n", Open->MaxFrameSize);)
+
+
+ if(IrpSp->Parameters.Write.Length == 0 || // Check that the buffer provided by the user is not empty
+ Open->MaxFrameSize == 0 || // Check that the MaxFrameSize is correctly initialized
+ IrpSp->Parameters.Write.Length > Open->MaxFrameSize) // Check that the fame size is smaller that the MTU
{
+ IF_LOUD(DbgPrint("frame size out of range, send aborted\n");)
+
Irp->IoStatus.Status = NDIS_STATUS_SUCCESS;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return NDIS_STATUS_SUCCESS;
return 0;
}
+ // Check that the MaxFrameSize is correctly initialized
+ if(Open->MaxFrameSize == 0)
+ {
+ IF_LOUD(DbgPrint("BufferedWrite: Open->MaxFrameSize not initialized, probably because of a problem in the OID query\n");)
+
+ return 0;
+ }
+
+
// Start from the first packet
winpcap_hdr = (struct sf_pkthdr*)UserBuff;
// Main loop: send the buffer to the wire
while( TRUE ){
- if(winpcap_hdr->caplen ==0 || winpcap_hdr->caplen > 65536)
+ if(winpcap_hdr->caplen ==0 || winpcap_hdr->caplen > Open->MaxFrameSize)
{
// Malformed header
- IF_LOUD(DbgPrint("NPF_BufferedWrite: malformed user buffer, aborting write.\n");)
+ IF_LOUD(DbgPrint("NPF_BufferedWrite: malformed or bogus user buffer, aborting write.\n");)
return -1;
}
if( Sync ){
-#if 0
// Release the application if it has been blocked for approximately more than 1 seconds
if( winpcap_hdr->ts.tv_sec - BufStartTime.tv_sec > 1 )
{
return (PCHAR)winpcap_hdr - UserBuff;
}
+#ifndef __GNUC__
// Calculate the time interval to wait before sending the next packet
- TargetTicks.QuadPart = StartTicks.QuadPart +
+ TargetTicks.QuadPart = StartTicks.QuadPart +
(LONGLONG)((winpcap_hdr->ts.tv_sec - BufStartTime.tv_sec) * 1000000 +
winpcap_hdr->ts.tv_usec - BufStartTime.tv_usec) *
(TimeFreq.QuadPart) / 1000000;
-
+
// Wait until the time interval has elapsed
while( CurTicks.QuadPart <= TargetTicks.QuadPart )
CurTicks = KeQueryPerformanceCounter(NULL);
+#else
#endif
-
}
}
return;
}
+
+
+#ifdef __GNUC__
+/*
+__divdi3()
+{
+ //_alldiv();
+}
+
+//_allmul();
+//_allrem();
+
+*/
+#endif