Sockets Library Functions getifaddrs(3SOCKET)
NAME
getifaddrs, freeifaddrs - get interface addresses
SYNOPSIS
cc [ flag... ] file ... -lsocket -lnsl [ library ... ]
#include
#include
#include
int getifaddrs(struct ifaddrs **ifap);void freeifaddrs(struct ifaddrs *ifp);
DESCRIPTION
The getifaddrs() function stores a reference to a linked list of network interface addresses on the local machine in the memory referenced by ifap. The list consists of ifaddrs structures, as defined in the include file. Each element of the list describes one network interface address. The caller can process each ifaddrs structure in this list by following the ifa_next pointer, until a null pointer is
encountered. struct ifaddrs {struct ifaddrs *ifa_next; /* next structure in linked list*/
char *ifa_name; /* Interface name */
uint64_t ifa_flags; /* Interface flags (if_tcp(7P)) */
struct sockaddr *ifa_addr; /* Interface address */
struct sockaddr *ifa_netmask; /* Interface netmask */
union { /* Interface broadcast address */struct sockaddr *ifa_dstaddr;
/* P2P interface destination */struct sockaddr *ifa_broadaddr;
} ifa_ifu;
void *ifa_data; /* Address specific data (unused) */
};#ifndef ifa_broadaddr
#define ifa_broadaddr ifa_ifu.ifu_broadaddr
#endif
#ifndef ifa_dstaddr
#define ifa_dstaddr ifa_ifu.ifu_dstaddr
#endif
The ifa_name member contains the interface name.
SunOS 5.11 Last change: 10 May 2010 1
Sockets Library Functions getifaddrs(3SOCKET)The ifa_flags member contains the interface flags.
The ifa_addr member references the address of the interface.
(The sa_family member of the ifa_addr member should be con-
sulted to determine the format of the ifa_addr address.)
The ifa_netmask member references the netmask associated
with ifa_addr, if one is set, otherwise it is NULL.
The ifa_broadaddr member, which should only be referenced
for non-P2P interfaces, references the broadcast address
associated with ifa_addr, if one exists, otherwise it is
NULL.The ifa_dstaddr member references the destination address on
a P2P inter face, if one exists, otherwise it is NULL.The ifa_data member is currently unused.
The data returned by getifaddrs() is dynamically allocatedand should be freed using freeifaddrs() when no longer
needed.RETURN VALUES
The getifaddrs() function returns the value 0 if successful;otherwise -1 is returned and errno is set to indicate the
error.ERRORS
The getifaddrs() function may fail and set errno for any of the errors specified for ioctl(2), socket(3SOCKET), and malloc(3C).ATTRIBUTES
See attributes(5) for descriptions of the following attri-
butes:SunOS 5.11 Last change: 10 May 2010 2
Sockets Library Functions getifaddrs(3SOCKET)____________________________________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|_____________________________|_____________________________|
| Interface Stability | Committed ||_____________________________|_____________________________|
| MT-Level | MT-Safe |
|_____________________________|_____________________________|
SEE ALSO
ipadm(1M), ifconfig(1M), ioctl(2), malloc(3C),socket(3SOCKET), if_tcp(7P), attributes(5)
SunOS 5.11 Last change: 10 May 2010 3