+ exec* functions
[meinos.git] / apps / include / netinet / in.h
blob1830001805e314a4d5ea39e539d85a26f49f85bc
1 /*
2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _NETINET_IN_H_
20 #define _NETINET_IN_H_
22 #include <sys/socket.h>
23 #include <stdint.h>
25 typedef uint16_t in_port_t;
27 // IPv4
29 #define IPPROTO_IP 0x00010000
30 #define IPPROTO_ICMP 0x00010001
31 #define IPPROTO_RAW 0x00010002
32 #define IPPROTO_TCP 0x00010003
33 #define IPPROTO_UDP 0x00010004
35 #define INADDR_ANY ((in_addr_t)0x00000000)
36 #define INADDR_BROADCAST ((in_addr_t)0xFFFFFFFF)
37 #define INADDR_NONE ((in_addr_t)0xFFFFFFFF)
39 #define INET_ADDRSTRLEN 16
41 typedef uint32_t in_addr_t;
43 struct in_addr {
44 in_addr_t s_addr;
47 struct sockaddr_in {
48 sa_family_t sin_family;
49 in_port_t sin_port;
50 struct in_addr sin_addr;
53 #include <arpa/inet.h>
55 // IPv6
57 #define IPPROTO_IPV6 1024
59 #define IN6ADDR_ANY_INIT { .sin_addr = { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
60 #define IN6ADDR_LOOPBACK_INIT { .sin_addr = { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
62 #define INET6_ADDRSTRLEN 46
64 #define IPV6_JOIN_GROUP 0x00011000
65 #define IPV6_LEAVE_GROUP 0x00011001
66 #define IPV6_MULTICAST_HOPS 0x00011002
67 #define IPV6_MULTICAST_IF 0x00011003
68 #define IPV6_MULTICAST_LOOP 0x00011004
69 #define IPV6_UNICAST_HOPS 0x00011005
70 #define IPV6_V6ONLY 0x00011006
72 #define IN6_IS_ADDR_UNSPECIFIED(a) \
73 (((const uint32_t *) (a))[0] == 0 \
74 && ((const uint32_t *) (a))[1] == 0 \
75 && ((const uint32_t *) (a))[2] == 0 \
76 && ((const uint32_t *) (a))[3] == 0)
78 #define IN6_IS_ADDR_LOOPBACK(a) \
79 (((const uint32_t *) (a))[0] == 0 \
80 && ((const uint32_t *) (a))[1] == 0 \
81 && ((const uint32_t *) (a))[2] == 0 \
82 && ((const uint32_t *) (a))[3] == htonl (1))
84 #define IN6_IS_ADDR_MULTICAST(a) (((const uint8_t *) (a))[0] == 0xff)
86 #define IN6_IS_ADDR_LINKLOCAL(a) \
87 ((((const uint32_t *) (a))[0] & htonl (0xffc00000)) \
88 == htonl (0xfe800000))
90 #define IN6_IS_ADDR_SITELOCAL(a) \
91 ((((const uint32_t *) (a))[0] & htonl (0xffc00000)) \
92 == htonl (0xfec00000))
94 #define IN6_IS_ADDR_V4MAPPED(a) \
95 ((((const uint32_t *) (a))[0] == 0) \
96 && (((const uint32_t *) (a))[1] == 0) \
97 && (((const uint32_t *) (a))[2] == htonl (0xffff)))
99 #define IN6_IS_ADDR_V4COMPAT(a) \
100 ((((const uint32_t *) (a))[0] == 0) \
101 && (((const uint32_t *) (a))[1] == 0) \
102 && (((const uint32_t *) (a))[2] == 0) \
103 && (ntohl (((const uint32_t *) (a))[3]) > 1))
105 #define IN6_ARE_ADDR_EQUAL(a,b) \
106 ((((const uint32_t *) (a))[0] == ((const uint32_t *) (b))[0]) \
107 && (((const uint32_t *) (a))[1] == ((const uint32_t *) (b))[1]) \
108 && (((const uint32_t *) (a))[2] == ((const uint32_t *) (b))[2]) \
109 && (((const uint32_t *) (a))[3] == ((const uint32_t *) (b))[3]))
111 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
112 (IN6_IS_ADDR_MULTICAST(a) \
113 && ((((const uint8_t *) (a))[1] & 0xf) == 0x1))
115 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
116 (IN6_IS_ADDR_MULTICAST(a) \
117 && ((((const uint8_t *) (a))[1] & 0xf) == 0x2))
119 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
120 (IN6_IS_ADDR_MULTICAST(a) \
121 && ((((const uint8_t *) (a))[1] & 0xf) == 0x5))
123 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
124 (IN6_IS_ADDR_MULTICAST(a) \
125 && ((((const uint8_t *) (a))[1] & 0xf) == 0x8))
127 #define IN6_IS_ADDR_MC_GLOBAL(a) \
128 (IN6_IS_ADDR_MULTICAST(a) \
129 && ((((const uint8_t *) (a))[1] & 0xf) == 0xe))
131 struct in6_addr {
132 uint8_t s6_addr[16];
135 struct sockaddr_in6 {
136 sa_family_t sin6_family;
137 in_port_t sin6_port;
138 uint32_t sin6_flowinfo;
139 struct in6_addr sin6_addr;
140 uint32_t sin6_scope_id;
143 struct ipv6_mreq {
144 struct in6_addr ipv6mr_multiaddr;
145 unsigned ipv6mr_interface;
148 const struct in6_addr in6addr_any;
149 const struct in6_addr in6addr_loopback;
151 #endif