]> granicus.if.org Git - strace/blob - netlink.h
Remove XLAT_END
[strace] / netlink.h
1 /*
2  * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
3  * Copyright (c) 2017-2018 The strace developers.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: LGPL-2.1-or-later
7  */
8
9 #ifndef STRACE_NETLINK_H
10 # define STRACE_NETLINK_H
11
12 # include <stdbool.h>
13 # include <sys/socket.h>
14 # include <linux/netlink.h>
15
16 # ifndef NETLINK_SOCK_DIAG
17 #  define NETLINK_SOCK_DIAG 4
18 # endif
19
20 # ifndef NLM_F_NONREC
21 #  define NLM_F_NONREC  0x100
22 # endif
23 # ifndef NLM_F_CAPPED
24 #  define NLM_F_CAPPED  0x100
25 # endif
26
27 # undef NLMSG_HDRLEN
28 # define NLMSG_HDRLEN ((unsigned int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
29
30 # ifndef NLMSG_MIN_TYPE
31 #  define NLMSG_MIN_TYPE                0x10
32 # endif
33
34 # ifndef NLA_ALIGN
35 #  define NLA_ALIGN(len) (((len) + 3) & ~3)
36 # endif
37
38 # undef NLA_HDRLEN
39 # define NLA_HDRLEN ((unsigned int) NLA_ALIGN(sizeof(struct nlattr)))
40
41 # ifndef NLA_TYPE_MASK
42 #  define NLA_F_NESTED          (1 << 15)
43 #  define NLA_F_NET_BYTEORDER   (1 << 14)
44 #  define NLA_TYPE_MASK         ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
45 # endif
46
47 static inline bool
48 is_nlmsg_ok(const struct nlmsghdr *const nlh, const ssize_t len)
49 {
50         return len >= (ssize_t) sizeof(*nlh)
51                && nlh->nlmsg_len >= sizeof(*nlh)
52                && (size_t) len >= nlh->nlmsg_len;
53 }
54
55 #endif /* !STRACE_NETLINK_H */