getifaddrs, freeifaddrs -- get interface addresses


#include <ifaddrs.h>

int getifaddrs(struct ifaddrs ** ifap);

void freeifaddrs(struct ifaddrs * ifa);


The getifaddrs() function creates a linked list of structures describing the network interfaces of the local system. The address of the first item is stored in memory pointed to by ifap. The data returned is dynamically allocated, and should be freed using freeifaddrs().

The list consists of structures of type ifaddrs (see Data Definitions above).

Return Value

On success, getifaddrs() returns zero; on error, -1 is returned, and errno is set appropriately.


getifaddrs() may fail and set errno for any of the errors specified for socket(), bind(), getsockname(), recvmsg(), sendto(), malloc(), or realloc().

See Also

bind(), getsockname(), socket().