Updated: April 19, 2023 |
Get a network interface address
#include <sys/types.h> #include <sys/socket.h> #include <ifaddrs.h> int getifaddrs( struct ifaddrs ** ifap );
The getifaddrs() function stores a reference to a linked list of the network interfaces on the local machine in the memory referenced by ifap.
The data returned by getifaddrs() is dynamically allocated; you should free it by calling freeifaddrs() when you no longer need it.
The getifaddrs() function may fail and set errno for any of the errors specified by ioctl(), malloc(), socket(), and sysctl().
It can also set errno to ENOMEM if the system is out of memory, or the interface list was growing while getifaddrs() was executing. Calling the function again when the interface list is stable can return 0 (success).
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |