Skip to content

Commit

Permalink
properly retrieve IP address from array for python2.7
Browse files Browse the repository at this point in the history
for python2.7 IP address(src_ip,dst_ip) conversion doesn't work
as expected and throws

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 315, in 'calling callback function'
  File "/usr/local/lib/python2.7/site-packages/bcc/table.py", line 526, in raw_cb_
    callback(cpu, data, size)
  File "./examples/networking/tc_perf_event.py", line 60, in print_skb_event
    (cpu, socket.inet_ntop(socket.AF_INET6, src_ip),
ValueError: invalid length of packed IP address string

IP string looks like
[254, 128, 0, 0, 0, 0, 0, 0, 156, 237, 12, 255, 254, 42, 90, 31]

Signed-off-by: Nirmoy Das <[email protected]>
  • Loading branch information
Nirmoy Das committed Mar 18, 2018
1 parent d6f716b commit 505f98d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/networking/tc_perf_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class SkbEvent(ct.Structure):

# Only print for echo request
if icmp_type == 128:
src_ip = bytes(skb_event.raw[22:38])
dst_ip = bytes(skb_event.raw[38:54])
src_ip = bytes(bytearray(skb_event.raw[22:38]))
dst_ip = bytes(bytearray(skb_event.raw[38:54]))
print("%-3s %-32s %-12s 0x%08x" %
(cpu, socket.inet_ntop(socket.AF_INET6, src_ip),
socket.inet_ntop(socket.AF_INET6, dst_ip),
Expand Down

0 comments on commit 505f98d

Please sign in to comment.