getnetgrent_r - Linux
Overview
getnetgrent_r
retrieves the next network group file entry. This function is a thread-safe version of getnetgrent
.
Syntax
#include <netdb.h>
int getnetgrent_r(struct netgroup *result, char *buffer, size_t buflen, int *errnop);
Options/Flags
None.
Examples
#include <stdio.h>
#include <netdb.h>
int main() {
int err;
struct netgroup *netgroup;
char buffer[1024];
while ((netgroup = getnetgrent_r(buffer, sizeof(buffer), &err)) != NULL) {
// Process netgroup
}
if (err == 0) {
// No more netgroups
} else {
// Error occurred
}
}
Common Issues
- getnetgrent_r may return
NULL
if there are no more entries in the network group file or if an error occurs while reading the file. - The
errnop
parameter must be non-NULL
.
Integration
getnetgrent_r
can be used with other functions such as setnetgrent_r
and endnetgrent_r
to iterate through the network group file.
Related Commands
- getprotoent_r
- getservbyname
- getservbyport