posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
in.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
16#ifndef ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_
17#define ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_
18
19#include <stdint.h>
20
21#include <zephyr/net/net_ip.h>
22#include <zephyr/net/socket.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#if !defined(_SA_FAMILY_T_DECLARED) && !defined(__sa_family_t_defined)
29typedef net_sa_family_t sa_family_t;
30#define _SA_FAMILY_T_DECLARED
31#define __sa_family_t_defined
32#endif
33
34#if !(defined(_IN_PORT_T_DECLARED) || defined(__in_port_t_defined)) || defined(__DOXYGEN__)
36typedef uint16_t in_port_t;
37#define _IN_PORT_T_DECLARED
38#define __in_port_t_defined
39#endif
40
41#if !(defined(_IN_ADDR_T_DECLARED) || defined(__in_addr_t_defined)) || defined(__DOXYGEN__)
43typedef uint32_t in_addr_t;
44#define _IN_ADDR_T_DECLARED
45#define __in_addr_t_defined
46#endif
47
48#if !(defined(_IN_ADDR_DECLARED) || defined(__in_addr_defined)) || defined(__DOXYGEN__)
50struct in_addr {
51 in_addr_t s_addr;
52};
53#define _IN_ADDR_DECLARED
54#define __in_addr_defined
55#endif
56
57#if !(defined(_SOCKADDR_IN_DECLARED) || defined(__sockaddr_in_defined)) || defined(__DOXYGEN__)
64#define _SOCKADDR_IN_DECLARED
65#define __sockaddr_in_defined
66#endif
67
68#if !(defined(_IN6_ADDR_DECLARED) || defined(__in6_addr_defined)) || defined(__DOXYGEN__)
70struct in6_addr {
71 union {
72 uint8_t s6_addr[16];
73 uint16_t s6_addr16[8];
74 uint32_t s6_addr32[4];
75 };
76};
77#define _IN6_ADDR_DECLARED
78#define __in6_addr_defined
79#endif
80
81#if !(defined(_SOCKADDR_IN6_DECLARED) || defined(__sockaddr_in6_defined)) || defined(__DOXYGEN__)
84 sa_family_t sin6_family;
87 uint32_t sin6_scope_id;
88 /* slightly out of order w.r.t. spec (zephyr assumes consistent family, port, addr offsets) */
89 uint32_t sin6_flowinfo;
90};
91#define _SOCKADDR_IN6_DECLARED
92#define __sockaddr_in6_defined
93#endif
94
96extern const struct in6_addr in6addr_any;
98extern const struct in6_addr in6addr_loopback;
99
101#define IN6ADDR_ANY_INIT { { { 0 } } }
103#define IN6ADDR_LOOPBACK_INIT { { { 0, 0, 0, 0, 0, 0, 0, 0, \
104 0, 0, 0, 0, 0, 0, 0, 1 } } }
105
106#if !(defined(_IPV6_MREQ_DECLARED) || defined(__ipv6_mreq_defined)) || defined(__DOXYGEN__)
108struct ipv6_mreq {
110 unsigned int ipv6mr_interface;
111};
112#define _IPV6_MREQ_DECLARED
113#define __ipv6_mreq_defined
114#endif
115
116/* Protocols (IPPROTO_*). */
117#define IPPROTO_IP NET_IPPROTO_IP
118#define IPPROTO_IPV6 NET_IPPROTO_IPV6
119#define IPPROTO_ICMP NET_IPPROTO_ICMP
120#define IPPROTO_RAW NET_IPPROTO_RAW
121#define IPPROTO_TCP NET_IPPROTO_TCP
122#define IPPROTO_UDP NET_IPPROTO_UDP
125#define INADDR_ANY ((in_addr_t)NET_INADDR_ANY)
127#define INADDR_BROADCAST ((in_addr_t)NET_INADDR_BROADCAST)
129#define INADDR_LOOPBACK ((in_addr_t)0x7f000001)
130
132#define INET_ADDRSTRLEN NET_INET_ADDRSTRLEN
133
135#define htonl(x) net_htonl(x)
137#define htons(x) net_htons(x)
139#define ntohl(x) net_ntohl(x)
141#define ntohs(x) net_ntohs(x)
142
144#define INET6_ADDRSTRLEN NET_INET6_ADDRSTRLEN
145
146/* IPv6-level socket options (IPPROTO_IPV6). */
148#define IPV6_JOIN_GROUP ZSOCK_IPV6_JOIN_GROUP
150#define IPV6_LEAVE_GROUP ZSOCK_IPV6_LEAVE_GROUP
152#define IPV6_MULTICAST_HOPS ZSOCK_IPV6_MULTICAST_HOPS
154#define IPV6_MULTICAST_IF ZSOCK_IPV6_MULTICAST_IF
156#define IPV6_MULTICAST_LOOP ZSOCK_IPV6_MULTICAST_LOOP
158#define IPV6_UNICAST_HOPS ZSOCK_IPV6_UNICAST_HOPS
160#define IPV6_V6ONLY ZSOCK_IPV6_V6ONLY
161
162/* IPv6 address tests. Each takes a pointer to a struct in6_addr and evaluates non-zero on match. */
164#define IN6_IS_ADDR_UNSPECIFIED(addr) \
165 ZSOCK_IN6_IS_ADDR_UNSPECIFIED((const struct net_in6_addr *)(addr))
167#define IN6_IS_ADDR_LOOPBACK(addr) ZSOCK_IN6_IS_ADDR_LOOPBACK((const struct net_in6_addr *)(addr))
169#define IN6_IS_ADDR_MULTICAST(addr) ZSOCK_IN6_IS_ADDR_MULTICAST((const struct net_in6_addr *)(addr))
171#define IN6_IS_ADDR_LINKLOCAL(addr) ZSOCK_IN6_IS_ADDR_LINKLOCAL((const struct net_in6_addr *)(addr))
173#define IN6_IS_ADDR_SITELOCAL(addr) ZSOCK_IN6_IS_ADDR_SITELOCAL((const struct net_in6_addr *)(addr))
175#define IN6_IS_ADDR_V4MAPPED(addr) ZSOCK_IN6_IS_ADDR_V4MAPPED((const struct net_in6_addr *)(addr))
177static inline int __z_posix_in6_is_addr_v4compat(const void *addr)
178{
179 const uint8_t *p = (const uint8_t *)addr;
180
181 for (int i = 0; i < 12; i++) {
182 if (p[i] != 0) {
183 return 0;
184 }
185 }
186
187 return p[12] != 0 || p[13] != 0 || p[14] != 0 || p[15] > 1;
188}
191#define IN6_IS_ADDR_V4COMPAT(addr) __z_posix_in6_is_addr_v4compat(addr)
193#define IN6_IS_ADDR_MC_NODELOCAL(addr) \
194 ZSOCK_IN6_IS_ADDR_MC_NODELOCAL((const struct net_in6_addr *)(addr))
196#define IN6_IS_ADDR_MC_LINKLOCAL(addr) \
197 ZSOCK_IN6_IS_ADDR_MC_LINKLOCAL((const struct net_in6_addr *)(addr))
199#define IN6_IS_ADDR_MC_SITELOCAL(addr) \
200 ZSOCK_IN6_IS_ADDR_MC_SITELOCAL((const struct net_in6_addr *)(addr))
202#define IN6_IS_ADDR_MC_ORGLOCAL(addr) \
203 ZSOCK_IN6_IS_ADDR_MC_ORGLOCAL((const struct net_in6_addr *)(addr))
205#define IN6_IS_ADDR_MC_GLOBAL(addr) ZSOCK_IN6_IS_ADDR_MC_GLOBAL((const struct net_in6_addr *)(addr))
206
207#ifdef __cplusplus
208}
209#endif
210
211#endif /* ZEPHYR_INCLUDE_POSIX_NETINET_IN_H_ */
const struct in6_addr in6addr_loopback
IPv6 loopback address.
uint16_t in_port_t
Unsigned 16-bit Internet port number.
Definition in.h:36
uint32_t in_addr_t
Unsigned 32-bit IPv4 address.
Definition in.h:43
const struct in6_addr in6addr_any
IPv6 wildcard address.
IPv6 address, laid out and aligned like struct net_in6_addr.
Definition in.h:70
uint8_t s6_addr[16]
IPv6 address bytes in network byte order.
Definition in.h:72
uint32_t s6_addr32[4]
IPv6 address as 32-bit words in network byte order.
Definition in.h:74
uint16_t s6_addr16[8]
IPv6 address as 16-bit words in network byte order.
Definition in.h:73
IPv4 address.
Definition inet.h:47
in_addr_t s_addr
IPv4 address in network byte order.
Definition inet.h:48
IPv6 multicast group request.
Definition in.h:108
struct in6_addr ipv6mr_multiaddr
Multicast address.
Definition in.h:109
unsigned int ipv6mr_interface
Interface index.
Definition in.h:110
Socket address for IPv6.
Definition in.h:83
in_port_t sin6_port
Port number in network byte order.
Definition in.h:85
struct in6_addr sin6_addr
IPv6 address.
Definition in.h:86
uint32_t sin6_flowinfo
IPv6 flow information.
Definition in.h:89
uint32_t sin6_scope_id
Scope identifier.
Definition in.h:87
sa_family_t sin6_family
Address family; AF_INET6.
Definition in.h:84
Socket address for IPv4.
Definition in.h:59
struct in_addr sin_addr
IPv4 address.
Definition in.h:62
sa_family_t sin_family
Address family; AF_INET.
Definition in.h:60
in_port_t sin_port
Port number in network byte order.
Definition in.h:61