GetUnicastAddresses
Retrieves a list of unicast addresses associated with the local computer.
Syntax
IP_STATUS GetUnicastAddresses(
_Out_ PMIB_UNICASTADDRESS_TABLE *Table
);
Parameters
Table-
A pointer to a
MIB_UNICASTADDRESS_TABLEstructure. This structure contains information about the unicast addresses on the local computer. The memory for this structure is allocated by the caller and must be freed usingFreeMibTable.
Return Value
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is one of the following error codes:
| Return Code | Description |
|---|---|
ERROR_INVALID_PARAMETER |
An invalid parameter was passed to the function. |
ERROR_NOT_SUPPORTED |
The function is not supported on the operating system. |
ERROR_NOT_ENOUGH_MEMORY |
Not enough memory is available to complete the operation. |
Remarks
The GetUnicastAddresses function retrieves a list of unicast IP addresses configured on the local computer. This includes IPv4 and IPv6 addresses.
The unicast addresses are returned in a MIB_UNICASTADDRESS_TABLE structure. This structure contains an array of MIB_UNICASTADDRESS_ROW structures, each representing a unicast address.
It is important to free the memory allocated for the Table parameter using the FreeMibTable function when it is no longer needed to prevent memory leaks.
Requirements
| Console | Client | Server |
|---|---|---|
| Windows Vista [desktop apps only] | Windows Vista [desktop apps only] | Windows Server 2008 [desktop apps only] |
| Header | iprtrmib.h (include Iphlpapi.h) |
|---|---|
| Library | Iphlpapi.lib |
| DLL | Iphlpapi.dll |
MIB_UNICASTADDRESS_TABLE Structure
Represents the table of unicast IP addresses on the local computer.
typedef struct _MIB_UNICASTADDRESS_TABLE {
DWORD NumEntries;
_Field_size_(NumEntries)
MIB_UNICASTADDRESS_ROW Table[ANYSIZE_ARRAY];
} MIB_UNICASTADDRESS_TABLE, *PMIB_UNICASTADDRESS_TABLE;
MIB_UNICASTADDRESS_ROW Structure
Represents a unicast IP address entry.
typedef struct _MIB_UNICASTADDRESS_ROW {
NET_IFINDEX InterfaceIndex;
ADDRESS_FAMILY AddressFamily;
union {
SOCKADDR_IN Ipv4;
SOCKADDR_IN6 Ipv6;
};
_If_(AddressFamily == AF_INET)
IP_PREFIX_ORIGIN PrefixOrigin;
IP_SUFFIX_ORIGIN SuffixOrigin;
IP_DAD_STATE OnLinkPrefixOrigin;
IP_DAD_STATE PreferredLifetime;
IP_DAD_STATE ValidLifetime;
ULONG SkipPrefixLength;
} MIB_UNICASTADDRESS_ROW, *PMIB_UNICASTADDRESS_ROW;