Seth Woolley's Man Viewer

libnetlink(3) - libnetlink - A library for accessing the netlink service - man 3 libnetlink

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

libnetlink(3)                                                    libnetlink(3)



NAME
       libnetlink - A library for accessing the netlink(3,7) service

SYNOPSIS
       #include <asm/types.h>
       #include <libnetlink.h>
       #include <linux/netlink.h>
       #include <linux/rtnetlink.h>

       int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)

       int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)

       int rtnl_send(struct rtnl_handle *rth, char *buf, int len)

       int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)

       int rtnl_dump_filter(struct rtnl_handle *rth,
                      int (*filter(1,3x,3x curs_util))(struct sockaddr_nl *, struct nlmsghdr *n, void *),
                      void *arg1,
                      int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
                      void *arg2)

       int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
                  unsigned groups, struct nlmsghdr *answer,
                  int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
                  void *jarg)

       int rtnl_listen(struct rtnl_handle *rtnl,
                  int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
                  void *jarg)

       int rtnl_from_file(FILE *rtnl,
                  int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
                  void *jarg)

       int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)

       int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen)

       int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data)

       int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen)

DESCRIPTION
       libnetlink provides a higher level interface to rtnetlink(3,7)(7).  The read(2,n,1 builtins)
       functions return 0 on success and a negative  errno  on  failure.   The
       send(2,n) functions return the amount of data sent, or -1 on error.

       rtnl_open
              Open  a rtnetlink(3,7) socket(2,7,n) and save the state into the rth handle.
              This handle is passed to all subsequent calls.  subscriptions is
              a  bitmap of the rtnetlink(3,7) multicast groups the socket(2,7,n) will be a
              member of.


       rtnl_wilddump_request
              Request a full dump of the type database for  family  addresses.
              type is a rtnetlink(3,7) message type.


       rtnl_dump_request
              Request  a full dump of the type data buffer into buf with maxi-
              mum length of len.  type is a rtnetlink(3,7) message type.


       rtnl_dump_filter
              Receive netlink(3,7) data after a request and filter(1,3x,3x curs_util) it.  The  filter(1,3x,3x curs_util)
              callback  checks  if(3,n) the received message is wanted. It gets(3,n) the
              source address of the message, the message itself  and  arg1  as
              arguments.  0 as return means that the filter(1,3x,3x curs_util) passed, a negative
              value is returned by rtnl_dump_filter in(1,8) case of error. NULL for
              filter(1,3x,3x curs_util)  means  to not use a filter.  junk is used to filter(1,3x,3x curs_util) mes-
              sages not destined to the local socket.  Only one message bundle
              is  received.  Unless there is no message pending, this function
              does not block.


       rtnl_listen
              Receive netlink(3,7) data after a request and  pass  it  to  handler.
              handler  is a callback that gets(3,n) the message source address, the
              message itself, and the jarg cookie as arguments.  It  will  get
              called  for  all  received messages.  Only one message bundle is
              received. Unless there is no message pending this function  does
              not block.


       rtnl_from_file
              Works  like rtnl_listen, but reads a netlink(3,7) message bundle from
              the file(1,n) file(1,n) and passes the messages to  handler  for  parsing.
              The  file(1,n) contains raw(3x,7,8,3x cbreak) data as received from a rtnetlink(3,7) socket.

       The following functions are useful to construct custom  rtnetlink(3,7)  mes-
       sages.  For  simple database dumping with filtering it is better to use
       the higher level functions above. See rtnetlink(3,7)(3)  and  netlink(3,7)(3)  on
       how  to  generate  a rtnetlink(3,7) message. The following utility functions
       require a continuous buffer that already  contains  a  netlink(3,7)  message
       header and a rtnetlink(3,7) request.


       rtnl_send
              Send the rtnetlink(3,7) message in(1,8) buf of length len to handle rth.


       addattr32
              Add  a  __u32  attribute  of  type  type  and with value data to
              netlink(3,7) message n, which is part of a buffer of length maxlen.


       addattr_l
              Add a variable length attribute of type type and with value data
              and  alen length to netlink(3,7) message n, which is part of a buffer
              of length maxlen.  data is copied.


       rta_addattr32
              Initialize the rtnetlink(3,7) attribute rta with a __u32 data  value.


       rta_addattr32
              Initialize  the  rtnetlink(3,7)  attribute rta with a variable length
              data value.


BUGS
       The functions sometimes use fprintf and exit(3,n,1 builtins) when a fatal error(8,n) occurs.
       This library should be named(5,8) librtnetlink.


AUTHORS
       netlink(3,7)/rtnetlink(3,7)  was  designed  and writen by Alexey Kuznetsov.  Andi
       Kleen wrote the man(1,5,7) page.


SEE ALSO
       netlink(3,7)(7), rtnetlink(3,7)(7)
       /usr/include/linux/rtnetlink.h



                                                                 libnetlink(3)

References for this manual (incoming links)