getnetent_r(3)

πŸ’… getnetent_r(3) β€” the reentrant network entry girlies

okay bestie, gather round, we're reading a Library Functions Manual page from the Standard C library (libc, -lc) and honestly? it's giving thread-safe. no cap. ✨


🌸 NAME 🌸

getnetent_r, getnetbyname_r, getnetbyaddr_r β€” get network entry (reentrant)

like, these are the ✨reentrant✨ girlies. the ones who don't share their static storage with anybody. main character energy fr fr. πŸ‘‘


πŸŽ€ LIBRARY πŸŽ€

Standard C library (libc, -lc)


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <netdb.h>

int getnetent_r(size_t size;
                struct netent *restrict result_buf,
                char buf[restrict size], size_t size,
                struct netent **restrict result,
                int *restrict h_errnop);
int getnetbyname_r(size_t size;
                const char *restrict name,
                struct netent *restrict result_buf,
                char buf[restrict size], size_t size,
                struct netent **restrict result,
                int *restrict h_errnop);
int getnetbyaddr_r(size_t size;
                uint32_t net, int type,
                struct netent *restrict result_buf,
                char buf[restrict size], size_t size,
                struct netent **restrict result,
                int *restrict h_errnop);

ngl those signatures are long. they could never be short. periodt. πŸ’€

🌈 Feature Test Macro Requirements for glibc (see feature_test_macros(7)) 🌈

  • getnetent_r(), getnetbyname_r(), getnetbyaddr_r():
    • Since glibc 2.19:
      • _DEFAULT_SOURCE
    • glibc 2.19 and earlier:
      • _BSD_SOURCE || _SVID_SOURCE

so if you're on a modern glibc, _DEFAULT_SOURCE and you're slaying. older than 2.19? you gotta throw _BSD_SOURCE or _SVID_SOURCE in there. iykyk 🫢


πŸ’– DESCRIPTION πŸ’–

So. getnetent_r(), getnetbyname_r(), and getnetbyaddr_r() are the reentrant equivalents of, respectively, getnetent(3), getnetbyname(3), and getnetbynumber(3). the way they differ from their non-reentrant sisters is how the netent structure comes back to you, plus the calling signature and the return value. this man page is literally just the differences, so if you want the whole lore, go read the nonreentrant ones. πŸ’…

instead of handing you back a pointer to some statically allocated netent structure as the function result, these functions copy the structure into the spot that result_buf points at. yes ma'am, into your buffer, your storage, your rules. πŸŽ€

the buf array is where the string fields that the returned netent structure points to get stored. (the nonreentrant functions just allocate those strings in static storage, which is exactly the shared-global drama we're avoiding here.) how big that array is? that's what you tell them in size. and bestie, if buf is too small, the call fails with the error ERANGE and you gotta try again with a bigger buffer. (a buffer of size 1024 bytes should be sufficient for most applications, so like, just do that and stop stressing fr.)

if the function call successfully obtains a network record, then *result is set pointing to result_buf; otherwise, *result is set to NULL. iconic behaviour, honestly. ✨

the buffer that h_errnop points to is used to return the value that would be stored in the global variable h_errno by the nonreentrant versions of these functions. so no touching globals, we keep it local, we keep it cute. πŸ¦‹


🌟 RETURN VALUE 🌟

On success, these functions return 0. slay. πŸ’–

On error, they return one of the positive error numbers listed down in ERRORS. 🚨

And on error, or when the record isn't found (getnetbyname_r(), getnetbyaddr_r()), or at end of input (getnetent_r()) β€” result is set to NULL. so like, check it, always. don't be out here dereferencing a NULL bestie, that's not the vibe. 😭


πŸ”₯ ERRORS πŸ”₯

  • ENOENT (getnetent_r()) β€” No more records in database. like, that's it, that's the whole database, we're done here. 🫠
  • ERANGE β€” buf is too small. Try again with a larger buffer (and increased size). yeah, the buffer was not big enough to hold the moment. glow-up your buffer and retry. πŸ’…

πŸ‘‘ ATTRIBUTES πŸ‘‘

For an explanation of the terms used in this section, see attributes(7).

  • Interface: getnetent_r(), getnetbyname_r(), getnetbyaddr_r()
  • Attribute: Thread safety
  • Value: MT-Safe locale

MT-Safe locale, meaning they're thread safe (with that locale caveat). so go ahead, call them from all your threads, they can handle it. πŸ’ͺ✨


🧚 VERSIONS 🧚

Functions with similar names exist on some other systems, though typically with different calling signatures.

so like, don't just assume the same signature everywhere β€” other systems have their own versions, and they do not match. check before you commit, bestie. πŸ™ˆ


⭐ STANDARDS ⭐

GNU.


🌈 SEE ALSO 🌈

getnetent(3), networks(5)


and that's the whole page, no notes. πŸ’œ

this was Linux man-pages 6.20, dated 2025-06-28, and the page is getnetent_r(3) β€” mwah, go forth and resolve networks reentrantly, you absolute icon. πŸŽ€πŸ’–βœ¨

πŸ“¦ 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