Skip to content

Commit

Permalink
Fix PCAPReader (#4)
Browse files Browse the repository at this point in the history
Fixing #4 
* Change file_name to filename (ValueError: PCAPReader)
* Use Cython for conversion PyBytes as *char (string)
* Add Cython missing dep
* Update version 24.10.1
  • Loading branch information
gwenblum authored Oct 18, 2024
1 parent 8423142 commit c9f6bae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
CHANGELOG
---------

[24.10.1]
* Add python dependency in setup.py (Cython)
* Bugfix in pcap.py (pcap_info, PCAPREADER)

[1.1.1]
* Minor fixes for doc updates

Expand All @@ -14,4 +18,3 @@ CHANGELOG
[1.0]

* Initial commit

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
install_requires = (
'steelscript>=24.2.0',
'tzlocal',
'Cython'
)


Expand All @@ -36,7 +37,7 @@

setup_args = {
'name': 'steelscript.packets',
'version': '24.2.1',
'version': '24.10.1',
'author': 'Riverbed Technology',
'author_email': 'eng-github@riverbed.com',
'url': 'http://pythonhosted.org/steelscript',
Expand Down
15 changes: 11 additions & 4 deletions steelscript/packets/core/pcap.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from libc.stdlib cimport malloc, free
from libc.stdint cimport uint32_t, uint64_t, uint16_t

from cpython.bytes cimport PyBytes_AsString

import time
import socket
import struct
Expand Down Expand Up @@ -457,10 +459,15 @@ cdef class PCAPReader(PCAPBase):

fname_srt = kwargs.get('filename', '')
fname_bytes = fname_srt.encode()
fname_p = fname_bytes
self.filename = fname_p

# Convert bytes object to char *
fname_p = PyBytes_AsString(fname_bytes)

# Store the bytes object
self.filename = fname_bytes

self.have_dumper = 0
self.reader = open_offline(self.filename, errors)
self.reader = open_offline(fname_p, errors)

if self.reader is NULL:
v_err = ValueError("PCAPReader failed to open {0} for reading. "
Expand Down Expand Up @@ -570,7 +577,7 @@ cpdef dict pcap_info(str filename):
double first_ts
dict rval

rdr = PCAPReader(file_name=filename)
rdr = PCAPReader(filename=filename)
ts, hdr, pkt = next(rdr)
first_ts = ts
pkts = 1
Expand Down

0 comments on commit c9f6bae

Please sign in to comment.