--- pcap.pyx.orig	2023-04-01 11:07:48
+++ pcap.pyx	2023-04-01 11:21:06
@@ -20,7 +20,8 @@
 import struct
 
 cdef extern from "Python.h":
-    object PyBuffer_FromMemory(char *s, int len)
+    int PyBUF_WRITE
+    object PyMemoryView_FromMemory(char *mem, Py_ssize_t size, int flags)
     int    PyObject_AsCharBuffer(object obj, char **buffer, int *buffer_len)
     int    PyGILState_Ensure()
     void   PyGILState_Release(int gil)
@@ -104,7 +105,7 @@
     gil = PyGILState_Ensure()
     try:
         (<object>ctx.callback)(hdr.ts.tv_sec + (hdr.ts.tv_usec/1000000.0),
-                               PyBuffer_FromMemory(pktmem, hdr.caplen),
+                               PyMemoryView_FromMemory(pktmem, hdr.caplen, PyBUF_WRITE),
                                *(<object>ctx.args))
     except:
         ctx.got_exc = 1
@@ -142,7 +143,7 @@
     cdef bpf_program fcode
     def __init__(self, char *filter, dlt=DLT_RAW):
         if pcap_ex_compile_nopcap(65535, dlt, &self.fcode, filter, 1, 0) < 0:
-            raise IOError, 'bad filter'
+            raise IOError('bad filter')
     def filter(self, buf):
         """Return boolean match for buf against our filter."""
         cdef char *p
@@ -184,7 +185,7 @@
         if not name:
             p = pcap_ex_lookupdev(self.__ebuf)
             if p == NULL:
-                raise OSError, self.__ebuf
+                raise OSError(self.__ebuf)
         else:
             p = name
             
@@ -193,14 +194,14 @@
             self.__pcap = pcap_open_live(pcap_ex_name(p), snaplen, promisc,
                                          timeout_ms, self.__ebuf)
         if not self.__pcap:
-            raise OSError, self.__ebuf
+            raise OSError(self.__ebuf)
         
         self.__name = strdup(p)
         self.__filter = strdup("")
         try: self.__dloff = dltoff[pcap_datalink(self.__pcap)]
         except KeyError: pass
         if immediate and pcap_ex_immediate(self.__pcap) < 0:
-            raise OSError, "couldn't enable immediate mode"
+            raise OSError("couldn't enable immediate mode")
     
     property name:
         """Network interface or dumpfile name."""
@@ -237,9 +238,9 @@
         free(self.__filter)
         self.__filter = strdup(value)
         if pcap_compile(self.__pcap, &fcode, self.__filter, optimize, 0) < 0:
-            raise OSError, pcap_geterr(self.__pcap)
+            raise OSError(pcap_geterr(self.__pcap))
         if pcap_setfilter(self.__pcap, &fcode) < 0:
-            raise OSError, pcap_geterr(self.__pcap)
+            raise OSError(pcap_geterr(self.__pcap))
         pcap_freecode(&fcode)
 
     def setnonblock(self, nonblock=True):
@@ -250,7 +251,7 @@
         """Return non-blocking capture mode as boolean."""
         ret = pcap_ex_getnonblock(self.__pcap, self.__ebuf)
         if ret < 0:
-            raise OSError, self.__ebuf
+            raise OSError(self.__ebuf)
         elif ret:
             return True
         return False
@@ -291,7 +292,9 @@
                           <unsigned char *>&ctx)
         if ctx.got_exc:
             exc = sys.exc_info()
-            raise exc[0], exc[1], exc[2]
+            e = exc[0](exc[1])
+            e.__traceback__ = exc[2]
+            raise e
         return n
 
     def loop(self, cnt, callback, *args):
@@ -318,7 +321,7 @@
                 n = pcap_ex_next(self.__pcap, &hdr, &pkt)
             if n == 1:
                 callback(hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0),
-                         PyBuffer_FromMemory(pkt, hdr.caplen), *args)
+                         PyMemoryView_FromMemory(pkt, hdr.caplen, PyBUF_WRITE), *args)
             elif n == 0:
                 break
             elif n == -1:
@@ -333,7 +336,7 @@
         """Send a raw network packet on the interface."""
         ret = pcap_sendpacket(self.__pcap, buf, len(buf))
         if ret == -1:
-            raise OSError, pcap_geterr(self.__pcap)
+            raise OSError(pcap_geterr(self.__pcap))
         return len(buf)
     
     def geterr(self):
@@ -345,7 +348,7 @@
         dropped, and dropped by the interface."""
         cdef pcap_stat pstat
         if pcap_stats(self.__pcap, &pstat) < 0:
-            raise OSError, pcap_geterr(self.__pcap)
+            raise OSError(pcap_geterr(self.__pcap))
         return (pstat.ps_recv, pstat.ps_drop, pstat.ps_ifdrop)
 
     def __iter__(self):
@@ -361,7 +364,7 @@
                 n = pcap_ex_next(self.__pcap, &hdr, &pkt)
             if n == 1:
                 return (hdr.ts.tv_sec + (hdr.ts.tv_usec / 1000000.0),
-                        PyBuffer_FromMemory(pkt, hdr.caplen))
+                        PyMemoryView_FromMemory(pkt, hdr.caplen, PyBUF_WRITE))
             elif n == 0:
                 return None
             elif n == -1:
@@ -385,7 +388,7 @@
     cdef char *p, ebuf[256]
     p = pcap_ex_lookupdev(ebuf)
     if p == NULL:
-        raise OSError, ebuf
+        raise OSError(ebuf)
     return p
 
 def findalldevs():
