summaryrefslogtreecommitdiff
path: root/include/sparse
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2012-06-14 09:46:18 -0700
committerBen Pfaff <blp@nicira.com>2012-07-18 10:29:21 -0700
commitfd94a42c43ff4a0e57a44bdc9ded1b7e1e63faaa (patch)
tree8dbefecf34d4e3625393f80d9ea7fd6612504d4b /include/sparse
parenta0505c49dd98b393f4c47a423f325008443eb1ee (diff)
downloadopenvswitch-fd94a42c43ff4a0e57a44bdc9ded1b7e1e63faaa.tar.gz
socket-util: Add functions for sending fds over Unix domain sockets.
These will be used in upcoming commits. This commit also adds corresponding definitions to the "sparse" header, so that sparse still works. Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'include/sparse')
-rw-r--r--include/sparse/sys/socket.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/sparse/sys/socket.h b/include/sparse/sys/socket.h
index d7e17ea12..13f61e508 100644
--- a/include/sparse/sys/socket.h
+++ b/include/sparse/sys/socket.h
@@ -47,6 +47,37 @@ struct msghdr {
int msg_flags;
};
+struct cmsghdr {
+ size_t cmsg_len;
+ int cmsg_level;
+ int cmsg_type;
+ unsigned char cmsg_data[];
+};
+
+#define __CMSG_ALIGNTO sizeof(size_t)
+#define CMSG_ALIGN(LEN) \
+ (((LEN) + __CMSG_ALIGNTO - 1) / __CMSG_ALIGNTO * __CMSG_ALIGNTO)
+#define CMSG_DATA(CMSG) ((CMSG)->cmsg_data)
+#define CMSG_LEN(LEN) (sizeof(struct cmsghdr) + (LEN))
+#define CMSG_SPACE(LEN) CMSG_ALIGN(CMSG_LEN(LEN))
+#define CMSG_FIRSTHDR(MSG) \
+ ((MSG)->msg_controllen ? (struct cmsghdr *) (MSG)->msg_control : NULL)
+#define CMSG_NXTHDR(MSG, CMSG) __cmsg_nxthdr(MSG, CMSG)
+
+static inline struct cmsghdr *
+__cmsg_nxthdr(struct msghdr *msg, struct cmsghdr *cmsg)
+{
+ size_t ofs = (char *) cmsg - (char *) msg->msg_control;
+ size_t next_ofs = ofs + CMSG_ALIGN(cmsg->cmsg_len);
+ return (next_ofs < msg->msg_controllen
+ ? (void *) ((char *) msg->msg_control + next_ofs)
+ : NULL);
+}
+
+enum {
+ SCM_RIGHTS = 1
+};
+
enum {
SOCK_DGRAM,
SOCK_RAW,