DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

How to Use RTM_GETADDR to Find Details for a Specific IP Address

RTM_GETADDR returns Linux interface address records as a dump. To retrieve details for one IP, scope by family and optional interface index, then match the appropriate reply attribute.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can 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.

Retrieve and match an address

  1. Open a Netlink socket. Use protocol NETLINK_ROUTE to communicate with the Linux routing subsystem.
  2. Build an RTM_GETADDR request. Set the address family in the ifaddrmsg header to AF_INET or AF_INET6, according to the target IP.
  3. Optionally scope the request to an interface. If you know the interface’s numeric index, set ifa_index. The kernel specification lists ifa-index as a get-address request filter; without it, leave the interface unspecified.
  4. 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.
  5. Match the target address. Compare it with the appropriate address attribute in each record. Check whether your use case calls for IFA_LOCAL or IFA_ADDRESS; the two can differ when local and peer/interface addresses have distinct meanings.
  6. 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What this query does not establish

  • It does not perform a route lookup. RTM_GETADDR reports 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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.