Use Linux rtnetlink’s RTM_GETADDR message to retrieve interface address records, then match the returned records to the IP address you need. The request can be limited by address family and, if known, interface index, but the kernel defines it as a dump rather than an exact-address lookup.
What RTM_GETADDR returns
RTM_GETADDR is the rtnetlink operation for getting IP address information associated with network interfaces. Rtnetlink communicates with Linux networking subsystems over a NETLINK_ROUTE socket. The Linux manual describes the operation as: “Add, remove, or receive information about an IP address associated with an interface.” See rtnetlink(7).
As an Amazon Associate I earn from qualifying purchases.
Each address record begins with an ifaddrmsg header containing the address family, prefix length, flags, scope, and interface index. IPv4 records use AF_INET; IPv6 records use AF_INET6. The reply may also include attributes such as IFA_ADDRESS, IFA_LOCAL, IFA_LABEL, and IFA_CACHEINFO.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsCan the request select one exact address?
Not according to the documented get-address request attributes. The kernel’s rt-addr family specification describes getaddr as a dump operation and lists ifa-index as a request attribute; it does not list an exact-address selector. To find one IP, receive the relevant records and compare their address attributes with the target.
#1 Best Overall
- Used Book in Good Condition
Retrieve and match an address
- Open a Netlink socket. Use protocol
NETLINK_ROUTEto communicate with the Linux routing subsystem. - Build an
RTM_GETADDRrequest. Set the address family in theifaddrmsgheader toAF_INETorAF_INET6, according to the target IP. - Optionally scope the request to an interface. If you know the interface’s numeric index, set
ifa_index. The kernel specification listsifa-indexas a get-address request filter; without it, leave the interface unspecified. - Receive and parse the dump. Treat the response as a set of address records, not a single-address result. Parse each record’s header and attributes using the APIs provided by your Netlink library, if applicable.
- Match the target address. Compare it with the appropriate address attribute in each record. Check whether your use case calls for
IFA_LOCALorIFA_ADDRESS; the two can differ when local and peer/interface addresses have distinct meanings. - Read any needed metadata. A matching record can also provide prefix length, scope, flags, interface index, label, and cache information.
This is the protocol-level procedure, not a library-specific code sample. The cited documentation does not validate particular wrapper APIs or their signatures, which vary by library and version.
Choose the address attribute deliberately
IFA_LOCAL represents the local address, while IFA_ADDRESS represents the address associated with the interface record. In configurations where a local endpoint and a peer or interface address differ, matching the wrong attribute can return the wrong result for your purpose. Inspect the semantics required by the caller rather than assuming the two fields are interchangeable.
Read cache lifetimes when needed
IFA_CACHEINFO carries address lifetime information. Its preferred and valid lifetime values are remaining seconds; timestamps are in centiseconds. UINT32_MAX denotes an infinite lifetime. Use these fields when the caller needs lifetime metadata, rather than treating a retrieved address as necessarily permanent.
Recommended Free Tools
What this query does not establish
- It does not perform a route lookup.
RTM_GETADDRreports addresses configured on interfaces. Asking which path Linux would use to reach a destination is a separate route operation. - It does not prove reachability. A matching record establishes address configuration metadata, not that packets can successfully reach or leave that address.
- It is Linux-specific. The rtnetlink manual identifies rtnetlink as a Linux feature introduced in Linux 2.2; these request and reply details should not be assumed to apply to other operating systems.
- Do not treat attributes as casually packed fields. The manual directs callers to manipulate routing attributes with the
RTA_*macros or libnetlink rather than relying on assumed raw layouts.
When a command-line view is enough
If you only need to inspect addresses interactively, a higher-level utility such as ip address may be more convenient. Use RTM_GETADDR when an application needs structured address records and is prepared to parse the dump, handle matching, and manage Netlink responses. The cited kernel and manual documentation defines the interface, but does not specify version-dependent command output or a particular library’s API.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




