netlink messages

martin f krafft madduck at
Mon Jun 11 12:35:48 CEST 2007

Dear list,

I am writing a daemon in Python that listens on AF_NETLINK and
processes RTM_NETLINK messages. FWIW, code is below since there is
hardly any reference on the net yet.

As you can see from the code, the NETLINK message is all binary/hex.
Before I go about wrapping it in a Python class, I was wondering
whether such a class already existed or if someone is already
working on this.

Please let me know if you are or have any hints, and please keep me
on CC.


Python 2.5.1 (r251:54863, Apr 25 2007, 22:53:30) 
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from socket import *
>>> from select import *
>>> from os import getpid
>>> s.bind((getpid(), RTMGRP_LINK))
>>> p = select((s,), (), (), 0)
>>> p
([], [], [])
>>> # connect device
>>> p = select((s,), (), (), 0)
>>> p
([<socket._socketobject object at 0xb7d9b374>], [], [])
>>> s2 = p[0][0]
>>> d = s2.recv(4096)
>>> d

martin;              (greetings from the heart of the sun.)
  \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net at madduck
spamtraps: madduck.bogus at
"men always want to be a woman's first love.
 women have a more subtle instinct:
 what they like is to be a man's last romance."
                                                        -- oscar wilde
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature (GPG/PGP)
URL: <>

More information about the Python-list mailing list