setnetgrent(3)
๐ setnetgrent(3) โ Library Functions Manual ๐
okay bestie, sit down, we're learning netgroups today and honestly? it's giving vintage. this whole page is about setnetgrent, endnetgrent, getnetgrent, getnetgrent_r, and innetgr โ the girlies that handle network group entries. and yes, it lives in the Standard C library (libc, -lc). ๐
โจ SYNOPSIS โจ
#include <netdb.h>
int setnetgrent(const char *netgroup);
void endnetgrent(void);
int getnetgrent(char **restrict host,
char **restrict user, char **restrict domain);
int getnetgrent_r(size_t size;
char **restrict host,
char **restrict user,
char **restrict domain,
char buf[restrict size], size_t size);
int innetgr(const char *netgroup, const char *host,
const char *user, const char *domain);
๐ฆ Feature Test Macro Requirements for glibc ๐ฆ
(peep feature_test_macros(7) if you're nosy, and you should be)
setnetgrent(), endnetgrent(), getnetgrent(), getnetgrent_r(), innetgr():
- Since glibc 2.19:
_DEFAULT_SOURCE
- glibc 2.19 and earlier:
_BSD_SOURCE || _SVID_SOURCE
๐ธ DESCRIPTION ๐ธ
The netgroup is a SunOS invention. no cap, that's literally where it came from. A netgroup database is a list of string triples โ that's (hostname, username, domainname) โ or other netgroup names. Any of the elements in a triple can be empty, and empty means โจanything matchesโจ. The functions described here allow access to the netgroup databases. And the file /etc/nsswitch.conf is the one that defines what database is searched. ๐
The setnetgrent() call defines the netgroup that will be searched by subsequent getnetgrent() calls. The getnetgrent() function retrieves the next netgroup entry, and returns pointers in host, user, domain. A null pointer means that the corresponding entry matches any string โ wildcard behavior, we love her ๐
. The pointers are valid only as long as there is no call to other netgroup-related functions. To avoid this problem you can use the GNU function getnetgrent_r() that stores the strings in the supplied buffer. To free all allocated buffers use endnetgrent(). ๐งน
In most cases you want to check only if the triplet (hostname, username, domainname) is a member of a netgroup. The function innetgr() can be used for this without calling the above three functions โ shortcut queen ๐ซถ. Again, a null pointer is a wildcard and matches any string. The function is thread-safe. ๐ฅ
๐ RETURN VALUE ๐
These functions return 1 on success and 0 for failure. that's it, that's the whole vibe. โจ
๐ FILES ๐
/etc/netgroup/etc/nsswitch.conf
๐ ATTRIBUTES ๐
For an explanation of the terms used in this section, see attributes(7).
setnetgrent(),getnetgrent_r(),innetgr()โ Thread safety:MT-Unsafe race:netgrent localeendnetgrent()โ Thread safety:MT-Unsafe race:netgrentgetnetgrent()โ Thread safety:MT-Unsafe race:netgrent race:netgrentbuf locale
In the above table, netgrent in race:netgrent signifies that if any of the functions setnetgrent(), getnetgrent_r(), innetgr(), getnetgrent(), or endnetgrent() are used in parallel in different threads of a program, then data races could occur.
๐ญ bestie PLEASE heed this one. parallel calls in different threads โ data races. it's giving chaos and we do not want that energy in your program.
โญ VERSIONS โญ
In the BSD implementation, setnetgrent() returns void. (different flavor, different rules, iykyk)
๐ STANDARDS ๐
None. literally none. it's giving "we made this up and it stuck". ๐
๐ HISTORY ๐
setnetgrent(), endnetgrent(), getnetgrent(), and innetgr() are available on most UNIX systems. getnetgrent_r() is not widely available on other systems โ she's the rare one, the main character of portability. ๐ฆ
๐ฅ SEE ALSO ๐ฅ
and that's the whole page, bestie!! you ate this. this was Linux man-pages 6.20, dated 2026-02-08 โ so when you're citing your sources, that's the icon right there. mwah ๐โจ๐
๐ฆ 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: GPL-1.0-or-later
- Copyright 2002, Walter Harms <walter.harms@informatik.uni-oldenburg.de>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms