getnetent(3)
โจ getnetent(3) โ the network entry glow-up โจ
okay bestie, so this is a libc one, from the Library Functions Manual, and it's literally all about pulling network entries out of your system's networks database. it's giving very much "old school but still serving" ๐ซถ
๐ธ NAME ๐ธ
getnetent, getnetbyname, getnetbyaddr, setnetent, endnetent โ get network entry
๐ LIBRARY ๐
Standard C library (libc, -lc)
๐ฆ SYNOPSIS ๐ฆ
#include <netdb.h>
struct netent *getnetent(void);
struct netent *getnetbyname(const char *name);
struct netent *getnetbyaddr(uint32_t net, int type);
void setnetent(int stayopen);
void endnetent(void);
๐ DESCRIPTION ๐
okay so the vibe here is that there's a whole database of networks and these functions are your little hands reaching into it. let's go one by one, no cap:
getnetent()reads the next entry from the networks database and hands you back anetentstructure with all the broken-out fields from that entry. if a connection to the database isn't open yet, it opens one. main character energy tbh.getnetbyname()returns anetentstructure for the entry from the database that matches the network name. you give it a name, it gives you the goods. ๐getnetbyaddr()returns anetentstructure for the entry from the database that matches the network number net of type type. โ ๏ธ heads up bestie: the net argument must be in host byte order โ do not come in here with network byte order, it will not slay.setnetent()opens a connection to the database and resets the next entry to the first entry. and ifstayopenis nonzero? then the connection to the database will not be closed between calls to one of thegetnet*()functions. iconic efficiency behavior honestly.endnetent()closes the connection to the database. bye girl, thanks for coming ๐
๐ the netent structure ๐
it's defined in <netdb.h> like this, fr fr:
struct netent {
char *n_name; /* official network name */
char **n_aliases; /* alias list */
int n_addrtype; /* net address type */
uint32_t n_net; /* network number */
}
and now the members, one by one, because every single one matters:
n_nameโ the official name of the network. the legal government name, if you will. ๐n_aliasesโ aNULL-terminated list of alternative names for the network. the nicknames. the stage names. the "yeah she also goes byโฆ" โจn_addrtypeโ the type of the network number; alwaysAF_INET. always. no exceptions, don't ask. ๐n_netโ the network number in host byte order.
๐ฅ RETURN VALUE ๐ฅ
getnetent(), getnetbyname(), and getnetbyaddr() all return a pointer to a statically allocated netent structure... or a null pointer if an error occurs or the end of the file is reached.
bestie. STATICALLY. ALLOCATED. that means the next call can absolutely stomp all over what you're holding, so copy what you need. this is not a drill, it's a race condition waiting to happen ๐
๐ FILES ๐
/etc/networksโ networks database file
literally the whole source of truth right there.
๐ง ATTRIBUTES ๐ง
for an explanation of the terms used in this section, see attributes(7).
here's the tea, laid out as bullets because we're cute like that:
getnetent()โ Thread safety:MT-Unsafe race:netent race:netentbuf env localegetnetbyname()โ Thread safety:MT-Unsafe race:netbyname env localegetnetbyaddr()โ Thread safety:MT-Unsafe race:netbyaddr localesetnetent(),endnetent()โ Thread safety:MT-Unsafe race:netent env locale
and to decode that for you, because the table language is a whole dialect:
netent in race:netent means that if any of the functions setnetent(), getnetent(), or endnetent() are used in parallel in different threads of a program, then data races could occur. yeah. ๐ญ multi-threaded + these functions = chaos, proceed accordingly.
๐ STANDARDS ๐
POSIX.1-2008.
๐ฐ๏ธ HISTORY ๐ฐ๏ธ
POSIX.1-2001, 4.3BSD.
and here's a lil historical nugget for you: before glibc 2.2, the net argument of getnetbyaddr() was of type long. the way it got โจupgradedโจ. growth!
๐ SEE ALSO ๐
and that's the whole page, bestie!! this was Linux man-pages 6.20, dated 2026-02-08, and it's the getnetent(3) page โ go forth and query your networks database responsibly ๐ซถ๐โจ
๐ฆ 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
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms