152a38012Sejakowatz /* in.h */ 24fc67516SDavid Reid 352a38012Sejakowatz #ifndef _NETINET_IN_H_ 452a38012Sejakowatz #define _NETINET_IN_H_ 552a38012Sejakowatz 60b5170a4Sbeveloper #include <sys/types.h> 74fc67516SDavid Reid #include <net/if.h> 8*42415555Sbeveloper #include <endian.h> 952a38012Sejakowatz 10*42415555Sbeveloper typedef unsigned short in_port_t; 11*42415555Sbeveloper typedef unsigned long in_addr_t; 12*42415555Sbeveloper 13*42415555Sbeveloper /* We can't include <ByteOrder.h> since we are a posix file, 14*42415555Sbeveloper * and we are not allowed to import all the BeOS types here. 15*42415555Sbeveloper */ 16*42415555Sbeveloper #ifndef htonl 17*42415555Sbeveloper extern unsigned long __swap_int32(unsigned long); /* private */ 18*42415555Sbeveloper extern unsigned short __swap_int16(unsigned short); /* private */ 19*42415555Sbeveloper #if BYTE_ORDER == LITTLE_ENDIAN 20*42415555Sbeveloper #define htonl(x) __swap_int32(x) 21*42415555Sbeveloper #define ntohl(x) __swap_int32(x) 22*42415555Sbeveloper #define htons(x) __swap_int16(x) 23*42415555Sbeveloper #define ntohs(x) __swap_int16(x) 24*42415555Sbeveloper #elif BYTE_ORDER == BIG_ENDIAN 25*42415555Sbeveloper #define htonl(x) (x) 26*42415555Sbeveloper #define ntohl(x) (x) 27*42415555Sbeveloper #define htons(x) (x) 28*42415555Sbeveloper #define ntohs(x) (x) 29*42415555Sbeveloper #else 30*42415555Sbeveloper #error Unknown byte order. 31*42415555Sbeveloper #endif 32*42415555Sbeveloper #endif 33*42415555Sbeveloper 340b5170a4Sbeveloper 3552a38012Sejakowatz /* Protocol definitions - add to as required... */ 3652a38012Sejakowatz enum { 3752a38012Sejakowatz IPPROTO_IP = 0, /* 0, IPv4 */ 3852a38012Sejakowatz IPPROTO_ICMP = 1, /* 1, ICMP (v4) */ 3952a38012Sejakowatz IPPROTO_IGMP = 2, /* 2, IGMP (group management) */ 4052a38012Sejakowatz IPPROTO_TCP = 6, /* 6, tcp */ 4152a38012Sejakowatz IPPROTO_UDP = 17, /* 17, UDP */ 4252a38012Sejakowatz IPPROTO_IPV6 = 41, /* 41, IPv6 in IPv6 */ 4352a38012Sejakowatz IPPROTO_ROUTING = 43, /* 43, Routing */ 4452a38012Sejakowatz IPPROTO_ICMPV6 = 58, /* 58, IPv6 ICMP */ 4552a38012Sejakowatz IPPROTO_ETHERIP = 97, /* 97, Ethernet in IPv4 */ 4652a38012Sejakowatz IPPROTO_RAW = 255 /* 255 */ 4752a38012Sejakowatz }; 4852a38012Sejakowatz 4952a38012Sejakowatz #define IPPROTO_MAX 256 5052a38012Sejakowatz 5152a38012Sejakowatz /* Port numbers... 5252a38012Sejakowatz * < IPPORT_RESERVED are privileged and should be 5352a38012Sejakowatz * accessible only by root 5452a38012Sejakowatz * > IPPORT_USERRESERVED are reserved for servers, though 5552a38012Sejakowatz * not requiring privileged status 5652a38012Sejakowatz */ 5752a38012Sejakowatz 5852a38012Sejakowatz #define IPPORT_RESERVED 1024 5952a38012Sejakowatz #define IPPORT_USERRESERVED 49151 6052a38012Sejakowatz 6152a38012Sejakowatz /* This is an IPv4 address structure. Why is it a structure? 6252a38012Sejakowatz * Historical reasons. 6352a38012Sejakowatz */ 6452a38012Sejakowatz struct in_addr { 6552a38012Sejakowatz in_addr_t s_addr; 6652a38012Sejakowatz }; 6752a38012Sejakowatz 6852a38012Sejakowatz /* 6952a38012Sejakowatz * IP Version 4 socket address. 7052a38012Sejakowatz */ 7152a38012Sejakowatz struct sockaddr_in { 7252a38012Sejakowatz uint8 sin_len; 7352a38012Sejakowatz uint8 sin_family; 7452a38012Sejakowatz uint16 sin_port; 7552a38012Sejakowatz struct in_addr sin_addr; 7652a38012Sejakowatz int8 sin_zero[8]; 7752a38012Sejakowatz }; 7852a38012Sejakowatz /* the address is therefore at sin_addr.s_addr */ 7952a38012Sejakowatz 8052a38012Sejakowatz /* 8152a38012Sejakowatz * Options for use with [gs]etsockopt at the IP level. 8252a38012Sejakowatz * First word of comment is data type; bool is stored in int. 8352a38012Sejakowatz */ 8452a38012Sejakowatz #define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */ 8552a38012Sejakowatz #define IP_HDRINCL 2 /* int; header is included with data */ 8652a38012Sejakowatz #define IP_TOS 3 /* int; IP type of service and preced. */ 8752a38012Sejakowatz #define IP_TTL 4 /* int; IP time to live */ 8852a38012Sejakowatz #define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */ 8952a38012Sejakowatz #define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */ 9052a38012Sejakowatz #define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */ 9152a38012Sejakowatz #define IP_RETOPTS 8 /* ip_opts; set/get IP options */ 9252a38012Sejakowatz #define IP_MULTICAST_IF 9 /* in_addr; set/get IP multicast i/f */ 9352a38012Sejakowatz #define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */ 9452a38012Sejakowatz #define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */ 9552a38012Sejakowatz #define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */ 9652a38012Sejakowatz #define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */ 9752a38012Sejakowatz 984fc67516SDavid Reid #ifdef _KERNEL_MODE 9952a38012Sejakowatz #define __IPADDR(x) ((uint32) htonl((uint32)(x))) 10052a38012Sejakowatz #else 10152a38012Sejakowatz #define __IPADDR(x) ((uint32)(x)) 10252a38012Sejakowatz #endif 10352a38012Sejakowatz 10452a38012Sejakowatz #define INADDR_ANY __IPADDR(0x00000000) 10552a38012Sejakowatz #define INADDR_LOOPBACK __IPADDR(0x7f000001) 10652a38012Sejakowatz #define INADDR_BROADCAST __IPADDR(0xffffffff) /* must be masked */ 10752a38012Sejakowatz 10852a38012Sejakowatz #define INADDR_UNSPEC_GROUP __IPADDR(0xe0000000) /* 224.0.0.0 */ 10952a38012Sejakowatz #define INADDR_ALLHOSTS_GROUP __IPADDR(0xe0000001) /* 224.0.0.1 */ 11052a38012Sejakowatz #define INADDR_ALLROUTERS_GROUP __IPADDR(0xe0000002) /* 224.0.0.2 */ 11152a38012Sejakowatz #define INADDR_MAX_LOCAL_GROUP __IPADDR(0xe00000ff) /* 224.0.0.255 */ 11252a38012Sejakowatz 11352a38012Sejakowatz #define IN_LOOPBACKNET 127 /* official! */ 11452a38012Sejakowatz 1154fc67516SDavid Reid #ifndef _KERNEL_MODE 11652a38012Sejakowatz #define INADDR_NONE __IPADDR(0xffffffff) 11752a38012Sejakowatz #endif 11852a38012Sejakowatz 11952a38012Sejakowatz #define IN_CLASSA(i) (((uint32)(i) & __IPADDR(0x80000000)) == \ 12052a38012Sejakowatz __IPADDR(0x00000000)) 12152a38012Sejakowatz #define IN_CLASSA_NET __IPADDR(0xff000000) 12252a38012Sejakowatz #define IN_CLASSA_NSHIFT 24 12352a38012Sejakowatz #define IN_CLASSA_HOST __IPADDR(0x00ffffff) 12452a38012Sejakowatz #define IN_CLASSA_MAX 128 12552a38012Sejakowatz 12652a38012Sejakowatz #define IN_CLASSB(i) (((uint32)(i) & __IPADDR(0xc0000000)) == \ 12752a38012Sejakowatz __IPADDR(0x80000000)) 12852a38012Sejakowatz #define IN_CLASSB_NET __IPADDR(0xffff0000) 12952a38012Sejakowatz #define IN_CLASSB_NSHIFT 16 13052a38012Sejakowatz #define IN_CLASSB_HOST __IPADDR(0x0000ffff) 13152a38012Sejakowatz #define IN_CLASSB_MAX 65536 13252a38012Sejakowatz 13352a38012Sejakowatz #define IN_CLASSC(i) (((uint32)(i) & __IPADDR(0xe0000000)) == \ 13452a38012Sejakowatz __IPADDR(0xc0000000)) 13552a38012Sejakowatz #define IN_CLASSC_NET __IPADDR(0xffffff00) 13652a38012Sejakowatz #define IN_CLASSC_NSHIFT 8 13752a38012Sejakowatz #define IN_CLASSC_HOST __IPADDR(0x000000ff) 13852a38012Sejakowatz 13952a38012Sejakowatz #define IN_CLASSD(i) (((uint32)(i) & __IPADDR(0xf0000000)) == \ 14052a38012Sejakowatz __IPADDR(0xe0000000)) 14152a38012Sejakowatz /* These ones aren't really net and host fields, but routing needn't know. */ 14252a38012Sejakowatz #define IN_CLASSD_NET __IPADDR(0xf0000000) 14352a38012Sejakowatz #define IN_CLASSD_NSHIFT 28 14452a38012Sejakowatz #define IN_CLASSD_HOST __IPADDR(0x0fffffff) 14552a38012Sejakowatz 14652a38012Sejakowatz #define IN_MULTICAST(i) IN_CLASSD(i) 14752a38012Sejakowatz 14852a38012Sejakowatz #define IN_EXPERIMENTAL(i) (((uint32)(i) & 0xf0000000) == 0xf0000000) 14952a38012Sejakowatz #define IN_BADCLASS(i) (((uint32)(i) & 0xf0000000) == 0xf0000000) 15052a38012Sejakowatz 15152a38012Sejakowatz #define IP_MAX_MEMBERSHIPS 20 15252a38012Sejakowatz 1534fc67516SDavid Reid #ifdef _KERNEL_MODE 15452a38012Sejakowatz /* some helpful macro's :) */ 15552a38012Sejakowatz #define in_hosteq(s,t) ((s).s_addr == (t).s_addr) 15652a38012Sejakowatz #define in_nullhost(x) ((x).s_addr == INADDR_ANY) 15752a38012Sejakowatz #define satosin(sa) ((struct sockaddr_in *)(sa)) 15852a38012Sejakowatz #define sintosa(sin) ((struct sockaddr *)(sin)) 15952a38012Sejakowatz 160*42415555Sbeveloper struct ifnet; // forward declaration 161*42415555Sbeveloper 16252a38012Sejakowatz /* Prototypes... */ 16352a38012Sejakowatz int in_broadcast (struct in_addr, struct ifnet *); 16452a38012Sejakowatz int in_canforward (struct in_addr); 16552a38012Sejakowatz int in_localaddr (struct in_addr); 16652a38012Sejakowatz void in_socktrim (struct sockaddr_in*); 167*42415555Sbeveloper /* uint16 in_cksum (struct mbuf *, int); */ 168*42415555Sbeveloper uint16 in_cksum(struct mbuf *m, int len, int off); 16952a38012Sejakowatz 1704fc67516SDavid Reid #endif /* _KERNEL_MODE */ 17152a38012Sejakowatz #endif /* NETINET_IN_H */ 172