/build/buildd/libnl-1.0~pre6/include/netlink/msg.h

00001 /*
00002  * netlink/msg.c                Netlink Messages Interface
00003  *
00004  *      This library is free software; you can redistribute it and/or
00005  *      modify it under the terms of the GNU Lesser General Public
00006  *      License as published by the Free Software Foundation version 2.1
00007  *      of the License.
00008  *
00009  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
00010  */
00011 
00012 #ifndef NETLINK_MSG_H_
00013 #define NETLINK_MSG_H_
00014 
00015 #include <netlink/netlink.h>
00016 #include <netlink/object.h>
00017 #include <netlink/attr.h>
00018 
00019 struct nl_msg;
00020 struct nl_tree;
00021 struct ucred;
00022 
00023 /* size calculations */
00024 extern int                nlmsg_msg_size(int);
00025 extern int                nlmsg_total_size(int);
00026 extern int                nlmsg_padlen(int);
00027 
00028 /* payload access */
00029 extern void *             nlmsg_data(const struct nlmsghdr *);
00030 extern int                nlmsg_len(const struct nlmsghdr *);
00031 extern void *             nlmsg_tail(const struct nlmsghdr *);
00032 
00033 /* attribute access */
00034 extern struct nlattr *    nlmsg_attrdata(const struct nlmsghdr *, int);
00035 extern int                nlmsg_attrlen(const struct nlmsghdr *, int);
00036 
00037 /* message parsing */
00038 extern int                nlmsg_ok(const struct nlmsghdr *, int);
00039 extern struct nlmsghdr *  nlmsg_next(struct nlmsghdr *, int *);
00040 extern int                nlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
00041                                       int, struct nla_policy *);
00042 extern struct nlattr *    nlmsg_find_attr(struct nlmsghdr *, int, int);
00043 extern int                nlmsg_validate(struct nlmsghdr *, int, int,
00044                                          struct nla_policy *);
00045 
00046 extern struct nl_msg *    nlmsg_new(void);
00047 extern struct nl_msg *    nlmsg_build(struct nlmsghdr *);
00048 extern struct nl_msg *    nlmsg_build_simple(int, int);
00049 extern struct nl_msg *    nlmsg_build_no_hdr(void);
00050 extern struct nl_msg *    nlmsg_convert(struct nlmsghdr *);
00051 extern int                nlmsg_append(struct nl_msg *, void *, size_t, int);
00052 
00053 extern struct nlmsghdr *  nlmsg_hdr(struct nl_msg *);
00054 extern void               nlmsg_free(struct nl_msg *);
00055 
00056 /* attribute modification */
00057 extern void               nlmsg_set_proto(struct nl_msg *, int);
00058 extern int                nlmsg_get_proto(struct nl_msg *);
00059 extern void               nlmsg_set_src(struct nl_msg *, struct sockaddr_nl *);
00060 extern struct sockaddr_nl *nlmsg_get_src(struct nl_msg *);
00061 extern void               nlmsg_set_dst(struct nl_msg *, struct sockaddr_nl *);
00062 extern struct sockaddr_nl *nlmsg_get_dst(struct nl_msg *);
00063 extern void               nlmsg_set_creds(struct nl_msg *, struct ucred *);
00064 extern struct ucred *     nlmsg_get_creds(struct nl_msg *);
00065 
00066 extern char *             nl_nlmsgtype2str(int, char *, size_t);
00067 extern int                nl_str2nlmsgtype(const char *);
00068 
00069 extern char *             nl_nlmsg_flags2str(int, char *, size_t);
00070 
00071 extern int                nl_msg_parse(struct nl_msg *,
00072                                        void (*cb)(struct nl_object *, void *),
00073                                        void *);
00074 
00075 /**
00076  * @name Iterators
00077  * @{
00078  */
00079 
00080 /**
00081  * @ingroup msg
00082  * Iterate over a stream of attributes in a message
00083  * @arg pos     loop counter, set to current attribute
00084  * @arg nlh     netlink message header
00085  * @arg hdrlen  length of family header
00086  * @arg rem     initialized to len, holds bytes currently remaining in stream
00087  */
00088 #define nlmsg_for_each_attr(pos, nlh, hdrlen, rem) \
00089         nla_for_each_attr(pos, nlmsg_attrdata(nlh, hdrlen), \
00090                           nlmsg_attrlen(nlh, hdrlen), rem)
00091 
00092 /**
00093  * Iterate over a stream of messages
00094  * @arg pos     loop counter, set to current message
00095  * @arg head    head of message stream
00096  * @arg len     length of message stream
00097  * @arg rem     initialized to len, holds bytes currently remaining in stream
00098  */
00099 #define nlmsg_for_each_msg(pos, head, len, rem) \
00100         for (pos = head, rem = len; \
00101              nlmsg_ok(pos, rem); \
00102              pos = nlmsg_next(pos, &(rem)))
00103 
00104 /** @} */
00105 
00106 #endif

Generated on Fri Apr 27 14:14:07 2007 for libnl by  doxygen 1.5.1