@@ -1647,7 +1647,7 @@ class RawPcapNgReader(RawPcapReader):
1647
1647
PacketMetadata = collections .namedtuple ("PacketMetadataNg" , # type: ignore
1648
1648
["linktype" , "tsresol" ,
1649
1649
"tshigh" , "tslow" , "wirelen" ,
1650
- "comment" , "ifname" , "direction" ,
1650
+ "comment" , "ifname" , "intid" , " direction" ,
1651
1651
"process_information" ])
1652
1652
1653
1653
def __init__ (self , filename , fdesc = None , magic = None ): # type: ignore
@@ -1656,6 +1656,7 @@ def __init__(self, filename, fdesc=None, magic=None): # type: ignore
1656
1656
self .f = fdesc
1657
1657
# A list of (linktype, snaplen, tsresol); will be populated by IDBs.
1658
1658
self .interfaces = [] # type: List[Tuple[int, int, Dict[str, Any]]]
1659
+ self .interface_names = []
1659
1660
self .default_options = {
1660
1661
"tsresol" : 1000000
1661
1662
}
@@ -1781,7 +1782,7 @@ def _read_block_shb(self):
1781
1782
def _read_packet (self , size = MTU ): # type: ignore
1782
1783
# type: (int) -> Tuple[bytes, RawPcapNgReader.PacketMetadata]
1783
1784
"""Read blocks until it reaches either EOF or a packet, and
1784
- returns None or (packet, (linktype, sec, usec, wirelen)),
1785
+ returns None or (packet, (linktype, sec, usec, wirelen, intid )),
1785
1786
where packet is a string.
1786
1787
1787
1788
"""
@@ -1860,6 +1861,7 @@ def _read_block_epb(self, block, size):
1860
1861
self .endian + "5I" ,
1861
1862
block [:20 ],
1862
1863
)
1864
+ ifname = self .interface_names [intid ] if intid < len (self .interface_names ) else None
1863
1865
except struct .error :
1864
1866
warning ("PcapNg: EPB is too small %d/20 !" % len (block ))
1865
1867
raise EOFError
@@ -1914,6 +1916,7 @@ def _read_block_epb(self, block, size):
1914
1916
wirelen = wirelen ,
1915
1917
comment = comment ,
1916
1918
ifname = ifname ,
1919
+ intid = intid ,
1917
1920
direction = direction ,
1918
1921
process_information = process_information ))
1919
1922
@@ -1952,6 +1955,7 @@ def _read_block_pkt(self, block, size):
1952
1955
self .endian + "HH4I" ,
1953
1956
block [:20 ],
1954
1957
)
1958
+ ifname = self .interface_names [intid ] if intid < len (self .interface_names ) else None
1955
1959
except struct .error :
1956
1960
warning ("PcapNg: PKT is too small %d/20 !" % len (block ))
1957
1961
raise EOFError
@@ -2067,7 +2071,7 @@ def read_packet(self, size=MTU, **kwargs):
2067
2071
rp = super (PcapNgReader , self )._read_packet (size = size )
2068
2072
if rp is None :
2069
2073
raise EOFError
2070
- s , (linktype , tsresol , tshigh , tslow , wirelen , comment , ifname , direction , process_information ) = rp # noqa: E501
2074
+ s , (linktype , tsresol , tshigh , tslow , wirelen , comment , ifname , intid , direction , process_information ) = rp # noqa: E501
2071
2075
try :
2072
2076
cls = conf .l2types .num2layer [linktype ] # type: Type[Packet]
2073
2077
p = cls (s , ** kwargs ) # type: Packet
@@ -2088,6 +2092,7 @@ def read_packet(self, size=MTU, **kwargs):
2088
2092
p .process_information = process_information .copy ()
2089
2093
if ifname is not None :
2090
2094
p .sniffed_on = ifname .decode ('utf-8' , 'backslashreplace' )
2095
+ p .intid = intid
2091
2096
return p
2092
2097
2093
2098
def recv (self , size : int = MTU , ** kwargs : Any ) -> 'Packet' : # type: ignore
0 commit comments