netifaddrs
Netifaddrs refers to the linked list data structure used by the getifaddrs function on many Unix-like systems to describe network interfaces and their addresses. Programs can call getifaddrs to retrieve a complete listing of available interfaces and then iterate the resulting list. The memory is allocated by the system and must be released with freeifaddrs when it is no longer needed. The list may contain multiple entries for a single interface, representing different address families such as IPv4 and IPv6.
The data structure used is typically called struct ifaddrs. Its common fields include:
- ifa_next: pointer to the next entry in the linked list
- ifa_name: a string with the interface name (for example, “eth0” or “en0”)
- ifa_flags: interface flags (such as IFF_UP, IFF_LOOPBACK)
- ifa_addr: address for this entry (struct sockaddr)
- ifa_netmask: netmask for the address (struct sockaddr)
- ifa_broadaddr: broadcast address for broadcasting interfaces (struct sockaddr)
- ifa_dstaddr: destination address for point-to-point links (struct sockaddr)
- ifa_data: private data for per-interface information (void*)
Entries may include addresses for multiple families; the actual sockaddr structures typically need to be cast
Usage and portability: getifaddrs is available on many BSD-derived systems, Linux, and macOS, with the struct