/*
- * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <Availability.h>
#endif
-#ifndef _IN_ADDR_T
-#define _IN_ADDR_T
-typedef __uint32_t in_addr_t; /* base type for internet address */
-#endif
+#include <sys/_types/_in_addr_t.h>
-#ifndef _IN_PORT_T
-#define _IN_PORT_T
-typedef __uint16_t in_port_t;
-#endif
+#include <sys/_types/_in_port_t.h>
/*
* POSIX 1003.1-2003
#define IPPROTO_SWIPE 53 /* IP with encryption */
#define IPPROTO_NHRP 54 /* Next Hop Resolution */
/* 55-57: Unassigned */
-#define IPPROTO_ICMPV6 58 /* ICMP6 */
-#define IPPROTO_NONE 59 /* IP6 no next header */
-#define IPPROTO_DSTOPTS 60 /* IP6 destination option */
+#define IPPROTO_ICMPV6 58 /* ICMP6 */
+#define IPPROTO_NONE 59 /* IP6 no next header */
+#define IPPROTO_DSTOPTS 60 /* IP6 destination option */
#define IPPROTO_AHIP 61 /* any host internal protocol */
#define IPPROTO_CFTP 62 /* CFTP */
#define IPPROTO_HELLO 63 /* "hello" routing protocol */
(((u_int32_t)(i) & 0xfff00000) == 0xac100000) || \
(((u_int32_t)(i) & 0xffff0000) == 0xc0a80000))
+#ifdef PRIVATE
+#define IN_SHARED_ADDRESS_SPACE(i) ((((u_int32_t)(i)) & (u_int32_t)0xffc00000) \
+ == (u_int32_t)0x64400000)
+
+#define IN_DS_LITE(i) ((((u_int32_t)(i)) & (u_int32_t)0xfffffff8) == (u_int32_t)0xc0000000)
+
+#define IN_6TO4_RELAY_ANYCAST(i) ((((u_int32_t)(i)) & (u_int32_t)IN_CLASSC_NET) == (u_int32_t)0xc0586300)
+#endif
+
#define IN_LOCAL_GROUP(i) (((u_int32_t)(i) & 0xffffff00) == 0xe0000000)
-
+
#define IN_ANY_LOCAL(i) (IN_LINKLOCAL(i) || IN_LOCAL_GROUP(i))
-#endif
+#endif /* __APPLE__ */
#define IN_LOOPBACKNET 127 /* official! */
#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
char sin_zero[8];
};
+#define IN_ARE_ADDR_EQUAL(a, b) \
+ (bcmp(&(a)->s_addr, &(b)->s_addr, \
+ sizeof (struct in_addr)) == 0)
+
+#ifdef PRIVATE
+/*
+ * sockaddr_in with scope ID field; this is used internally to keep
+ * track of scoped route entries in the routing table. The fact that
+ * such a value is embedded in the structure is an artifact of the
+ * current implementation which could change in future.
+ */
+struct sockaddr_inifscope {
+ __uint8_t sin_len;
+ sa_family_t sin_family;
+ in_port_t sin_port;
+ struct in_addr sin_addr;
+ /*
+ * To avoid possible conflict with an overlaid sockaddr_inarp
+ * having sin_other set to SIN_PROXY, we use the first 4-bytes
+ * of sin_zero since sin_srcaddr is one of the unused fields
+ * in sockaddr_inarp.
+ */
+ union {
+ char sin_zero[8];
+ struct {
+ __uint32_t ifscope;
+ } _in_index;
+ } un;
+#define sin_scope_id un._in_index.ifscope
+};
+
+#endif /* PRIVATE */
+
#define INET_ADDRSTRLEN 16
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
#define IP_RECVIF 20 /* bool; receive reception if w/dgram */
/* for IPSEC */
#define IP_IPSEC_POLICY 21 /* int; set/get security policy */
-#define IP_FAITH 22 /* bool; accept FAITH'ed connections */
+#define IP_FAITH 22 /* deprecated */
#ifdef __APPLE__
#define IP_STRIPHDR 23 /* bool: drop receive of raw IP header */
#endif
#define IP_BOUND_IF 25 /* int; set/get bound interface */
#define IP_PKTINFO 26 /* get pktinfo on recv socket, set src on sent dgram */
#define IP_RECVPKTINFO IP_PKTINFO /* receive pktinfo w/dgram */
-
+#define IP_RECVTOS 27 /* bool; receive IP TOS w/dgram */
#define IP_FW_ADD 40 /* add a firewall rule to chain */
#define IP_FW_DEL 41 /* delete a firewall rule from chain */
#define MCAST_UNBLOCK_SOURCE 85 /* unblock a source */
#ifdef PRIVATE
-#define IP_FORCE_OUT_IFP 69 /* deprecated; use IP_BOUND_IF instead */
+#define IP_FORCE_OUT_IFP 69 /* not implemented; use IP_BOUND_IF instead */
#define IP_NO_IFT_CELLULAR 6969 /* for internal use only */
#define IP_NO_IFT_PDP IP_NO_IFT_CELLULAR /* deprecated */
#define IP_OUT_IF 9696 /* for internal use only */
struct sockaddr_storage *msfr_srcs;
};
-#ifdef XNU_KERNEL_PRIVATE
+#ifdef BSD_KERNEL_PRIVATE
struct __msfilterreq32 {
uint32_t msfr_ifindex; /* interface index */
uint32_t msfr_fmode; /* filter mode for group */
struct sockaddr_storage msfr_group; /* group address */
user64_addr_t msfr_srcs;
};
-#endif /* XNU_KERNEL_PRIVATE */
+#endif /* BSD_KERNEL_PRIVATE */
#endif /* __MSFILTERREQ_DEFINED */
#pragma pack()
* We use uint32_t here to be consistent.
*/
int setipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t,
- uint32_t, struct in_addr *) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
+ uint32_t, struct in_addr *) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
int getipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t *,
- uint32_t *, struct in_addr *) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
+ uint32_t *, struct in_addr *) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
int setsourcefilter(int, uint32_t, struct sockaddr *, socklen_t,
- uint32_t, uint32_t, struct sockaddr_storage *) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
+ uint32_t, uint32_t, struct sockaddr_storage *) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
int getsourcefilter(int, uint32_t, struct sockaddr *, socklen_t,
- uint32_t *, uint32_t *, struct sockaddr_storage *) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
+ uint32_t *, uint32_t *, struct sockaddr_storage *) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
#endif
/*
*/
#define IPPROTO_MAXID (IPPROTO_AH + 1) /* don't list to IPPROTO_MAX */
-#ifdef KERNEL_PRIVATE
-
+#ifdef BSD_KERNEL_PRIVATE
#define CTL_IPPROTO_NAMES { \
{ "ip", CTLTYPE_NODE }, \
{ "icmp", CTLTYPE_NODE }, \
{ 0, 0 }, \
{ "ipsec", CTLTYPE_NODE }, \
}
-
-#endif /* KERNEL_PRIVATE */
+#endif /* BSD_KERNEL_PRIVATE */
/*
* Names for IP sysctl objects
#define IPCTL_STATS 12 /* ipstat structure */
#define IPCTL_ACCEPTSOURCEROUTE 13 /* may accept source routed packets */
#define IPCTL_FASTFORWARDING 14 /* use fast IP forwarding code */
-#define IPCTL_KEEPFAITH 15 /* FAITH IPv4->IPv6 translater ctl */
+#define IPCTL_KEEPFAITH 15 /* deprecated */
#define IPCTL_GIF_TTL 16 /* default TTL for gif encap packet */
#define IPCTL_MAXID 17
-#ifdef KERNEL_PRIVATE
+#ifdef BSD_KERNEL_PRIVATE
#define IPCTL_NAMES { \
{ 0, 0 }, \
{ "keepfaith", CTLTYPE_INT }, \
{ "gifttl", CTLTYPE_INT }, \
}
-#endif /* KERNEL_PRIVATE */
-
+#endif /* BSD_KERNEL_PRIVATE */
#endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
-
/* INET6 stuff */
#define __KAME_NETINET_IN_H_INCLUDED_
#include <netinet6/in6.h>
#undef __KAME_NETINET_IN_H_INCLUDED_
-#ifdef KERNEL
-#ifdef KERNEL_PRIVATE
-struct ifnet; struct mbuf; /* forward declarations for Standard C */
+#ifdef PRIVATE
+/*
+ * Minimal sized structure to hold an IPv4 or IPv6 socket address
+ * as sockaddr_storage can waste memory
+ */
+union sockaddr_in_4_6 {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+ struct sockaddr_in6 sin6;
+};
+
+#define CLAT46_HDR_EXPANSION_OVERHD (sizeof(struct ip6_hdr) - sizeof(struct ip))
-extern int in_broadcast(struct in_addr, struct ifnet *);
-extern int in_canforward(struct in_addr);
+/*
+ * Recommended DiffServ Code Point values
+ */
-#define in_cksum(m, l) inet_cksum(m, 0, 0, l)
-#define in_cksum_skip(m, l, o) inet_cksum(m, 0, o, (l) - (o))
+#define _DSCP_DF 0 /* RFC 2474 */
+
+#define _DSCP_CS0 0 /* RFC 2474 */
+#define _DSCP_CS1 8 /* RFC 2474 */
+#define _DSCP_CS2 16 /* RFC 2474 */
+#define _DSCP_CS3 24 /* RFC 2474 */
+#define _DSCP_CS4 32 /* RFC 2474 */
+#define _DSCP_CS5 40 /* RFC 2474 */
+#define _DSCP_CS6 48 /* RFC 2474 */
+#define _DSCP_CS7 56 /* RFC 2474 */
+
+#define _DSCP_EF 46 /* RFC 2474 */
+#define _DSCP_VA 44 /* RFC 5865 */
+
+#define _DSCP_AF11 10 /* RFC 2597 */
+#define _DSCP_AF12 12 /* RFC 2597 */
+#define _DSCP_AF13 14 /* RFC 2597 */
+#define _DSCP_AF21 18 /* RFC 2597 */
+#define _DSCP_AF22 20 /* RFC 2597 */
+#define _DSCP_AF23 22 /* RFC 2597 */
+#define _DSCP_AF31 26 /* RFC 2597 */
+#define _DSCP_AF32 28 /* RFC 2597 */
+#define _DSCP_AF33 30 /* RFC 2597 */
+#define _DSCP_AF41 34 /* RFC 2597 */
+#define _DSCP_AF42 36 /* RFC 2597 */
+#define _DSCP_AF43 38 /* RFC 2597 */
+
+#define _DSCP_52 52 /* Wi-Fi WMM Certification: Sigma */
+
+#define _MAX_DSCP 63 /* coded on 6 bits */
-extern u_int16_t inet_cksum(struct mbuf *m, unsigned int proto,
- unsigned int offset, unsigned int transport_len);
-extern u_short in_addword(u_short, u_short);
-extern u_short in_pseudo(u_int, u_int, u_int);
+#endif /* PRIVATE */
-extern int in_localaddr(struct in_addr);
+#ifdef KERNEL
+#ifdef BSD_KERNEL_PRIVATE
+#include <mach/boolean.h>
+
+struct ip;
+struct ifnet;
+struct mbuf;
+
+extern boolean_t in_broadcast(struct in_addr, struct ifnet *);
+extern boolean_t in_canforward(struct in_addr);
extern u_int32_t in_netof(struct in_addr);
-extern int inaddr_local(struct in_addr);
+extern uint32_t os_cpu_in_cksum_mbuf(struct mbuf *m, int len, int off,
+ uint32_t initial_sum);
+
+extern uint16_t inet_cksum(struct mbuf *, uint32_t, uint32_t, uint32_t);
+extern uint16_t inet_cksum_buffer(const void *, uint32_t, uint32_t, uint32_t);
+extern uint16_t in_addword(uint16_t, uint16_t);
+extern uint16_t in_pseudo(uint32_t, uint32_t, uint32_t);
+extern uint16_t in_pseudo64(uint64_t, uint64_t, uint64_t);
+extern uint16_t in_cksum_hdr_opt(const struct ip *);
+extern uint16_t ip_cksum_hdr_dir(struct mbuf *, uint32_t, int);
+extern uint16_t ip_cksum_hdr_dir_buffer(const void *, uint32_t, uint32_t, int);
+extern uint32_t in_finalize_cksum(struct mbuf *, uint32_t, uint32_t);
+extern uint16_t b_sum16(const void *buf, int len);
+#if DEBUG || DEVELOPMENT
+extern uint32_t in_cksum_mbuf_ref(struct mbuf *, int, int, uint32_t);
+#endif /* DEBUG || DEVELOPMENT */
+
+extern int in_getconninfo(struct socket *, sae_connid_t, uint32_t *,
+ uint32_t *, int32_t *, user_addr_t, socklen_t *, user_addr_t, socklen_t *,
+ uint32_t *, user_addr_t, uint32_t *);
+extern struct in_ifaddr * inifa_ifpwithflag(struct ifnet *, uint32_t);
+extern struct in_ifaddr * inifa_ifpclatv4(struct ifnet *);
+
+#define in_cksum(_m, _l) \
+ inet_cksum(_m, 0, 0, _l)
+#define in_cksum_buffer(_b, _l) \
+ inet_cksum_buffer(_b, 0, 0, _l)
+#define ip_cksum_hdr_in(_m, _l) \
+ ip_cksum_hdr_dir(_m, _l, 0)
+#define ip_cksum_hdr_out(_m, _l) \
+ ip_cksum_hdr_dir(_m, _l, 1)
+
+#define in_cksum_hdr(_ip) \
+ (~b_sum16(_ip, sizeof (struct ip)) & 0xffff)
+
+#define in_cksum_offset(_m, _o) \
+ ((void) in_finalize_cksum(_m, _o, CSUM_DELAY_IP))
+#define in_delayed_cksum(_m) \
+ ((void) in_finalize_cksum(_m, 0, CSUM_DELAY_DATA))
+#define in_delayed_cksum_offset(_m, _o) \
+ ((void) in_finalize_cksum(_m, _o, CSUM_DELAY_DATA))
#define in_hosteq(s, t) ((s).s_addr == (t).s_addr)
#define in_nullhost(x) ((x).s_addr == INADDR_ANY)
#define in_allhosts(x) ((x).s_addr == htonl(INADDR_ALLHOSTS_GROUP))
+#define SIN(s) ((struct sockaddr_in *)(void *)s)
+#define satosin(sa) SIN(sa)
+#define sintosa(sin) ((struct sockaddr *)(void *)(sin))
+#define SINIFSCOPE(s) ((struct sockaddr_inifscope *)(void *)(s))
+#endif /* BSD_KERNEL_PRIVATE */
+
+#ifdef KERNEL_PRIVATE
+/* exported for ApplicationFirewall */
+extern int in_localaddr(struct in_addr);
+extern int inaddr_local(struct in_addr);
+
+extern char *inet_ntoa(struct in_addr);
+extern char *inet_ntoa_r(struct in_addr ina, char *buf,
+ size_t buflen);
+extern int inet_pton(int af, const char *, void *);
#endif /* KERNEL_PRIVATE */
+
#define MAX_IPv4_STR_LEN 16
#define MAX_IPv6_STR_LEN 64
-extern const char *inet_ntop(int, const void *, char *, socklen_t); /* in libkern */
+extern int inet_aton(const char *, struct in_addr *); /* in libkern */
+extern const char *inet_ntop(int, const void *, char *, socklen_t); /* in libkern*/
#endif /* KERNEL */
-#ifndef KERNEL
+#ifndef KERNEL
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
__BEGIN_DECLS
int bindresvport(int, struct sockaddr_in *);
int bindresvport_sa(int, struct sockaddr *);
__END_DECLS
#endif
-#endif
-
+#endif /* !KERNEL */
#endif /* _NETINET_IN_H_ */