---
name: "getnetent_r"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/getnetent_r"
---

# getnetent\_r(3)

get network entry (reentrant)

## NAME

getnetent\_r, getnetbyname\_r, getnetbyaddr\_r - get network entry (reentrant)

## 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***);**

Feature Test Macro Requirements for glibc (see [**feature\_test\_macros**(7)](/feature_test_macros/7.md)):

**getnetent\_r**(), **getnetbyname\_r**(), **getnetbyaddr\_r**():

```
    Since glibc 2.19:
        _DEFAULT_SOURCE
    glibc 2.19 and earlier:
        _BSD_SOURCE || _SVID_SOURCE
```

## DESCRIPTION

The **getnetent\_r**(), **getnetbyname\_r**(), and **getnetbyaddr\_r**() functions are the reentrant equivalents of, respectively, [**getnetent**(3)](/getnetent/3.md), [**getnetbyname**(3)](/getnetbyname/3.md), and **getnetbynumber**(3). They differ in the way that the *netent* structure is returned, and in the function calling signature and return value. This manual page describes just the differences from the nonreentrant functions.

Instead of returning a pointer to a statically allocated *netent* structure as the function result, these functions copy the structure into the location pointed to by *result\_buf*.

The *buf* array is used to store the string fields pointed to by the returned *netent* structure. (The nonreentrant functions allocate these strings in static storage.) The size of this array is specified in *size*. If *buf* is too small, the call fails with the error **ERANGE**, and the caller must try again with a larger buffer. (A buffer of size 1024 bytes should be sufficient for most applications.)

If the function call successfully obtains a network record, then *\*result* is set pointing to *result\_buf*; otherwise, *\*result* is set to NULL.

The buffer pointed to by *h\_errnop* is used to return the value that would be stored in the global variable *h\_errno* by the nonreentrant versions of these functions.

## RETURN VALUE

On success, these functions return 0. On error, they return one of the positive error numbers listed in ERRORS.

On error, record not found (**getnetbyname\_r**(), **getnetbyaddr\_r**()), or end of input (**getnetent\_r**()) *result* is set to NULL.

## ERRORS

- **ENOENT**

  (**getnetent\_r**()) No more records in database.

- **ERANGE**

  *buf* is too small. Try again with a larger buffer (and increased *size*).

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **getnetent\_r**(), **getnetbyname\_r**(), **getnetbyaddr\_r**() | Thread safety | MT-Safe locale |

## VERSIONS

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

## STANDARDS

GNU.

## SEE ALSO

[**getnetent**(3)](/getnetent/3.md), [**networks**(5)](/networks/5.md)
