Bump to version 2.0.22
[platform/upstream/acpid.git] / libnetlink.h
1 #ifndef __LIBNETLINK_H__
2 #define __LIBNETLINK_H__ 1
3
4 #include <asm/types.h>
5 /* needed by netlink.h, should be in there */
6 #include <arpa/inet.h>
7 #include <linux/netlink.h>
8 #include <linux/rtnetlink.h>
9
10 struct rtnl_handle
11 {
12         int                     fd;
13         struct sockaddr_nl      local;
14         struct sockaddr_nl      peer;
15         __u32                   seq;
16         __u32                   dump;
17 };
18
19 extern int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions);
20 extern int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int protocol);
21 extern void rtnl_close(struct rtnl_handle *rth);
22 extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type);
23 extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len);
24
25 typedef int (*rtnl_filter_t)(const struct sockaddr_nl *,
26                              struct nlmsghdr *n, void *);
27 extern int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter,
28                             void *arg1,
29                             rtnl_filter_t junk,
30                             void *arg2);
31 extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
32                      unsigned groups, struct nlmsghdr *answer,
33                      rtnl_filter_t junk,
34                      void *jarg);
35 extern int rtnl_send(struct rtnl_handle *rth, const char *buf, int);
36
37
38 extern int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data);
39 extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen);
40 extern int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len);
41 extern int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data);
42 extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, const void *data, int alen);
43
44 extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len);
45 extern int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len);
46
47 #define parse_rtattr_nested(tb, max, rta) \
48         (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
49
50 extern int rtnl_listen(struct rtnl_handle *, rtnl_filter_t handler,
51                        void *jarg);
52 extern int rtnl_from_file(FILE *, rtnl_filter_t handler,
53                        void *jarg);
54
55 #define NLMSG_TAIL(nmsg) \
56         ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
57
58 #ifndef IFA_RTA
59 #define IFA_RTA(r) \
60         ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
61 #endif
62 #ifndef IFA_PAYLOAD
63 #define IFA_PAYLOAD(n)  NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
64 #endif
65
66 #ifndef IFLA_RTA
67 #define IFLA_RTA(r) \
68         ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
69 #endif
70 #ifndef IFLA_PAYLOAD
71 #define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
72 #endif
73
74 #ifndef NDA_RTA
75 #define NDA_RTA(r) \
76         ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
77 #endif
78 #ifndef NDA_PAYLOAD
79 #define NDA_PAYLOAD(n)  NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
80 #endif
81
82 #ifndef NDTA_RTA
83 #define NDTA_RTA(r) \
84         ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndtmsg))))
85 #endif
86 #ifndef NDTA_PAYLOAD
87 #define NDTA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndtmsg))
88 #endif
89
90 #endif /* __LIBNETLINK_H__ */
91