3 libnetlink \- A library for accessing the netlink service
8 #include <libnetlink.h>
10 #include <linux/netlink.h>
12 #include <linux/rtnetlink.h>
14 int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
16 int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
18 int rtnl_send(struct rtnl_handle *rth, char *buf, int len)
20 int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
22 int rtnl_dump_filter(struct rtnl_handle *rth,
23 int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
25 int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
28 int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
29 unsigned groups, struct nlmsghdr *answer,
31 int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
35 int rtnl_listen(struct rtnl_handle *rtnl,
36 int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
39 int rtnl_from_file(FILE *rtnl,
40 int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
43 int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)
45 int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen)
47 int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data)
49 int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen)
51 libnetlink provides a higher level interface to
53 The read functions return 0 on success and a negative errno on failure.
54 The send functions return the amount of data sent, or -1 on error.
57 Open a rtnetlink socket and save the state into the
59 handle. This handle is passed to all subsequent calls.
61 is a bitmap of the rtnetlink multicast groups the socket will be
66 Request a full dump of the
72 is a rtnetlink message type.
77 Request a full dump of the
81 with maximum length of
84 is a rtnetlink message type.
88 Receive netlink data after a request and filter it.
91 callback checks if the received message is wanted. It gets the source
92 address of the message, the message itself and
94 as arguments. 0 as return means that the filter passed, a negative
98 in case of error. NULL for
100 means to not use a filter.
102 is used to filter messages not destined to the local socket.
103 Only one message bundle is received. Unless there is no message
104 pending, this function does not block.
108 Receive netlink data after a request and pass it to
111 is a callback that gets the message source address, the message itself,
114 cookie as arguments. It will get called for all received messages.
115 Only one message bundle is received. Unless there is no message
116 pending this function does not block.
122 but reads a netlink message bundle from the file
124 and passes the messages to
126 for parsing. The file contains raw data as received from a rtnetlink socket.
128 The following functions are useful to construct custom rtnetlink messages. For
129 simple database dumping with filtering it is better to use the higher level
134 on how to generate a rtnetlink message. The following utility functions
135 require a continuous buffer that already contains a netlink message header
136 and a rtnetlink request.
140 Send the rtnetlink message in
149 Add a __u32 attribute of type
155 which is part of a buffer of length
160 Add a variable length attribute of type
166 length to netlink message
168 which is part of a buffer of length
175 Initialize the rtnetlink attribute
177 with a __u32 data value.
181 Initialize the rtnetlink attribute
183 with a variable length data value.
186 The functions sometimes use fprintf and exit when a fatal error occurs.
187 This library should be named librtnetlink.
190 netlink/rtnetlink was designed and writen by Alexey Kuznetsov.
191 Andi Kleen wrote the man page.
197 /usr/include/linux/rtnetlink.h