getaddrinfo
termKept in this browser · My desk
The socket API's resolver function: it turns a host name or address and a service name or port into the arguments needed to create and connect a socket, for IPv4 and IPv6 alike.
RFC 3493 defines it for protocol-independent translation of names and services. It returns a list of entries, each with an address family, a socket type, a protocol and a socket address; most Linux configurations return the list sorted, and a client should try the entries in order until one connects, or in parallel as Happy Eyeballs does. The AI_NUMERICHOST flag forbids name lookups and accepts numeric addresses only. Python's socket.getaddrinfo() wraps the C function and returns 5-tuples (family, type, proto, canonname, sockaddr).
Also known as: getaddrinfo(), socket.getaddrinfo, AI_NUMERICHOST, addrinfo
Sources
- RFC 3493, Basic Socket Interface Extensions for IPv6: section 6.1, protocol-independent nodename and service name translation with getaddrinfo() (read 2026-10-27)
- Python 3.13 documentation, socket: getaddrinfo() returns 5-tuples, sorted on most Linux configurations, AI_NUMERICHOST disables name resolution (read 2026-10-27)