#ifndef _NETINET_IN_H_
#define _NETINET_IN_H_
#include <sys/featuretest.h>
#include <machine/int_types.h>
#ifndef _BSD_UINT8_T_
typedef __uint8_t uint8_t;
#define _BSD_UINT8_T_
#endif
#ifndef _BSD_UINT32_T_
typedef __uint32_t uint32_t;
#define _BSD_UINT32_T_
#endif
#include <sys/ansi.h>
#ifndef in_addr_t
typedef __in_addr_t in_addr_t;
#define in_addr_t __in_addr_t
#endif
#ifndef in_port_t
typedef __in_port_t in_port_t;
#define in_port_t __in_port_t
#endif
#ifndef sa_family_t
typedef __sa_family_t sa_family_t;
#define sa_family_t __sa_family_t
#endif
#define IPPROTO_IP 0
#define IPPROTO_HOPOPTS 0
#define IPPROTO_ICMP 1
#define IPPROTO_IGMP 2
#define IPPROTO_GGP 3
#define IPPROTO_IPV4 4
#define IPPROTO_IPIP 4
#define IPPROTO_TCP 6
#define IPPROTO_EGP 8
#define IPPROTO_PUP 12
#define IPPROTO_UDP 17
#define IPPROTO_IDP 22
#define IPPROTO_TP 29
#define IPPROTO_DCCP 33
#define IPPROTO_IPV6 41
#define IPPROTO_ROUTING 43
#define IPPROTO_FRAGMENT 44
#define IPPROTO_RSVP 46
#define IPPROTO_GRE 47
#define IPPROTO_ESP 50
#define IPPROTO_AH 51
#define IPPROTO_MOBILE 55
#define IPPROTO_IPV6_ICMP 58
#define IPPROTO_ICMPV6 58
#define IPPROTO_NONE 59
#define IPPROTO_DSTOPTS 60
#define IPPROTO_EON 80
#define IPPROTO_ETHERIP 97
#define IPPROTO_ENCAP 98
#define IPPROTO_PIM 103
#define IPPROTO_IPCOMP 108
#define IPPROTO_VRRP 112
#define IPPROTO_CARP 112
#define IPPROTO_L2TP 115
#define IPPROTO_SCTP 132
#define IPPROTO_PFSYNC 240
#define IPPROTO_RAW 255
#define IPPROTO_MAX 256
#define IPPROTO_DONE 257
#define CTL_IPPROTO_IPSEC 258
#define IPPORT_RESERVED 1024
#define IPPORT_ANONMIN 49152
#define IPPORT_ANONMAX 65535
#define IPPORT_RESERVEDMIN 600
#define IPPORT_RESERVEDMAX (IPPORT_RESERVED-1)
struct in_addr {
in_addr_t s_addr;
};
#ifdef __CTASSERT
__CTASSERT(sizeof(struct in_addr) == 4);
#endif
#ifdef _KERNEL
#define __IPADDR(x) ((uint32_t) htonl((uint32_t)(x)))
#else
#define __IPADDR(x) ((uint32_t)(x))
#endif
#define IN_CLASSA(i) (((uint32_t)(i) & __IPADDR(0x80000000)) == \
__IPADDR(0x00000000))
#define IN_CLASSA_NET __IPADDR(0xff000000)
#define IN_CLASSA_NSHIFT 24
#define IN_CLASSA_HOST __IPADDR(0x00ffffff)
#define IN_CLASSA_MAX 128
#define IN_CLASSB(i) (((uint32_t)(i) & __IPADDR(0xc0000000)) == \
__IPADDR(0x80000000))
#define IN_CLASSB_NET __IPADDR(0xffff0000)
#define IN_CLASSB_NSHIFT 16
#define IN_CLASSB_HOST __IPADDR(0x0000ffff)
#define IN_CLASSB_MAX 65536
#define IN_CLASSC(i) (((uint32_t)(i) & __IPADDR(0xe0000000)) == \
__IPADDR(0xc0000000))
#define IN_CLASSC_NET __IPADDR(0xffffff00)
#define IN_CLASSC_NSHIFT 8
#define IN_CLASSC_HOST __IPADDR(0x000000ff)
#define IN_CLASSD(i) (((uint32_t)(i) & __IPADDR(0xf0000000)) == \
__IPADDR(0xe0000000))
#define IN_CLASSD_NET __IPADDR(0xf0000000)
#define IN_CLASSD_NSHIFT 28
#define IN_CLASSD_HOST __IPADDR(0x0fffffff)
#define IN_MULTICAST(i) IN_CLASSD(i)
#define IN_EXPERIMENTAL(i) (((uint32_t)(i) & __IPADDR(0xf0000000)) == \
__IPADDR(0xf0000000))
#define IN_BADCLASS(i) (((uint32_t)(i) & __IPADDR(0xf0000000)) == \
__IPADDR(0xf0000000))
#define IN_LINKLOCAL(i) (((uint32_t)(i) & __IPADDR(0xffff0000)) == \
__IPADDR(0xa9fe0000))
#define IN_PRIVATE(i) ((((uint32_t)(i) & __IPADDR(0xff000000)) == \
__IPADDR(0x0a000000)) || \
(((uint32_t)(i) & __IPADDR(0xfff00000)) == \
__IPADDR(0xac100000)) || \
(((uint32_t)(i) & __IPADDR(0xffff0000)) == \
__IPADDR(0xc0a80000)))
#define IN_LOCAL_GROUP(i) (((uint32_t)(i) & __IPADDR(0xffffff00)) == \
__IPADDR(0xe0000000))
#define IN_ANY_LOCAL(i) (IN_LINKLOCAL(i) || IN_LOCAL_GROUP(i))
#define INADDR_ANY __IPADDR(0x00000000)
#define INADDR_LOOPBACK __IPADDR(0x7f000001)
#define INADDR_BROADCAST __IPADDR(0xffffffff)
#define INADDR_NONE __IPADDR(0xffffffff)
#define INADDR_UNSPEC_GROUP __IPADDR(0xe0000000)
#define INADDR_ALLHOSTS_GROUP __IPADDR(0xe0000001)
#define INADDR_ALLRTRS_GROUP __IPADDR(0xe0000002)
#define INADDR_CARP_GROUP __IPADDR(0xe0000012)
#define INADDR_MAX_LOCAL_GROUP __IPADDR(0xe00000ff)
#define IN_LOOPBACKNET 127
#define IN_RFC3021_MASK __IPADDR(0xfffffffe)
struct sockaddr_in {
uint8_t sin_len;
sa_family_t sin_family;
in_port_t sin_port;
struct in_addr sin_addr;
__int8_t sin_zero[8];
};
#define INET_ADDRSTRLEN 16
struct ip_opts {
struct in_addr ip_dst;
#if defined(__cplusplus)
__int8_t Ip_opts[40];
#else
__int8_t ip_opts[40];
#endif
};
#define IP_OPTIONS 1
#define IP_HDRINCL 2
#define IP_TOS 3
#define IP_TTL 4
#define IP_RECVOPTS 5
#define IP_RECVRETOPTS 6
#define IP_RECVDSTADDR 7
#define IP_RETOPTS 8
#define IP_MULTICAST_IF 9
#define IP_MULTICAST_TTL 10
#define IP_MULTICAST_LOOP 11
#define IP_ADD_MEMBERSHIP 12
#define IP_DROP_MEMBERSHIP 13
#define IP_PORTALGO 18
#define IP_PORTRANGE 19
#define IP_RECVIF 20
#define IP_ERRORMTU 21
#define IP_IPSEC_POLICY 22
#define IP_RECVTTL 23
#define IP_MINTTL 24
#define IP_PKTINFO 25
#define IP_RECVPKTINFO 26
#define IP_BINDANY 27
#define IP_SENDSRCADDR IP_RECVDSTADDR
struct in_pktinfo {
struct in_addr ipi_addr;
unsigned int ipi_ifindex;
};
#define ipi_spec_dst ipi_addr
#define IP_DEFAULT_MULTICAST_TTL 1
#define IP_DEFAULT_MULTICAST_LOOP 1
#define IP_MAX_MEMBERSHIPS 20
struct ip_mreq {
struct in_addr imr_multiaddr;
struct in_addr imr_interface;
};
#define IP_PORTRANGE_DEFAULT 0
#define IP_PORTRANGE_HIGH 1
#define IP_PORTRANGE_LOW 2
#if defined(_NETBSD_SOURCE)
#define IPCTL_FORWARDING 1
#define IPCTL_SENDREDIRECTS 2
#define IPCTL_DEFTTL 3
#define IPCTL_FORWSRCRT 5
#define IPCTL_DIRECTEDBCAST 6
#define IPCTL_ALLOWSRCRT 7
#define IPCTL_SUBNETSARELOCAL 8
#define IPCTL_MTUDISC 9
#define IPCTL_ANONPORTMIN 10
#define IPCTL_ANONPORTMAX 11
#define IPCTL_MTUDISCTIMEOUT 12
#define IPCTL_MAXFLOWS 13
#define IPCTL_HOSTZEROBROADCAST 14
#define IPCTL_GIF_TTL 15
#define IPCTL_LOWPORTMIN 16
#define IPCTL_LOWPORTMAX 17
#define IPCTL_MAXFRAGPACKETS 18
#define IPCTL_GRE_TTL 19
#define IPCTL_CHECKINTERFACE 20
#define IPCTL_IFQ 21
#define IPCTL_RANDOMID 22
#define IPCTL_LOOPBACKCKSUM 23
#define IPCTL_STATS 24
#define IPCTL_DAD_COUNT 25
#endif
#define __KAME_NETINET_IN_H_INCLUDED_
#include <netinet6/in6.h>
#undef __KAME_NETINET_IN_H_INCLUDED_
#ifdef _KERNEL
#include <sys/psref.h>
static __inline u_int16_t __unused
in_cksum_phdr(u_int32_t src, u_int32_t dst, u_int32_t lenproto)
{
u_int32_t sum;
sum = lenproto +
(u_int16_t)(src >> 16) +
(u_int16_t)(src ) +
(u_int16_t)(dst >> 16) +
(u_int16_t)(dst );
sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum );
if (sum > 0xffff)
sum -= 0xffff;
return (sum);
}
static __inline u_int16_t __unused
in_cksum_addword(u_int16_t a, u_int16_t b)
{
u_int32_t sum = a + b;
if (sum > 0xffff)
sum -= 0xffff;
return (sum);
}
extern struct in_addr zeroin_addr;
extern u_char ip_protox[];
extern const struct sockaddr_in in_any;
int in_broadcast(struct in_addr, struct ifnet *);
int in_direct(struct in_addr, struct ifnet *);
int in_canforward(struct in_addr);
int cpu_in_cksum(struct mbuf *, int, int, uint32_t);
int in_cksum(struct mbuf *, int);
int in4_cksum(struct mbuf *, u_int8_t, int, int);
int in_localaddr(struct in_addr);
void in_socktrim(struct sockaddr_in *);
void in_len2mask(struct in_addr *, u_int);
void in_if_link_up(struct ifnet *);
void in_if_link_down(struct ifnet *);
void in_if_up(struct ifnet *);
void in_if_down(struct ifnet *);
void in_if_link_state_change(struct ifnet *, int);
struct route;
struct ip_moptions;
struct in_ifaddr *in_selectsrc(struct sockaddr_in *,
struct route *, int, struct ip_moptions *, int *, struct psref *);
struct ip;
int in_tunnel_validate(const struct ip *, struct in_addr, struct in_addr);
#define in_hosteq(s,t) ((s).s_addr == (t).s_addr)
#define in_nullhost(x) ((x).s_addr == INADDR_ANY)
#define satosin(sa) ((struct sockaddr_in *)(sa))
#define satocsin(sa) ((const struct sockaddr_in *)(sa))
#define sintosa(sin) ((struct sockaddr *)(sin))
#define sintocsa(sin) ((const struct sockaddr *)(sin))
#define ifatoia(ifa) ((struct in_ifaddr *)(ifa))
int sockaddr_in_cmp(const struct sockaddr *, const struct sockaddr *);
const void *sockaddr_in_const_addr(const struct sockaddr *, socklen_t *);
void *sockaddr_in_addr(struct sockaddr *, socklen_t *);
static __inline void
sockaddr_in_init1(struct sockaddr_in *sin, const struct in_addr *addr,
in_port_t port)
{
sin->sin_port = port;
sin->sin_addr = *addr;
memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
}
static __inline void
sockaddr_in_init(struct sockaddr_in *sin, const struct in_addr *addr,
in_port_t port)
{
sin->sin_family = AF_INET;
sin->sin_len = sizeof(*sin);
sockaddr_in_init1(sin, addr, port);
}
static __inline struct sockaddr *
sockaddr_in_alloc(const struct in_addr *addr, in_port_t port, int flags)
{
struct sockaddr *sa;
sa = sockaddr_alloc(AF_INET, sizeof(struct sockaddr_in), flags);
if (sa == NULL)
return NULL;
sockaddr_in_init1(satosin(sa), addr, port);
return sa;
}
#endif
#if defined(_KERNEL) || defined(_TEST)
int in_print(char *, size_t, const struct in_addr *);
#define IN_PRINT(b, a) (in_print((b), sizeof(b), a), (b))
int sin_print(char *, size_t, const void *);
#endif
#endif