47
47
48
48
#include "windivert.h"
49
49
50
- #define MAXBUF 400000
51
- #define MAXBATCH 0xFF
52
-
50
+ #define MTU 1500
53
51
static int batch = 1 ;
54
52
55
53
static DWORD passthru (LPVOID arg );
@@ -78,7 +76,7 @@ int __cdecl main(int argc, char **argv)
78
76
{
79
77
batch = atoi (argv [3 ]);
80
78
}
81
- if (batch <= 0 || batch > MAXBATCH )
79
+ if (batch <= 0 || batch > WINDIVERT_BATCH_MAX )
82
80
{
83
81
fprintf (stderr , "error: invalid batch size\n" );
84
82
exit (EXIT_FAILURE );
@@ -110,7 +108,7 @@ int __cdecl main(int argc, char **argv)
110
108
(LPVOID )handle , 0 , NULL );
111
109
if (thread == NULL )
112
110
{
113
- fprintf (stderr , "error: failed to start passthru thread (%u )\n" ,
111
+ fprintf (stderr , "error: failed to start passthru thread (%d )\n" ,
114
112
GetLastError ());
115
113
exit (EXIT_FAILURE );
116
114
}
@@ -125,17 +123,27 @@ int __cdecl main(int argc, char **argv)
125
123
// Passthru thread.
126
124
static DWORD passthru (LPVOID arg )
127
125
{
128
- UINT8 packet [ MAXBUF ] ;
126
+ UINT8 * packet ;
129
127
UINT packet_len , addr_len ;
130
- WINDIVERT_ADDRESS addr [ MAXBATCH ] ;
128
+ WINDIVERT_ADDRESS * addr ;
131
129
HANDLE handle = (HANDLE )arg ;
132
130
131
+ packet = (UINT8 * )malloc (batch * MTU );
132
+ addr = (WINDIVERT_ADDRESS * )malloc (batch * sizeof (WINDIVERT_ADDRESS ));
133
+ if (packet == NULL || addr == NULL )
134
+ {
135
+ fprintf (stderr , "error: failed to allocate buffer (%d)\n" ,
136
+ GetLastError ());
137
+ exit (EXIT_FAILURE );
138
+ }
139
+
133
140
// Main loop:
134
141
while (TRUE)
135
142
{
136
143
// Read a matching packet.
137
- addr_len = batch * sizeof (WINDIVERT_ADDRESS );
138
- if (!WinDivertRecvEx (handle , packet , sizeof (packet ), & packet_len , 0 ,
144
+ packet_len = batch * MTU ;
145
+ addr_len = batch * sizeof (WINDIVERT_ADDRESS );
146
+ if (!WinDivertRecvEx (handle , packet , packet_len , & packet_len , 0 ,
139
147
addr , & addr_len , NULL ))
140
148
{
141
149
fprintf (stderr , "warning: failed to read packet (%d)\n" ,
0 commit comments