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 rtnl_ctrl_data *,
37 struct nlmsghdr *n, void *),
40 int rtnl_from_file(FILE *rtnl,
41 int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
44 int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)
46 int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen)
48 int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data)
50 int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen)
52 libnetlink provides a higher level interface to
54 The read functions return 0 on success and a negative errno on failure.
55 The send functions return the amount of data sent, or -1 on error.
58 Open a rtnetlink socket and save the state into the
60 handle. This handle is passed to all subsequent calls.
62 is a bitmap of the rtnetlink multicast groups the socket will be
67 Request a full dump of the
73 is a rtnetlink message type.
78 Request a full dump of the
82 with maximum length of
85 is a rtnetlink message type.
89 Receive netlink data after a request and filter it.
92 callback checks if the received message is wanted. It gets the source
93 address of the message, the message itself and
95 as arguments. 0 as return means that the filter passed, a negative
99 in case of error. NULL for
101 means to not use a filter.
103 is used to filter messages not destined to the local socket.
104 Only one message bundle is received. If there is a message
105 pending, this function does not block.
109 Receive netlink data after a request and pass it to
112 is a callback that gets the message source address, anscillary data, the message
115 cookie as arguments. It will get called for all received messages.
116 Only one message bundle is received. If there is a message
117 pending this function does not block.
123 but reads a netlink message bundle from the file
125 and passes the messages to
127 for parsing. The file should contain raw data as received from a rtnetlink socket.
129 The following functions are useful to construct custom rtnetlink messages. For
130 simple database dumping with filtering it is better to use the higher level
135 on how to generate a rtnetlink message. The following utility functions
136 require a continuous buffer that already contains a netlink message header
137 and a rtnetlink request.
141 Send the rtnetlink message in
150 Add a __u32 attribute of type
156 which is part of a buffer of length
161 Add a variable length attribute of type
167 length to netlink message
169 which is part of a buffer of length
176 Initialize the rtnetlink attribute
178 with a __u32 data value.
182 Initialize the rtnetlink attribute
184 with a variable length data value.
187 This library is meant for internal use, use libmnl for new programs.
189 The functions sometimes use fprintf and exit when a fatal error occurs.
190 This library should be named librtnetlink.
193 netlink/rtnetlink was designed and written by Alexey Kuznetsov.
194 Andi Kleen wrote the man page.
200 /usr/include/linux/rtnetlink.h