{
    "mode": "man",
    "parameter": "libnetlink",
    "section": "3",
    "url": "https://www.chedong.com/phpMan.php/man/libnetlink/3/json",
    "generated": "2026-10-07T16:06:26Z",
    "synopsis": "#include <asm/types.h>\n#include <libnetlink.h>\n#include <linux/netlink.h>\n#include <linux/rtnetlink.h>\nint rtnlopen(struct rtnlhandle *rth, unsigned subscriptions)\nint rtnlwilddumprequest(struct rtnlhandle *rth, int family, int type)\nint rtnlsend(struct rtnlhandle *rth, char *buf, int len)\nint rtnldumprequest(struct rtnlhandle *rth, int type, void *req, int len)\nint rtnldumpfilter(struct rtnlhandle *rth,\nint (*filter)(struct sockaddrnl *, struct nlmsghdr *n, void *),\nvoid *arg1,\nint (*junk)(struct sockaddrnl *,struct nlmsghdr *n, void *),\nvoid *arg2)\nint rtnltalk(struct rtnlhandle *rtnl, struct nlmsghdr *n, pidt peer,\nunsigned groups, struct nlmsghdr *answer,\nint (*junk)(struct sockaddrnl *,struct nlmsghdr *n, void *),\nvoid *jarg)\nint rtnllisten(struct rtnlhandle *rtnl,\nint (*handler)(struct sockaddrnl *, struct rtnlctrldata *,\nstruct nlmsghdr *n, void *),\nvoid *jarg)\nint rtnlfromfile(FILE *rtnl,\nint (*handler)(struct sockaddrnl *,struct nlmsghdr *n, void *),\nvoid *jarg)\nint addattr32(struct nlmsghdr *n, int maxlen, int type, u32 data)\nint addattrl(struct nlmsghdr *n, int maxlen, int type, void *data, int alen)\nint rtaaddattr32(struct rtattr *rta, int maxlen, int type, u32 data)\nint rtaaddattrl(struct rtattr *rta, int maxlen, int type, void *data, int alen)",
    "sections": {
        "NAME": {
            "content": "libnetlink - A library for accessing the netlink service\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "#include <asm/types.h>\n#include <libnetlink.h>\n#include <linux/netlink.h>\n#include <linux/rtnetlink.h>\n\nint rtnlopen(struct rtnlhandle *rth, unsigned subscriptions)\n\nint rtnlwilddumprequest(struct rtnlhandle *rth, int family, int type)\n\nint rtnlsend(struct rtnlhandle *rth, char *buf, int len)\n\nint rtnldumprequest(struct rtnlhandle *rth, int type, void *req, int len)\n\nint rtnldumpfilter(struct rtnlhandle *rth,\nint (*filter)(struct sockaddrnl *, struct nlmsghdr *n, void *),\nvoid *arg1,\nint (*junk)(struct sockaddrnl *,struct nlmsghdr *n, void *),\nvoid *arg2)\n\nint rtnltalk(struct rtnlhandle *rtnl, struct nlmsghdr *n, pidt peer,\nunsigned groups, struct nlmsghdr *answer,\nint (*junk)(struct sockaddrnl *,struct nlmsghdr *n, void *),\nvoid *jarg)\n\nint rtnllisten(struct rtnlhandle *rtnl,\nint (*handler)(struct sockaddrnl *, struct rtnlctrldata *,\nstruct nlmsghdr *n, void *),\nvoid *jarg)\n\nint rtnlfromfile(FILE *rtnl,\nint (*handler)(struct sockaddrnl *,struct nlmsghdr *n, void *),\nvoid *jarg)\n\nint addattr32(struct nlmsghdr *n, int maxlen, int type, u32 data)\n\nint addattrl(struct nlmsghdr *n, int maxlen, int type, void *data, int alen)\n\nint rtaaddattr32(struct rtattr *rta, int maxlen, int type, u32 data)\n\nint rtaaddattrl(struct rtattr *rta, int maxlen, int type, void *data, int alen)\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "libnetlink provides a higher level interface to rtnetlink(7).  The read functions return 0 on\nsuccess  and a negative errno on failure.  The send functions return the amount of data sent,\nor -1 on error.\n\nrtnlopen\nOpen a rtnetlink socket and save the state into the rth handle. This handle is  passed\nto  all subsequent calls.  subscriptions is a bitmap of the rtnetlink multicast groups\nthe socket will be a member of.\n\n\nrtnlwilddumprequest\nRequest a full dump of the type database for family addresses.  type  is  a  rtnetlink\nmessage type.\n\n\nrtnldumprequest\nRequest a full dump of the type data buffer into buf with maximum length of len.  type\nis a rtnetlink message type.\n\n\nrtnldumpfilter\nReceive netlink data after a request and filter it.  The filter callback checks if the\nreceived message is wanted. It gets the source address of the message, the message it‐\nself and arg1 as arguments. 0 as return means that the filter passed, a negative value\nis  returned  by rtnldumpfilter in case of error. NULL for filter means to not use a\nfilter.  junk is used to filter messages not destined to the local socket.   Only  one\nmessage  bundle  is  received.  If  there is a message pending, this function does not\nblock.\n\n\nrtnllisten\nReceive netlink data after a request and pass it to handler.  handler  is  a  callback\nthat  gets  the  message  source address, anscillary data, the message itself, and the\njarg cookie as arguments. It will get called for all received messages.  Only one mes‐\nsage bundle is received. If there is a message pending this function does not block.\n\n\nrtnlfromfile\nWorks like rtnllisten, but reads a netlink message bundle  from  the  file  file  and\npasses  the  messages  to handler for parsing. The file should contain raw data as re‐\nceived from a rtnetlink socket.\n\nThe following functions are useful to construct custom rtnetlink messages. For  simple  data‐\nbase  dumping  with  filtering  it is better to use the higher level functions above. See rt‐\nnetlink(3) and netlink(3) on how to generate a rtnetlink message. The following utility func‐\ntions require a continuous buffer that already contains a netlink message header  and  a  rt‐\nnetlink request.\n\n\nrtnlsend\nSend the rtnetlink message in buf of length len to handle rth.\n\n\naddattr32\nAdd  a u32 attribute of type type and with value data to netlink message n, which is\npart of a buffer of length maxlen.\n\n\naddattrl\nAdd a variable length attribute of type type and with value data and  alen  length  to\nnetlink message n, which is part of a buffer of length maxlen.  data is copied.\n\n\nrtaaddattr32\nInitialize the rtnetlink attribute rta with a u32 data value.\n\n\nrtaaddattr32\nInitialize the rtnetlink attribute rta with a variable length data value.\n\n",
            "subsections": []
        },
        "BUGS": {
            "content": "This library is meant for internal use, use libmnl for new programs.\n\nThe  functions sometimes use fprintf and exit when a fatal error occurs.  This library should\nbe named librtnetlink.\n\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "netlink/rtnetlink was designed and written by Alexey Kuznetsov.  Andi  Kleen  wrote  the  man\npage.\n\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "netlink(7), rtnetlink(7)\n/usr/include/linux/rtnetlink.h\n\nlibnetlink(3)",
            "subsections": []
        }
    },
    "summary": "libnetlink - A library for accessing the netlink service",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "netlink",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/netlink/7/json"
        },
        {
            "name": "rtnetlink",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/rtnetlink/7/json"
        }
    ]
}