This commit was generated by cvs2svn to compensate for changes in r786,
[libnl.git] / include / netlink / msg.h
1 /*
2  * netlink/msg.c                Netlink Messages Interface
3  *
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
7  *      of the License.
8  *
9  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10  */
11
12 #ifndef NETLINK_MSG_H_
13 #define NETLINK_MSG_H_
14
15 #include <netlink/netlink.h>
16 #include <netlink/object.h>
17 #include <netlink/attr.h>
18
19 struct nl_msg;
20 struct nl_tree;
21 struct ucred;
22
23 /* size calculations */
24 extern int                nlmsg_msg_size(int);
25 extern int                nlmsg_total_size(int);
26 extern int                nlmsg_padlen(int);
27
28 /* payload access */
29 extern void *             nlmsg_data(const struct nlmsghdr *);
30 extern int                nlmsg_len(const struct nlmsghdr *);
31 extern void *             nlmsg_tail(const struct nlmsghdr *);
32
33 /* attribute access */
34 extern struct nlattr *    nlmsg_attrdata(const struct nlmsghdr *, int);
35 extern int                nlmsg_attrlen(const struct nlmsghdr *, int);
36
37 /* message parsing */
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,
44                                          struct nla_policy *);
45
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);
52
53 extern struct nlmsghdr *  nlmsg_hdr(struct nl_msg *);
54 extern void               nlmsg_free(struct nl_msg *);
55
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 *);
65
66 extern char *             nl_nlmsgtype2str(int, char *, size_t);
67 extern int                nl_str2nlmsgtype(const char *);
68
69 extern char *             nl_nlmsg_flags2str(int, char *, size_t);
70
71 extern int                nl_msg_parse(struct nl_msg *,
72                                        void (*cb)(struct nl_object *, void *),
73                                        void *);
74
75 /**
76  * @name Iterators
77  * @{
78  */
79
80 /**
81  * @ingroup msg
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
87  */
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)
91
92 /**
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
98  */
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)))
103
104 /** @} */
105
106 #endif