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). Use getaddrinfo(3) and getnameinfo(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 with AF_INET6 to 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 with AI_V4MAPPED to 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 with AF_INET6 to 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 the AI_V4MAPPED flag.
  • 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 a struct in_addr and size must be set to sizeof(struct in_addr).
  • AF_INET6 β€” the addr argument points to a struct in6_addr and size must be set to sizeof(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 to getipnodebyname() or getipnodebyaddr(). h_addrtype will always be AF_INET if the af argument was AF_INET. h_addrtype will always be AF_INET6 if the af argument was AF_INET6. it's literally just echoing what you said back to you πŸ’…
  • h_length β€” this field will be set to sizeof(struct in_addr) if h_addrtype is AF_INET, and to sizeof(struct in6_addr) if h_addrtype is AF_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

RFC 2553.

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