getipnodebyname(3)
πΈ getipnodebyname β NAME π
ok so bestie, this is a page from the Library Functions Manual β it's section 3, the C library one, getipnodebyname(3) if you're fancy about it π β and it's about three lil functions that go get network hostnames and addresses for you: getipnodebyname, getipnodebyaddr, and freehostent.
π LIBRARY
Standard C library (libc, -lc). yes girl, the regular one π
β¨ SYNOPSIS β¨
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
[[deprecated]] struct hostent *getipnodebyname(const char *name, int af,
int flags, int *error_num);
[[deprecated]] struct hostent *getipnodebyaddr(size_t size;
const void addr[size],
size_t size, int af,
int *error_num);
[[deprecated]] void freehostent(struct hostent *ip);
π¬ DESCRIPTION
π¨ okay so here's the tea: these functions are deprecated (and straight up unavailable in glibc). Usegetaddrinfo(3)andgetnameinfo(3)instead. that's the whole vibe. no cap.
getipnodebyname() and getipnodebyaddr() return the names and addresses of a network host. They hand you back a pointer to this structure right here:
struct hostent {
char *h_name;
char **h_aliases;
int h_addrtype;
int h_length;
char **h_addr_list;
};
These functions replace gethostbyname(3) and gethostbyaddr(3), which could only ever access the IPv4 network address family β like, only one family, so limited π. But getipnodebyname() and getipnodebyaddr() can access multiple network address families. glow up β¨
And unlike the gethostby functions, these ones return pointers to dynamically allocated memory. The freehostent() function is what you use to release that dynamically allocated memory once you're done with the hostent structure. pls don't ghost your memory leaks bestie π
π getipnodebyname() arguments
getipnodebyname() looks up network addresses for the host specified by the name argument. The af argument specifies one of these values:
AF_INETβ the name argument points to a dotted-quad IPv4 address or a name of an IPv4 network host.AF_INET6β the name argument points to a hexadecimal IPv6 address or a name of an IPv6 network host.
The flags argument specifies additional options. You can specify more than one option by bitwise OR-ing them together β stack 'em, combo them, the more the merrier π
. flags should be set to 0 if you don't want any options at all.
AI_V4MAPPEDβ this flag is used withAF_INET6to request a query for IPv4 addresses instead of IPv6 addresses; the IPv4 addresses will be mapped to IPv6 addresses. it's giving translation services π¦AI_ALLβ this flag is used withAI_V4MAPPEDto request a query for both IPv4 and IPv6 addresses. Any IPv4 address found will be mapped to an IPv6 address. greedy in the best way πAI_ADDRCONFIGβ this flag is used withAF_INET6to further request that queries for IPv6 addresses should not be made unless the system has at least one IPv6 address assigned to a network interface, and that queries for IPv4 addresses should not be made unless the system has at least one IPv4 address assigned to a network interface. This flag may be used by itself or with theAI_V4MAPPEDflag.AI_DEFAULTβ this flag is equivalent to(AI_ADDRCONFIG | AI_V4MAPPED). two-in-one, iconic β
π getipnodebyaddr() arguments
getipnodebyaddr() looks up the name of the host whose network address is specified by the addr argument. The af argument specifies one of these values:
AF_INETβ the addr argument points to astruct in_addrand size must be set tosizeof(struct in_addr).AF_INET6β the addr argument points to astruct in6_addrand size must be set tosizeof(struct in6_addr).
π RETURN VALUE
NULL is returned if an error occurred, and error_num will contain an error code from this list:
HOST_NOT_FOUNDβ the hostname or network address was not found. it's not there, babe, we looked πNO_ADDRESSβ the domain name server recognized the network address or name, but no answer was returned. This can happen if the network host has only IPv4 addresses and a request has been made for IPv6 information only, or vice versa. wrong family, wrong time πNO_RECOVERYβ the domain name server returned a permanent failure response. yeah that one's not coming back.TRY_AGAINβ the domain name server returned a temporary failure response. You might have better luck next time. manifesting for you bestie π«Ά
A successful query returns a pointer to a hostent structure that contains the following fields:
h_nameβ this is the official name of this network host. the government name, if you will β¨h_aliasesβ this is an array of pointers to unofficial aliases for the same host. The array is terminated by a null pointer.h_addrtypeβ this is a copy of the af argument togetipnodebyname()orgetipnodebyaddr().h_addrtypewill always beAF_INETif the af argument wasAF_INET.h_addrtypewill always beAF_INET6if the af argument wasAF_INET6. it's literally just echoing what you said back to you πh_lengthβ this field will be set tosizeof(struct in_addr)ifh_addrtypeisAF_INET, and tosizeof(struct in6_addr)ifh_addrtypeisAF_INET6.h_addr_listβ this is an array of one or more pointers to network address structures for the network host. The array is terminated by a null pointer.
π STANDARDS
None. (empty. nothing. void. the silence is loud π)
π°οΈ HISTORY
Present in glibc 2.1.91-95, but removed again. Several UNIX-like systems support them, but all call them deprecated. so like... a comeback that got cancelled π
π SEE ALSO
getaddrinfo(3), getnameinfo(3), inet_ntop(3), inet_pton(3)
π ok that's the whole page bestie, go use getaddrinfo(3) fr fr π
that's a wrap on this one, brought to you by Linux man-pages 6.20, dated 2025-09-21 β mwah, slay, periodt π β¨
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms