Skip to content

Commit 68597ee

Browse files
committed
patch based on @TomFairbairn, check $eof after $fread
1 parent b112c80 commit 68597ee

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

pcap/pcapparser_1gb.v

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,24 @@ module PcapParser
8484
// fields of interest are U32 so bear in mind the byte ordering when assembling
8585
// multibyte fields
8686
r = $fread(packet_header, file);
87-
if (swapped == 1) begin
88-
pktSz = {packet_header[11],packet_header[10],packet_header[9] ,packet_header[8] };
89-
diskSz = {packet_header[15],packet_header[14],packet_header[13],packet_header[12]};
90-
end else begin
91-
pktSz = {packet_header[ 8],packet_header[ 9],packet_header[10],packet_header[11]};
92-
diskSz = {packet_header[12],packet_header[13],packet_header[14],packet_header[15]};
93-
end
87+
eof = $feof(file);
9488

95-
$display(" packet %0d: incl_length %0d orig_length %0d", pktcount, pktSz, diskSz );
89+
if ( eof == 0) begin
90+
if (swapped == 1) begin
91+
pktSz = {packet_header[11],packet_header[10],packet_header[9] ,packet_header[8] };
92+
diskSz = {packet_header[15],packet_header[14],packet_header[13],packet_header[12]};
93+
end else begin
94+
pktSz = {packet_header[ 8],packet_header[ 9],packet_header[10],packet_header[11]};
95+
diskSz = {packet_header[12],packet_header[13],packet_header[14],packet_header[15]};
96+
end
9697

97-
available <= 1;
98-
newpkt <= 1;
99-
pktcount <= pktcount + 1;
100-
countIPG <= ipg; // reload interpacket gap counter
98+
$display(" packet %0d: incl_length %0d orig_length %0d eof %0d", pktcount, pktSz, diskSz, eof );
10199

100+
available <= 1;
101+
newpkt <= 1;
102+
pktcount <= pktcount + 1;
103+
countIPG <= ipg; // reload interpacket gap counter
104+
end
102105
end else if ( diskSz > 0) begin
103106

104107
// packet content is byte-aligned, no swapping required

pcap/pcapparser_1gb_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module PcapParser_test;
3939
initial begin
4040

4141
$dumpfile("bin/pcap.lxt");
42-
$dumpvars(0,pcap);
42+
$dumpvars(0);
4343

4444
// Initialize Inputs
4545
$display("Reading from pcap");

0 commit comments

Comments
 (0)