aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/options/posix/include/netinet/in.h
blob: 9a42c47ea1452c35f5a0b9737a0caccd236035c4 (plain)
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

#ifndef _NETINET_IN_H
#define _NETINET_IN_H

#include <stdint.h>
#include <endian.h>
#include <sys/socket.h> // struct sockaddr
#include <abi-bits/socket.h>
#include <abi-bits/in.h>
#include <arpa/inet.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef __MLIBC_ABI_ONLY

extern const struct in6_addr in6addr_any;
extern const struct in6_addr in6addr_loopback;

uint32_t htonl(uint32_t);
uint16_t htons(uint16_t);
uint32_t ntohl(uint32_t);
uint16_t ntohs(uint16_t);

#endif /* !__MLIBC_ABI_ONLY */

#define IN6_IS_ADDR_UNSPECIFIED(a) ({ \
    uint32_t *_a = (uint32_t *)(((struct in6_addr *) a)->s6_addr); \
    !_a[0] && \
    !_a[1] && \
    !_a[2] && \
    !_a[3];  \
})
#define IN6_IS_ADDR_LOOPBACK(a) ({ \
    uint32_t *_a = (uint32_t *)(((struct in6_addr *) a)->s6_addr); \
    !_a[0] && \
    !_a[1] && \
    !_a[2] && \
     _a[3] == htonl(0x0001); \
})
#define IN6_IS_ADDR_MULTICAST(a) (((const uint8_t *) (a))[0] == 0xff)
#define IN6_IS_ADDR_LINKLOCAL(a) ({ \
    uint32_t *_a = (uint32_t *)(((struct in6_addr *) a)->s6_addr); \
    _a[0] & htonl(0xffc00000) == htonl(0xfe800000); \
})
#define IN6_IS_ADDR_SITELOCAL(a) ({ \
    uint32_t *_a = (uint32_t *)(((struct in6_addr *) a)->s6_addr); \
    _a[0] & htonl(0xffc00000) == htonl(0xfec00000); \
})
#define IN6_IS_ADDR_V4MAPPED(a) ({ \
    uint32_t *_a = (uint32_t *)(((struct in6_addr *) a)->s6_addr); \
    !_a[0] && \
    !_a[1] && \
     _a[2] == htonl(0xffff); \
})
#define __ARE_4_BYTE_EQUAL(a, b) \
	((a)[0] == (b)[0] && (a)[1] == (b)[1] && (a)[2] == (b)[2] && \
	 (a)[3] == (b)[3] && (a)[4] == (b)[4])
#define IN6_ARE_ADDR_EQUAL(a, b) \
	__ARE_4_BYTE_EQUAL((const uint32_t *)(a), (const uint32_t *)(b))

#define IN6_IS_ADDR_V4COMPAT(a) ({ \
	uint32_t *_a = (uint32_t *)(((struct in6_addr *) a)->s6_addr); \
	uint8_t *_a8 = (uint8_t *)(((struct in6_addr *) a)->s6_addr); \
	!_a[0] && !_a[1] && !_a[2] && (_a8[15] > 1); \
})
#define IN6_IS_ADDR_MC_NODELOCAL(a) ({ \
    (IN6_IS_ADDR_MULTICAST(a) && \
    ((((const uint8_t *)(a))[1] & 0xf) == 0x1)); \
})
#define IN6_IS_ADDR_MC_LINKLOCAL(a) ({ \
    (IN6_IS_ADDR_MULTICAST(a) && \
    ((((const uint8_t *)(a))[1] & 0xf) == 0x2)); \
})
#define IN6_IS_ADDR_MC_SITELOCAL(a) ({ \
    (IN6_IS_ADDR_MULTICAST(a) && \
    ((((const uint8_t *)(a))[1] & 0xf) == 0x5)); \
})
#define IN6_IS_ADDR_MC_ORGLOCAL(a) ({ \
    (IN6_IS_ADDR_MULTICAST(a) && \
    ((((const uint8_t *)(a))[1] & 0xf) == 0x8)); \
})
#define IN6_IS_ADDR_MC_GLOBAL(a) ({ \
    (IN6_IS_ADDR_MULTICAST(a) && \
    ((((const uint8_t *)(a))[1] & 0xf) == 0xe)); \
})

#define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0)
#define IN_CLASSA_NET 0xff000000
#define IN_CLASSA_NSHIFT 24
#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
#define IN_CLASSA_MAX 128
#define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET 0xffff0000
#define IN_CLASSB_NSHIFT 16
#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
#define IN_CLASSB_MAX 65536
#define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
#define IN_CLASSC_NET 0xffffff00
#define IN_CLASSC_NSHIFT 8
#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
#define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
#define IN_MULTICAST(a) IN_CLASSD(a)
#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
#define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)

#define IN_LOOPBACKNET 127

#define MCAST_EXCLUDE 0
#define MCAST_INCLUDE 1

#ifdef __cplusplus
}
#endif

#endif // _NETINET_IN_H