git: a3c3c02244f4 - stable/13 - getnetent(3): Add missing reentrant functions

From: Gordon Bergling <>
Date: Sat, 24 Sep 2022 08:12:34 UTC
The branch stable/13 has been updated by gbe (doc committer):


commit a3c3c02244f4fe4c77c034ca3846b410dbbb1091
Author:     Fernando ApesteguĂ­a <>
AuthorDate: 2021-05-21 15:25:25 +0000
Commit:     Gordon Bergling <>
CommitDate: 2022-09-24 08:12:08 +0000

    getnetent(3): Add missing reentrant functions
    Add documentation for gethostbyname_r, gethostbyname2_r and gethostbyaddr_r
    Create proper MLINKs for the new functions.
    PR:     249154
    Reported by:    asomers@
    Approved by:    manpages (0mp@), Pau Amma
    Differential Revision:
    (cherry picked from commit dc68997328ec6cec41ad3b818c1846c8217e0c68)
 lib/libc/net/    |  7 ++++---
 lib/libc/net/gethostbyname.3 | 33 +++++++++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/lib/libc/net/ b/lib/libc/net/
index 6628028ccc83..683e2826c401 100644
--- a/lib/libc/net/
+++ b/lib/libc/net/
@@ -59,9 +59,10 @@ MLINKS+=eui64.3 eui64_aton.3 eui64.3 eui64_hostton.3 \
 	eui64.3 eui64_ntoa.3 eui64.3 eui64_ntohost.3
 MLINKS+=getaddrinfo.3 freeaddrinfo.3 
 MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \
-	gethostbyname.3 gethostbyname2.3 gethostbyname.3 gethostent.3 \
-	gethostbyname.3 herror.3 gethostbyname.3 hstrerror.3 \
-	gethostbyname.3 sethostent.3
+	gethostbyname.3 gethostbyaddr_r.3 gethostbyname.3 gethostbyname2.3 \
+	gethostbyname.3 gethostbyname2_r.3 gethostbyname.3 gethostbyname_r.3 \
+	gethostbyname.3 gethostent.3 gethostbyname.3 herror.3 \
+	gethostbyname.3 hstrerror.3 gethostbyname.3 sethostent.3
 MLINKS+=getifaddrs.3 freeifaddrs.3
 MLINKS+=getifmaddrs.3 freeifmaddrs.3
 MLINKS+=getipnodebyname.3 getipnodebyaddr.3 getipnodebyname.3 freehostent.3
diff --git a/lib/libc/net/gethostbyname.3 b/lib/libc/net/gethostbyname.3
index 04a055ea3b1c..9f7156b7cd9c 100644
--- a/lib/libc/net/gethostbyname.3
+++ b/lib/libc/net/gethostbyname.3
@@ -28,7 +28,7 @@
 .\"     From: @(#)gethostbyname.3	8.4 (Berkeley) 5/25/95
 .\" $FreeBSD$
-.Dd October 4, 2017
+.Dd June 20, 2022
@@ -39,7 +39,10 @@
 .Nm sethostent ,
 .Nm endhostent ,
 .Nm herror ,
-.Nm hstrerror
+.Nm hstrerror ,
+.Nm gethostbyname_r ,
+.Nm gethostbyname2_r ,
+.Nm gethostbyaddr_r
 .Nd get network host entry
 .Lb libc
@@ -62,6 +65,12 @@
 .Fn herror "const char *string"
 .Ft const char *
 .Fn hstrerror "int err"
+.Ft int
+.Fn gethostbyname_r "const char *name" "struct hostent *he" "char *buffer" "size_t buflen" "struct hostent **result" "int *h_errnop"
+.Ft int
+.Fn gethostbyname2_r "const char *name" "int af" "struct hostent *he" "char *buffer" "size_t buflen" "struct hostent **result" "int *h_errnop"
+.Ft int
+.Fn gethostbyaddr_r "const void *addr" "socklen_t len" "int af" "struct hostent *hp" "char *buf" "size_t buflen" "struct hostent **result" "int *h_errno"p
 .Bf -symbolic
@@ -225,6 +234,26 @@ function returns a string which is the message text corresponding to the
 value of the
 .Fa err
+Functions with the
+.Em _r
+suffix provide reentrant versions of their respective counterparts.
+The caller must supply five additional parameters: a
+.Vt struct hostent
+variable to be filled on success, a
+.Va buffer
+.Va buflen
+bytes in size, a
+.Vt struct hostent
+.Va result
+variable that will point to the result on success or be set to
+on failure or if the name is not found.
+.Va h_errnop
+variable will be filled with the error code if any.
+All these functions return 0 on success.
 .Bl -tag -width /etc/nsswitch.conf -compact
 .It Pa /etc/hosts