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 a netent structure 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 a netent structure for the entry from the database that matches the network name. you give it a name, it gives you the goods. ๐Ÿ’…
  • getnetbyaddr() returns a netent structure 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 if stayopen is nonzero? then the connection to the database will not be closed between calls to one of the getnet*() 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 โ€” a NULL-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; always AF_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 locale
  • getnetbyname() โ€” Thread safety: MT-Unsafe race:netbyname env locale
  • getnetbyaddr() โ€” Thread safety: MT-Unsafe race:netbyaddr locale
  • setnetent(), 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms