Site map  

Socket structs

Some info on sockets. I keep looking for these, so I put them here.
Note: Stuff like family is AF_INET for IPv4 and AF_INET6 for IPv6.

struct addrinfo {
	int		 ai_flags;
	int		 ai_family;
	int		 ai_socktype;
	int		 ai_protocol;
	size_t		 ai_addrlen;
	struct sockaddr	*ai_addr;
	char		*ai_canonname;
	struct addrinfo	*ai_next;

struct ifaddrs {
	struct ifaddrs	*ifa_next;	//  Next item in list
	char		*ifa_name;	//  Name of interface
	unsigned int	 ifa_flags;	//  Flags from SIOCGIFFLAGS
	struct sockaddr	*ifa_addr;	//  Address of interface
	struct sockaddr	*ifa_netmask;	//  Netmask of interface
	union {
		struct sockaddr *ifu_broadaddr;	//  Broadcast address of interface
		struct sockaddr *ifu_dstaddr;	//  Point-to-point destination address
	} ifa_ifu;
	#define		 ifa_broadaddr	ifa_ifu.ifu_broadaddr
	#define		 ifa_dstaddr	ifa_ifu.ifu_dstaddr
        void		*ifa_data;	//  Address-specific data

struct sockaddr {
	sa_family_t	sa_family;
	char		sa_data[];	// Used to be 14 bytes

struct sockaddr_in {
	sa_family_t	sin_family;
	in_port_t	sin_port;
	struct in_addr	sin_addr;

struct in_addr {
	in_addr_t s_addr;		//  32-bit unsigned int

struct sockaddr_in6 {
	sa_family_t	sin6_family;
	in_port_t	sin6_port;
	uint32_t	sin6_flowinfo;
	struct in6_addr	sin6_addr;
	uint32_t	sin6_scope_id;

struct in6_addr {
	unsigned char   s6_addr[16];

An IPv4 address is an 32-bit unsigned int.
An IPv6 address is an array of 16 8-bit unsigned ints.

An IPv4 address in an above struct is network byte order. So that's high to low or big endian.