1libnetlink(3)              Library Functions Manual              libnetlink(3)
2
3
4

NAME

6       libnetlink - A library for accessing the netlink service
7

SYNOPSIS

9       #include <asm/types.h>
10       #include <libnetlink.h>
11       #include <linux/netlink.h>
12       #include <linux/rtnetlink.h>
13
14       int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
15
16       int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
17
18       int rtnl_send(struct rtnl_handle *rth, char *buf, int len)
19
20       int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
21
22       int rtnl_dump_filter(struct rtnl_handle *rth,
23                      int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
24                      void *arg1,
25                      int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
26                      void *arg2)
27
28       int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
29                  unsigned groups, struct nlmsghdr *answer,
30                  int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
31                  void *jarg)
32
33       int rtnl_listen(struct rtnl_handle *rtnl,
34                  int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
35                  void *jarg)
36
37       int rtnl_from_file(FILE *rtnl,
38                  int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
39                  void *jarg)
40
41       int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)
42
43       int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen)
44
45       int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data)
46
47       int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen)
48

DESCRIPTION

50       libnetlink provides a higher level interface to rtnetlink(7).  The read
51       functions return 0 on success and a negative  errno  on  failure.   The
52       send functions return the amount of data sent, or -1 on error.
53
54       rtnl_open
55              Open  a rtnetlink socket and save the state into the rth handle.
56              This handle is passed to all subsequent calls.  subscriptions is
57              a  bitmap of the rtnetlink multicast groups the socket will be a
58              member of.
59
60
61       rtnl_wilddump_request
62              Request a full dump of the type database for  family  addresses.
63              type is a rtnetlink message type.
64
65
66       rtnl_dump_request
67              Request  a full dump of the type data buffer into buf with maxi‐
68              mum length of len.  type is a rtnetlink message type.
69
70
71       rtnl_dump_filter
72              Receive netlink data after a request and filter it.  The  filter
73              callback  checks  if the received message is wanted. It gets the
74              source address of the message, the message itself  and  arg1  as
75              arguments.  0 as return means that the filter passed, a negative
76              value is returned by rtnl_dump_filter in case of error. NULL for
77              filter  means  to not use a filter.  junk is used to filter mes‐
78              sages not destined to the local socket.  Only one message bundle
79              is  received.  Unless there is no message pending, this function
80              does not block.
81
82
83       rtnl_listen
84              Receive netlink data after a request and  pass  it  to  handler.
85              handler  is a callback that gets the message source address, the
86              message itself, and the jarg cookie as arguments.  It  will  get
87              called  for  all  received messages.  Only one message bundle is
88              received. Unless there is no message pending this function  does
89              not block.
90
91
92       rtnl_from_file
93              Works  like rtnl_listen, but reads a netlink message bundle from
94              the file file and passes the messages to  handler  for  parsing.
95              The file contains raw data as received from a rtnetlink socket.
96
97       The  following  functions are useful to construct custom rtnetlink mes‐
98       sages. For simple database dumping with filtering it is better  to  use
99       the  higher  level  functions above. See rtnetlink(3) and netlink(3) on
100       how to generate a rtnetlink message. The  following  utility  functions
101       require  a  continuous  buffer  that already contains a netlink message
102       header and a rtnetlink request.
103
104
105       rtnl_send
106              Send the rtnetlink message in buf of length len to handle rth.
107
108
109       addattr32
110              Add a __u32 attribute of  type  type  and  with  value  data  to
111              netlink message n, which is part of a buffer of length maxlen.
112
113
114       addattr_l
115              Add a variable length attribute of type type and with value data
116              and alen length to netlink message n, which is part of a  buffer
117              of length maxlen.  data is copied.
118
119
120       rta_addattr32
121              Initialize the rtnetlink attribute rta with a __u32 data value.
122
123
124       rta_addattr32
125              Initialize  the  rtnetlink  attribute rta with a variable length
126              data value.
127
128

BUGS

130       The functions sometimes use fprintf and exit when a fatal error occurs.
131       This library should be named librtnetlink.
132
133

AUTHORS

135       netlink/rtnetlink  was  designed and written by Alexey Kuznetsov.  Andi
136       Kleen wrote the man page.
137
138

SEE ALSO

140       netlink(7), rtnetlink(7)
141       /usr/include/linux/rtnetlink.h
142
143
144
145                                                                 libnetlink(3)
Impressum