@@ -119,10 +119,11 @@ def capture_event(ctx: c_void_p) -> c_int64:
119119 # Set fields
120120 event.timestamp = ktime()
121121 event.pid = pid()
122- event.comm = comm()
122+ # Note: comm() requires a buffer parameter to fill
123+ # comm(event.comm) # Fills event.comm with process name
123124
124125 # Use the struct
125- print (f " Process { event.comm } with PID { event.pid} " )
126+ print (f " Process with PID { event.pid} " )
126127
127128 return c_int64(0 )
128129```
@@ -204,7 +205,8 @@ def trace_fork(ctx: c_void_p) -> c_int64:
204205 event = ProcessEvent()
205206 event.timestamp = ktime()
206207 event.pid = pid()
207- event.comm = comm()
208+ # Note: comm() requires a buffer parameter
209+ # comm(event.comm) # Fills event.comm with process name
208210
209211 # Send to userspace
210212 events.output(event)
@@ -265,7 +267,8 @@ Assign values to fields:
265267event = Event()
266268event.timestamp = ktime()
267269event.pid = pid()
268- event.comm = comm()
270+ # Note: comm() requires a buffer parameter
271+ # comm(event.comm) # Fills event.comm with process name
269272```
270273
271274### String Fields
@@ -285,8 +288,8 @@ def example(ctx: c_void_p) -> c_int64:
285288 # Assign string value
286289 msg.text = " Hello from BPF"
287290
288- # Use helper to get process name
289- msg.text = comm()
291+ # Use helper to get process name (requires buffer)
292+ # comm( msg.text) # Fills msg.text with process name
290293
291294 return c_int64(0 )
292295```
@@ -316,6 +319,7 @@ class MyStruct:
316319``` python
317320from pythonbpf import bpf, struct, map , section
318321from pythonbpf.maps import RingBuffer
322+ from pythonbpf.helper import ktime, XDP_PASS
319323from ctypes import c_void_p, c_int64, c_uint8, c_uint16, c_uint32, c_uint64
320324
321325@bpf
@@ -336,15 +340,15 @@ def packets() -> RingBuffer:
336340
337341@bpf
338342@section (" xdp" )
339- def capture_packets (ctx : c_void_p) -> c_uint32 :
343+ def capture_packets (ctx : c_void_p) -> c_int64 :
340344 pkt = PacketEvent()
341345 pkt.timestamp = ktime()
342346 # Parse packet data from ctx...
343347
344348 packets.output(pkt)
345349
346350 # XDP_PASS
347- return c_uint32( 2 )
351+ return XDP_PASS
348352```
349353
350354### Process Lifecycle Tracking
@@ -377,7 +381,8 @@ def track_fork(ctx: c_void_p) -> c_int64:
377381 info = ProcessLifecycle()
378382 info.pid = process_id
379383 info.start_time = ktime()
380- info.comm = comm()
384+ # Note: comm() requires a buffer parameter
385+ # comm(info.comm) # Fills info.comm with process name
381386
382387 process_info.update(process_id, info)
383388
0 commit comments