2 * netlink/msg.c Netlink Messages Interface
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
12 #ifndef NETLINK_MSG_H_
13 #define NETLINK_MSG_H_
15 #include <netlink/netlink.h>
16 #include <netlink/object.h>
17 #include <netlink/attr.h>
23 /* size calculations */
24 extern int nlmsg_msg_size(int);
25 extern int nlmsg_total_size(int);
26 extern int nlmsg_padlen(int);
29 extern void * nlmsg_data(const struct nlmsghdr *);
30 extern int nlmsg_len(const struct nlmsghdr *);
31 extern void * nlmsg_tail(const struct nlmsghdr *);
33 /* attribute access */
34 extern struct nlattr * nlmsg_attrdata(const struct nlmsghdr *, int);
35 extern int nlmsg_attrlen(const struct nlmsghdr *, int);
38 extern int nlmsg_ok(const struct nlmsghdr *, int);
39 extern struct nlmsghdr * nlmsg_next(struct nlmsghdr *, int *);
40 extern int nlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
41 int, struct nla_policy *);
42 extern struct nlattr * nlmsg_find_attr(struct nlmsghdr *, int, int);
43 extern int nlmsg_validate(struct nlmsghdr *, int, int,
46 extern struct nl_msg * nlmsg_new(void);
47 extern struct nl_msg * nlmsg_build(struct nlmsghdr *);
48 extern struct nl_msg * nlmsg_build_simple(int, int);
49 extern struct nl_msg * nlmsg_build_no_hdr(void);
50 extern struct nl_msg * nlmsg_convert(struct nlmsghdr *);
51 extern int nlmsg_append(struct nl_msg *, void *, size_t, int);
53 extern struct nlmsghdr * nlmsg_hdr(struct nl_msg *);
54 extern void nlmsg_free(struct nl_msg *);
56 /* attribute modification */
57 extern void nlmsg_set_proto(struct nl_msg *, int);
58 extern int nlmsg_get_proto(struct nl_msg *);
59 extern void nlmsg_set_src(struct nl_msg *, struct sockaddr_nl *);
60 extern struct sockaddr_nl *nlmsg_get_src(struct nl_msg *);
61 extern void nlmsg_set_dst(struct nl_msg *, struct sockaddr_nl *);
62 extern struct sockaddr_nl *nlmsg_get_dst(struct nl_msg *);
63 extern void nlmsg_set_creds(struct nl_msg *, struct ucred *);
64 extern struct ucred * nlmsg_get_creds(struct nl_msg *);
66 extern char * nl_nlmsgtype2str(int, char *, size_t);
67 extern int nl_str2nlmsgtype(const char *);
69 extern char * nl_nlmsg_flags2str(int, char *, size_t);
71 extern int nl_msg_parse(struct nl_msg *,
72 void (*cb)(struct nl_object *, void *),
82 * Iterate over a stream of attributes in a message
83 * @arg pos loop counter, set to current attribute
84 * @arg nlh netlink message header
85 * @arg hdrlen length of family header
86 * @arg rem initialized to len, holds bytes currently remaining in stream
88 #define nlmsg_for_each_attr(pos, nlh, hdrlen, rem) \
89 nla_for_each_attr(pos, nlmsg_attrdata(nlh, hdrlen), \
90 nlmsg_attrlen(nlh, hdrlen), rem)
93 * Iterate over a stream of messages
94 * @arg pos loop counter, set to current message
95 * @arg head head of message stream
96 * @arg len length of message stream
97 * @arg rem initialized to len, holds bytes currently remaining in stream
99 #define nlmsg_for_each_msg(pos, head, len, rem) \
100 for (pos = head, rem = len; \
101 nlmsg_ok(pos, rem); \
102 pos = nlmsg_next(pos, &(rem)))