0
import os
import socket
import struct

...

s = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, socket.NETLINK_ROUTE)
s.bind((os.getpid(), RTMGRP_IPV4_IFADDR))

while True:
   data = s.recv(65535)
   msg_len, msg_type, flags, seq, pid = struct.unpack("=LHHLL", data[:16])

   ...

   # dump data in hex

I would like to print the first 64 bytes of the data, print data returns garbage, I think this is because data needs to be unpacked?

I also tried ' '.join(str(x) for x in s[:len(s)]) but it doesn't help either. What would be the right way to dump data read from netlink socket?

Mark
  • 6,052
  • 8
  • 61
  • 129

0 Answers0