* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
* This module is responsible for defining the following basic networking
*\li struct sockaddr_storage
* It ensures that the AF_ and PF_ macros are defined.
* It declares ntoh[sl]() and hton[sl]().
* It declares inet_aton(), inet_ntop(), and inet_pton().
* It ensures that #INADDR_LOOPBACK, #INADDR_ANY, #IN6ADDR_ANY_INIT,
* IN6ADDR_V4MAPPED_INIT, in6addr_any, and in6addr_loopback are available.
* It ensures that IN_MULTICAST() is available to check for multicast
*\li No anticipated impact.
*\li No anticipated impact.
#include <isc/platform.h>
#include <sys/socket.h> /* Contractual promise. */
#include <netinet/in.h> /* Contractual promise. */
#include <arpa/inet.h> /* Contractual promise. */
#ifdef ISC_PLATFORM_NEEDNETINETIN6H
#include <netinet/in6.h> /* Required on UnixWare. */
#ifdef ISC_PLATFORM_NEEDNETINET6IN6H
#include <netinet6/in6.h> /* Required on BSD/OS for in6_pktinfo. */
#ifndef ISC_PLATFORM_HAVEIPV6
#include <isc/ipv6.h> /* Contractual promise. */
#ifdef ISC_PLATFORM_HAVEINADDR6
#define in6_addr in_addr6 /*%< Required for pre RFC2133 implementations. */
#ifdef ISC_PLATFORM_HAVEIPV6
* Required for some pre RFC2133 implementations.
* IN6ADDR_ANY_INIT and IN6ADDR_LOOPBACK_INIT were added in
* draft-ietf-ipngwg-bsd-api-04.txt or draft-ietf-ipngwg-bsd-api-05.txt.
* If 's6_addr' is defined then assume that there is a union and three
* levels otherwise assume two levels required.
#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
#define IN6ADDR_ANY_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } }
#ifndef IN6ADDR_LOOPBACK_INIT
/*% IPv6 address loopback init */
#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
#define IN6ADDR_LOOPBACK_INIT { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } }
#ifndef IN6ADDR_V4MAPPED_INIT
/*% IPv6 v4mapped prefix init */
#define IN6ADDR_V4MAPPED_INIT { { { 0,0,0,0,0,0,0,0,0,0,0xff,0xff,0,0,0,0 } } }
#define IN6ADDR_V4MAPPED_INIT { { 0,0,0,0,0,0,0,0,0,0,0xff,0xff,0,0,0,0 } }
#ifndef IN6_IS_ADDR_V4MAPPED
/*% Is IPv6 address V4 mapped? */
#define IN6_IS_ADDR_V4MAPPED(x) \
(memcmp((x)->s6_addr, in6addr_any.s6_addr, 10) == 0 && \
(x)->s6_addr[10] == 0xff && (x)->s6_addr[11] == 0xff)
#ifndef IN6_IS_ADDR_V4COMPAT
/*% Is IPv6 address V4 compatible? */
#define IN6_IS_ADDR_V4COMPAT(x) \
(memcmp((x)->s6_addr, in6addr_any.s6_addr, 12) == 0 && \
((x)->s6_addr[12] != 0 || (x)->s6_addr[13] != 0 || \
(x)->s6_addr[14] != 0 || \
((x)->s6_addr[15] != 0 && (x)->s6_addr[15] != 1)))
#ifndef IN6_IS_ADDR_MULTICAST
/*% Is IPv6 address multicast? */
#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
#ifndef IN6_IS_ADDR_LINKLOCAL
/*% Is IPv6 address linklocal? */
#define IN6_IS_ADDR_LINKLOCAL(a) \
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
#ifndef IN6_IS_ADDR_SITELOCAL
/*% is IPv6 address sitelocal? */
#define IN6_IS_ADDR_SITELOCAL(a) \
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
#ifndef IN6_IS_ADDR_LOOPBACK
/*% is IPv6 address loopback? */
#define IN6_IS_ADDR_LOOPBACK(x) \
(memcmp((x)->s6_addr, in6addr_loopback.s6_addr, 16) == 0)
#define PF_INET6 AF_INET6
#define INADDR_ANY 0x00000000UL
#define INADDR_LOOPBACK 0x7f000001UL
#ifndef ISC_PLATFORM_HAVEIN6PKTINFO
struct in6_addr ipi6_addr; /*%< src/dst IPv6 address */
unsigned int ipi6_ifindex; /*%< send/recv interface index */
#ifndef ISC_PLATFORM_HAVESOCKADDRSTORAGE
#define _SS_ALIGNSIZE (sizeof (uint64_t))
#ifdef ISC_PLATFORM_HAVESALEN
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - (2 * sizeof(uint8_t)))
#define _SS_PAD2SIZE (_SS_MAXSIZE - (_SS_ALIGNSIZE + _SS_PAD1SIZE \
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(uint16_t))
#define _SS_PAD2SIZE (_SS_MAXSIZE - (_SS_ALIGNSIZE + _SS_PAD1SIZE \
struct sockaddr_storage {
#ifdef ISC_PLATFORM_HAVESALEN
char __ss_pad1[_SS_PAD1SIZE];
uint64_t __ss_align; /* field to force desired structure */
char __ss_pad2[_SS_PAD2SIZE];
#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
extern const struct in6_addr isc_net_in6addrany;
* Cope with a missing in6addr_any and in6addr_loopback.
#define in6addr_any isc_net_in6addrany
#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRLOOPBACK)
extern const struct in6_addr isc_net_in6addrloop;
#define in6addr_loopback isc_net_in6addrloop
#ifdef ISC_PLATFORM_FIXIN6ISADDR
#undef IN6_IS_ADDR_GEOGRAPHIC
* Fix UnixWare 7.1.1's broken IN6_IS_ADDR_* definitions.
#define IN6_IS_ADDR_GEOGRAPHIC(a) (((a)->S6_un.S6_l[0] & 0xE0) == 0x80)
#define IN6_IS_ADDR_IPX(a) (((a)->S6_un.S6_l[0] & 0xFE) == 0x04)
#undef IN6_IS_ADDR_LINKLOCAL
#define IN6_IS_ADDR_LINKLOCAL(a) (((a)->S6_un.S6_l[0] & 0xC0FF) == 0x80FE)
#undef IN6_IS_ADDR_MULTICAST
#define IN6_IS_ADDR_MULTICAST(a) (((a)->S6_un.S6_l[0] & 0xFF) == 0xFF)
#define IN6_IS_ADDR_NSAP(a) (((a)->S6_un.S6_l[0] & 0xFE) == 0x02)
#undef IN6_IS_ADDR_PROVIDER
#define IN6_IS_ADDR_PROVIDER(a) (((a)->S6_un.S6_l[0] & 0xE0) == 0x40)
#undef IN6_IS_ADDR_SITELOCAL
#define IN6_IS_ADDR_SITELOCAL(a) (((a)->S6_un.S6_l[0] & 0xC0FF) == 0xC0FE)
#endif /* ISC_PLATFORM_FIXIN6ISADDR */
#ifdef ISC_PLATFORM_NEEDPORTT
* Ensure type in_port_t is defined.
typedef uint16_t in_port_t;
* If this system does not have MSG_TRUNC (as returned from recvmsg())
* ISC_PLATFORM_RECVOVERFLOW will be defined. This will enable the MSG_TRUNC
* faking code in socket.c.
#define ISC_PLATFORM_RECVOVERFLOW
#define ISC__IPADDR(x) ((uint32_t)htonl((uint32_t)(x)))
/*% Is IP address multicast? */
#define ISC_IPADDR_ISMULTICAST(i) \
(((uint32_t)(i) & ISC__IPADDR(0xf0000000)) \
== ISC__IPADDR(0xe0000000))
#define ISC_IPADDR_ISEXPERIMENTAL(i) \
(((uint32_t)(i) & ISC__IPADDR(0xf0000000)) \
== ISC__IPADDR(0xf0000000))
* Check if the system's kernel supports IPv4.
*\li #ISC_R_SUCCESS IPv4 is supported.
*\li #ISC_R_NOTFOUND IPv4 is not supported.
*\li #ISC_R_DISABLED IPv4 is disabled.
* Check if the system's kernel supports IPv6.
*\li #ISC_R_SUCCESS IPv6 is supported.
*\li #ISC_R_NOTFOUND IPv6 is not supported.
*\li #ISC_R_DISABLED IPv6 is disabled.
isc_net_probe_ipv6only(void);
* Check if the system's kernel supports the IPV6_V6ONLY socket option.
*\li #ISC_R_SUCCESS the option is supported for both TCP and UDP.
*\li #ISC_R_NOTFOUND IPv6 itself or the option is not supported.
isc_net_probe_ipv6pktinfo(void);
* Check if the system's kernel supports the IPV6_(RECV)PKTINFO socket option
* \li #ISC_R_SUCCESS the option is supported.
* \li #ISC_R_NOTFOUND IPv6 itself or the option is not supported.
isc_net_disableipv4(void);
isc_net_disableipv6(void);
isc_net_enableipv4(void);
isc_net_enableipv6(void);
* Returns whether UNIX domain sockets are supported.
#define ISC_NET_DSCPRECVV4 0x01 /* Can receive sent DSCP value IPv4 */
#define ISC_NET_DSCPRECVV6 0x02 /* Can receive sent DSCP value IPv6 */
#define ISC_NET_DSCPSETV4 0x04 /* Can set DSCP on socket IPv4 */
#define ISC_NET_DSCPSETV6 0x08 /* Can set DSCP on socket IPv6 */
#define ISC_NET_DSCPPKTV4 0x10 /* Can set DSCP on per packet IPv4 */
#define ISC_NET_DSCPPKTV6 0x20 /* Can set DSCP on per packet IPv6 */
#define ISC_NET_DSCPALL 0x3f /* All valid flags */
* Probe the level of DSCP support.
isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high);
* Returns system's default range of ephemeral UDP ports, if defined.
* If the range is not available or unknown, ISC_NET_PORTRANGELOW and
* ISC_NET_PORTRANGEHIGH will be returned.
*\li 'low' and 'high' must be non NULL.
*\li *low and *high will be the ports specifying the low and high ends of
#ifdef ISC_PLATFORM_NEEDNTOP
isc_net_ntop(int af, const void *src, char *dst, size_t size);
#define inet_ntop isc_net_ntop
#ifdef ISC_PLATFORM_NEEDPTON
isc_net_pton(int af, const char *src, void *dst);
#define inet_pton isc_net_pton
isc_net_aton(const char *cp, struct in_addr *addr);
#define inet_aton isc_net_aton