summaryrefslogtreecommitdiff
path: root/include/netinet/in.h
blob: 368a61c1d78ca35a6e95462edd5efa60255d0d12 (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
#ifndef __NETINET_IN_H
#define __NETINET_IN_H

#include <stdint.h>
#define __BITS_IN_ADDR_H_
#include <bits/in_addr.h>
#undef __BITS_IN_ADDR_H_

#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}} \
	}

#define IPPROTO_IP   0
#define IPPROTO_IPV6 41
#define IPPROTO_ICMP 1
#define IPPROTO_RAW  255
#define IPPROTO_TCP  6
#define IPPROTO_UDP  17

#define INADDR_ANY	 ((unsigned long int)0x00000000)
#define INADDR_BROADCAST ((unsigned long int)0xffffffff)

#define INET_ADDRSTRLEN	 16
#define INET6_ADDRSTRLEN 46

#define IPV6_JOIN_GROUP	    20
#define IPV6_LEAVE_GROUP    21
#define IPV6_MULTICAST_HOPS 18
#define IPV6_MULTICAST_IF   17
#define IPV6_UNICAST_HOPS   16

#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_addr32[3]) == ntohl(1)))

#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *)(a))[0] == 0xff)

#define IN6_IS_ADDR_LINKLOCAL(a) \
	((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0x80)

#define IN6_IS_ADDR_SITELOCAL(a) \
	((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0xc0)

#define IN6_IS_ADDR_V4MAPPED(a)                                      \
	((((a)->s6_addr32[0]) == 0) && (((a)->s6_addr32[1]) == 0) && \
	 (((a)->s6_addr32[2]) == ntohl(0x0000ffff)))

#define IN6_IS_ADDR_V4COMPAT(a)                                      \
	((((a)->s6_addr32[0]) == 0) && (((a)->s6_addr32[1]) == 0) && \
	 (((a)->s6_addr32[2]) == 0) && (((a)->s6_addr32[3]) != 0) && \
	 (((a)->s6_addr32[3]) != ntohl(1)))

#define IN6_IS_ADDR_MC_NODELOCAL(a) \
	(IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x1))

#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
	(IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x2))

#define IN6_IS_ADDR_MC_SITELOCAL(a) \
	(IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x5))

#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
	(IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x8))

#define IN6_IS_ADDR_MC_GLOBAL(a) \
	(IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0xe))

typedef __UINT8_TYPE__ uint8_t;
typedef __UINT16_TYPE__ in_port_t;
typedef __UINT16_TYPE__ sa_family_t;
typedef __UINT32_TYPE__ uint32_t;

struct sockaddr_in {
	sa_family_t sin_family;
	in_port_t sin_port;
	struct in_addr sin_addr;
};

struct in6_addr {
	uint8_t s6_addr[16];
};

struct sockaddr_in6 {
	sa_family_t sin6_family;
	in_port_t sin6_port;
	uint32_t sin6_flowinfo;
	struct in6_addr sin6_addr;
	uint32_t sin6_scope_id;
};

struct ipv6_mreq {
	struct in6_addr ipv6mr_multiaddr;
	unsigned ipv6mr_interface;
};

const struct in6_addr in6addr_any;
const struct in6_addr in6addr_loopback;

#endif