1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//===-- Definition of macros from netinet/in.h ----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
#define LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
#include "../__llvm-libc-common.h"
#include "../llvm-libc-types/in_addr_t.h"
#include "../llvm-libc-types/struct_in6_addr.h"
#define IPPROTO_IP 0
#define IPPROTO_ICMP 1
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
#define IPPROTO_IPV6 41
#define IPPROTO_RAW 255
#define INADDR_ANY __LLVM_LIBC_CAST(static_cast, in_addr_t, 0x00000000)
#define INADDR_BROADCAST __LLVM_LIBC_CAST(static_cast, in_addr_t, 0xffffffff)
#define INADDR_NONE __LLVM_LIBC_CAST(static_cast, in_addr_t, 0xffffffff)
// Not specified by POSIX, added in SVR4
#define INADDR_LOOPBACK __LLVM_LIBC_CAST(static_cast, in_addr_t, 0x7f000001)
#define IN6ADDR_ANY_INIT \
{ \
{ \
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } \
} \
}
#define IN6ADDR_LOOPBACK_INIT \
{ \
{ \
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } \
} \
}
// The following macros test for special IPv6 addresses. Each macro is of type
// int and takes a single argument of type const struct in6_addr *:
// https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html
#define __IN6_IS_ADDR_UNSPECIFIED(a) \
((a)->s6_addr32[0] == 0 && (a)->s6_addr32[1] == 0 && \
(a)->s6_addr32[2] == 0 && (a)->s6_addr32[3] == 0)
#define __IN6_IS_ADDR_LOOPBACK(a) \
((a)->s6_addr32[0] == 0 && (a)->s6_addr32[1] == 0 && \
(a)->s6_addr32[2] == 0 && (a)->s6_addr[12] == 0 && (a)->s6_addr[13] == 0 && \
(a)->s6_addr[14] == 0 && (a)->s6_addr[15] == 1)
#define IN6_IS_ADDR_UNSPECIFIED(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
__IN6_IS_ADDR_UNSPECIFIED(__a); \
}))
#define IN6_IS_ADDR_LOOPBACK(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
__IN6_IS_ADDR_LOOPBACK(__a); \
}))
#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
#define IN6_IS_ADDR_LINKLOCAL(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
__a->s6_addr[0] == 0xfe && (__a->s6_addr[1] & 0xc0) == 0x80; \
}))
#define IN6_IS_ADDR_SITELOCAL(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
__a->s6_addr[0] == 0xfe && (__a->s6_addr[1] & 0xc0) == 0xc0; \
}))
#define IN6_IS_ADDR_V4MAPPED(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
__a->s6_addr32[0] == 0 && __a->s6_addr32[1] == 0 && \
__a->s6_addr[8] == 0 && __a->s6_addr[9] == 0 && \
__a->s6_addr[10] == 0xff && __a->s6_addr[11] == 0xff; \
}))
#define IN6_IS_ADDR_V4COMPAT(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
__a->s6_addr32[0] == 0 && __a->s6_addr32[1] == 0 && \
__a->s6_addr32[2] == 0 && !__IN6_IS_ADDR_UNSPECIFIED(__a) && \
!__IN6_IS_ADDR_LOOPBACK(__a); \
}))
#define IN6_IS_ADDR_MC_NODELOCAL(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
IN6_IS_ADDR_MULTICAST(__a) && (__a->s6_addr[1] & 0xf) == 0x1; \
}))
#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
IN6_IS_ADDR_MULTICAST(__a) && (__a->s6_addr[1] & 0xf) == 0x2; \
}))
#define IN6_IS_ADDR_MC_SITELOCAL(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
IN6_IS_ADDR_MULTICAST(__a) && (__a->s6_addr[1] & 0xf) == 0x5; \
}))
#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
IN6_IS_ADDR_MULTICAST(__a) && (__a->s6_addr[1] & 0xf) == 0x8; \
}))
#define IN6_IS_ADDR_MC_GLOBAL(a) \
(__extension__({ \
const struct in6_addr *__a = (a); \
IN6_IS_ADDR_MULTICAST(__a) && (__a->s6_addr[1] & 0xf) == 0xe; \
}))
#endif // LLVM_LIBC_MACROS_NETINET_IN_MACROS_H