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 rtnl_ctrl_data *,
35                           struct nlmsghdr *n, void *),
36                  void *jarg)
37
38       int rtnl_from_file(FILE *rtnl,
39                  int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
40                  void *jarg)
41
42       int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)
43
44       int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen)
45
46       int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data)
47
48       int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen)
49

DESCRIPTION

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

BUGS

132       This library is meant for internal use, use libmnl for new programs.
133
134       The functions sometimes use fprintf and exit when a fatal error occurs.
135       This library should be named librtnetlink.
136
137

AUTHORS

139       netlink/rtnetlink was designed and written by Alexey  Kuznetsov.   Andi
140       Kleen wrote the man page.
141
142

SEE ALSO

144       netlink(7), rtnetlink(7)
145       /usr/include/linux/rtnetlink.h
146
147
148
149                                                                 libnetlink(3)
Impressum