#include <netinet/in.h>
netinet/in.h
macroIPPROTO_DIVERT
253-254: Experimentation and testing; 255: Reserved (RFC3692)
BSD Private, local use, namespace incursion
#define IPPROTO_DIVERT 254
divert pseudo-protocol
macroIPPROTO_MAX
#define IPPROTO_MAX 256
macroIPPROTO_DONE
last return value of *_input(), meaning "all job for this pkt is done".
#define IPPROTO_DONE 257
macroIPPORT_RESERVED
Ports < IPPORT_RESERVED are reserved for
privileged processes (e.g. root). (IP_PORTRANGE_LOW)
Ports > IPPORT_USERRESERVED are reserved
for servers, not necessarily privileged. (IP_PORTRANGE_DEFAULT)
#define IPPORT_RESERVED __DARWIN_IPPORT_RESERVED
macroIPPORT_USERRESERVED
#define IPPORT_USERRESERVED 5000
macroIPPORT_HIFIRSTAUTO
Default local port range to use by setting IP_PORTRANGE_HIGH
#define IPPORT_HIFIRSTAUTO 49152
macroIPPORT_HILASTAUTO
#define IPPORT_HILASTAUTO 65535
macroIPPORT_RESERVEDSTART
Scanning for a free reserved port return a value below IPPORT_RESERVED,
but higher than IPPORT_RESERVEDSTART. Traditionally the start value was
512, but that conflicts with some well-known-services that firewalls may
have a fit if we use.
#define IPPORT_RESERVEDSTART 600
macroINADDR_ANY
Definitions of bits in internet address integers.
On subnets, the decomposition of addresses to host and net parts
is done according to subnet mask, not the masks here.
#define INADDR_ANY (u_int32_t)0x00000000
macroIN_CLASSA_NET
#define IN_CLASSA_NET 0xff000000
macroIN_CLASSA_NSHIFT
#define IN_CLASSA_NSHIFT 24
macroIN_CLASSA_HOST
#define IN_CLASSA_HOST 0x00ffffff
macroIN_CLASSA_MAX
#define IN_CLASSA_MAX 128
macroIN_CLASSB_NET
#define IN_CLASSB_NET 0xffff0000
macroIN_CLASSB_NSHIFT
#define IN_CLASSB_NSHIFT 16
macroIN_CLASSB_HOST
#define IN_CLASSB_HOST 0x0000ffff
macroIN_CLASSB_MAX
#define IN_CLASSB_MAX 65536
macroIN_CLASSC_NET
#define IN_CLASSC_NET 0xffffff00
macroIN_CLASSC_NSHIFT
#define IN_CLASSC_NSHIFT 8
macroIN_CLASSC_HOST
#define IN_CLASSC_HOST 0x000000ff
macroIN_MULTICAST
#define IN_MULTICAST(i) IN_CLASSD(i)
macroIN_EXPERIMENTAL
#define IN_EXPERIMENTAL(i) (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
macroIN_BADCLASS
#define IN_BADCLASS(i) (((u_int32_t)(i) & 0xf0000000) == 0xf0000000)
macroINADDR_LOOPBACK
#define INADDR_LOOPBACK (u_int32_t)0x7f000001
macroIN_LINKLOCAL
#define IN_LINKLOCAL(i) (((u_int32_t)(i) & IN_CLASSB_NET) == IN_LINKLOCALNETNUM)
macroIN_LOOPBACK
#define IN_LOOPBACK(i) (((u_int32_t)(i) & 0xff000000) == 0x7f000000)
macroIN_ZERONET
#define IN_ZERONET(i) (((u_int32_t)(i) & 0xff000000) == 0)
macroIN_PRIVATE
#define IN_PRIVATE(i) ((((u_int32_t)(i) & 0xff000000) == 0x0a000000) || (((u_int32_t)(i) & 0xfff00000) == 0xac100000) || (((u_int32_t)(i) & 0xffff0000) == 0xc0a80000))
macroIN_LOCAL_GROUP
#define IN_LOCAL_GROUP(i) (((u_int32_t)(i) & 0xffffff00) == 0xe0000000)
macroIN_ANY_LOCAL
#define IN_ANY_LOCAL(i) (IN_LINKLOCAL(i) || IN_LOCAL_GROUP(i))
structsockaddr_in
Socket address, internet style.
| __uint8_t | sin_len | |
| sa_family_t | sin_family | |
| in_port_t | sin_port | |
| struct in_addr | sin_addr | |
| char[8] | sin_zero |
macroIN_ARE_ADDR_EQUAL
#define IN_ARE_ADDR_EQUAL(a, b) (bcmp(&(a)->s_addr, &(b)->s_addr, sizeof (struct in_addr)) == 0)
macroINET_ADDRSTRLEN
#define INET_ADDRSTRLEN 16
structip_opts
Structure used to describe IP options.
Used to store options internally, to pass them to a process,
or to restore options retrieved earlier.
The ip_dst is used for the first-hop gateway when using a source route
(this gets put into the header proper).
| struct in_addr | ip_dst | first hop, 0 w/o src rt |
| char[40] | ip_opts | actually variable in size |
macroIP_OPTIONS
Options for use with [gs]etsockopt at the IP level.
First word of comment is data type; bool is stored in int.
#define IP_OPTIONS 1
buf/ip_opts; set/get IP options
macroIP_OLD_FW_ADD
These older firewall socket option codes are maintained for backward compatibility.
#define IP_OLD_FW_ADD 50
add a firewall rule to chain
macroIP_TRAFFIC_MGT_BACKGROUND
#define IP_TRAFFIC_MGT_BACKGROUND 65
int*; get background IO flags; set background IO
macroIP_ADD_SOURCE_MEMBERSHIP
IPv4 Source Filter Multicast API [RFC3678]
#define IP_ADD_SOURCE_MEMBERSHIP 70
join a source-specific group
macroIP_MSFILTER
The following option is private; do not use it from user applications.
#define IP_MSFILTER 74
set/get filter list
macroMCAST_JOIN_GROUP
Protocol Independent Multicast API [RFC3678]
#define MCAST_JOIN_GROUP 80
join an any-source group
macroIP_DEFAULT_MULTICAST_TTL
Defaults and limits for options
#define IP_DEFAULT_MULTICAST_TTL 1
normally limit m'casts to 1 hop
macroIP_MIN_MEMBERSHIPS
The imo_membership vector for each socket is now dynamically allocated at
run-time, bounded by USHRT_MAX, and is reallocated when needed, sized
according to a power-of-two increment.
#define IP_MIN_MEMBERSHIPS 31
macroIP_MAX_MEMBERSHIPS
#define IP_MAX_MEMBERSHIPS 4095
macroIP_MAX_GROUP_SRC_FILTER
Default resource limits for IPv4 multicast source filtering.
These may be modified by sysctl.
#define IP_MAX_GROUP_SRC_FILTER 512
sources per group
structip_mreq
Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
| struct in_addr | imr_multiaddr | IP multicast address of group |
| struct in_addr | imr_interface | local IP address of interface |
structip_mreqn
Modified argument structure for IP_MULTICAST_IF, obtained from Linux.
This is used to specify an interface index for multicast sends, as
the IPv4 legacy APIs do not support this (unless IP_SENDIF is available).
| struct in_addr | imr_multiaddr | IP multicast address of group |
| struct in_addr | imr_address | local IP address of interface |
| int | imr_ifindex | Interface index; cast to uint32_t |
structip_mreq_source
Argument structure for IPv4 Multicast Source Filter APIs. [RFC3678]
| struct in_addr | imr_multiaddr | IP multicast address of group |
| struct in_addr | imr_sourceaddr | IP address of source |
| struct in_addr | imr_interface | local IP address of interface |
structgroup_req
Argument structures for Protocol-Independent Multicast Source
Filter APIs. [RFC3678]
| uint32_t | gr_interface | interface index |
| struct sockaddr_storage | gr_group | group address |
structgroup_source_req
| uint32_t | gsr_interface | interface index |
| struct sockaddr_storage | gsr_group | group address |
| struct sockaddr_storage | gsr_source | source address |
struct__msfilterreq
The following structure is private; do not use it from user applications.
It is used to communicate IP_MSFILTER/IPV6_MSFILTER information between
the RFC 3678 libc functions and the kernel.
| uint32_t | msfr_ifindex | interface index |
| uint32_t | msfr_fmode | filter mode for group |
| uint32_t | msfr_nsrcs | # of sources in msfr_srcs |
| uint32_t | __msfr_align | |
| struct sockaddr_storage | msfr_group | group address |
| struct sockaddr_storage * | msfr_srcs |
functionsetipv4sourcefilter
__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3) int setipv4sourcefilter( int, struct in_addr, struct in_addr, uint32_t, uint32_t, struct in_addr * )
Advanced (Full-state) APIs [RFC3678]
The RFC specifies uint_t for the 6th argument to [sg]etsourcefilter().
We use uint32_t here to be consistent.
functiongetipv4sourcefilter
__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 * )
functionsetsourcefilter
__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 * )
functiongetsourcefilter
__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 * )
macroMCAST_UNDEFINED
Filter modes; also used to represent per-socket filter mode internally.
#define MCAST_UNDEFINED 0
fmode: not yet defined
macroIP_PORTRANGE_DEFAULT
Argument for IP_PORTRANGE:
- which range to search when port is unspecified at bind() or connect()
#define IP_PORTRANGE_DEFAULT 0
default range
structin_pktinfo
IP_PKTINFO: Packet information (equivalent to RFC2292 sec 5 for IPv4)
This structure is used for
1) Receiving ancilliary data about the datagram if IP_PKTINFO sockopt is
set on the socket. In this case ipi_ifindex will contain the interface
index the datagram was received on, ipi_addr is the IP address the
datagram was received to.
2) Sending a datagram using a specific interface or IP source address.
if ipi_ifindex is set to non-zero when in_pktinfo is passed as
ancilliary data of type IP_PKTINFO, this will be used as the source
interface to send the datagram from. If ipi_ifindex is null, ip_spec_dst
will be used for the source address.
Note: if IP_BOUND_IF is set on the socket, ipi_ifindex in the ancillary
IP_PKTINFO option silently overrides the bound interface when it is
specified during send time.
| unsigned int | ipi_ifindex | send/recv interface index |
| struct in_addr | ipi_spec_dst | Local address |
| struct in_addr | ipi_addr | IP Header dst address |
macroIPPROTO_MAXID
Definitions for inet sysctl operations.
Third level is protocol number.
Fourth level is desired variable within that protocol.
#define IPPROTO_MAXID (IPPROTO_AH + 1)
don't list to IPPROTO_MAX
macroIPCTL_MAXID
#define IPCTL_MAXID 17
functionbindresvport
int bindresvport(int, struct sockaddr_in *)
man page · November 22, 1987
bindresvport(3) — bind a socket to a privileged IP portfunctionbindresvport_sa
int bindresvport_sa(int, struct sockaddr *)
man page · November 22, 1987
bindresvport_sa(3) — bind a socket to a privileged IP port