Revisted the packet capture driver and updated with fixes in latest 3.0a4 release.
[reactos.git] / reactos / drivers / net / packet / write.c
index f12818f..0db9e01 100644 (file)
 #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"
@@ -34,8 +40,8 @@
 
 
 //-------------------------------------------------------------------
+
 NTSTATUS
-//STDCALL
 NPF_Write(
     IN PDEVICE_OBJECT DeviceObject,
     IN PIRP Irp
@@ -48,17 +54,22 @@ NPF_Write(
        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;
@@ -159,6 +170,15 @@ NPF_BufferedWrite(
                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;
        
@@ -181,10 +201,10 @@ NPF_BufferedWrite(
        // 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;
                }
@@ -247,7 +267,6 @@ NPF_BufferedWrite(
                
                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 )
                        {
@@ -256,17 +275,18 @@ NPF_BufferedWrite(
                                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
-
                }
                
        }
@@ -330,3 +350,17 @@ NPF_SendComplete(
 
        return;
 }
+
+
+#ifdef __GNUC__
+/*
+__divdi3()
+{
+    //_alldiv();
+}
+
+//_allmul();
+//_allrem();
+
+*/
+#endif