1 /* A GNU-like <arpa/inet.h>.
3 Copyright (C) 2005-2006, 2008-2025 Free Software Foundation, Inc.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #ifndef _@GUARD_PREFIX@_ARPA_INET_H
21 @PRAGMA_SYSTEM_HEADER@
26 # include <features.h> /* for __GLIBC__ */
29 /* Gnulib's sys/socket.h is responsible for defining socklen_t (used below) and
30 for pulling in winsock2.h etc. under MinGW.
31 But avoid namespace pollution on glibc systems. */
33 # include <sys/socket.h>
36 /* On NonStop Kernel, inet_ntop and inet_pton are declared in <netdb.h>.
37 But avoid namespace pollution on glibc systems. */
38 #if defined __TANDEM && !defined __GLIBC__
42 #if @HAVE_ARPA_INET_H@
44 /* The include_next requires a split double-inclusion guard. */
45 # @INCLUDE_NEXT@ @NEXT_ARPA_INET_H@
49 #ifndef _@GUARD_PREFIX@_ARPA_INET_H
50 #define _@GUARD_PREFIX@_ARPA_INET_H
52 /* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
53 #if !_GL_CONFIG_H_INCLUDED
54 #error "Please include config.h first."
57 /* Get all possible declarations of inet_ntop() and inet_pton(). */
58 #if (@GNULIB_INET_NTOP@ || @GNULIB_INET_PTON@ || defined GNULIB_POSIXCHECK) \
60 # include <ws2tcpip.h>
63 #if !(@HAVE_DECL_HTONL@ || @HAVE_DECL_HTONS@ || @HAVE_DECL_NTOHL@ || @HAVE_DECL_NTOHS@)
67 _GL_INLINE_HEADER_BEGIN
68 #ifndef _GL_ARPA_INET_INLINE
69 # define _GL_ARPA_INET_INLINE _GL_INLINE
73 /* Host to network byte order. */
75 #if !@HAVE_DECL_HTONS@
76 _GL_ARPA_INET_INLINE
uint16_t
77 htons (uint16_t value
)
79 return htobe16 (value
);
83 #if !@HAVE_DECL_HTONL@
84 _GL_ARPA_INET_INLINE
uint32_t
85 htonl (uint32_t value
)
87 return htobe32 (value
);
91 /* Network to host byte order. */
93 #if !@HAVE_DECL_NTOHS@
94 _GL_ARPA_INET_INLINE
uint16_t
95 ntohs (uint16_t value
)
97 return htobe16 (value
);
101 #if !@HAVE_DECL_NTOHL@
102 _GL_ARPA_INET_INLINE
uint32_t
103 ntohl (uint32_t value
)
105 return htobe32 (value
);
110 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
112 /* The definition of _GL_ARG_NONNULL is copied here. */
114 /* The definition of _GL_WARN_ON_USE is copied here. */
117 #if @GNULIB_INET_NTOP@
118 /* Converts an internet address from internal format to a printable,
120 AF is an internet address family, such as AF_INET or AF_INET6.
121 SRC points to a 'struct in_addr' (for AF_INET) or 'struct in6_addr'
123 DST points to a buffer having room for CNT bytes.
124 The printable representation of the address (in numeric form, not
125 surrounded by [...], no reverse DNS is done) is placed in DST, and
126 DST is returned. If an error occurs, the return value is NULL and
127 errno is set. If CNT bytes are not sufficient to hold the result,
128 the return value is NULL and errno is set to ENOSPC. A good value
131 For more details, see the POSIX:2008 specification
132 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html>. */
133 # if @REPLACE_INET_NTOP@
134 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
136 # define inet_ntop rpl_inet_ntop
138 _GL_FUNCDECL_RPL (inet_ntop
, const char *,
139 (int af
, const void *restrict src
,
140 char *restrict dst
, socklen_t cnt
),
141 _GL_ARG_NONNULL ((2, 3)));
142 _GL_CXXALIAS_RPL (inet_ntop
, const char *,
143 (int af
, const void *restrict src
,
144 char *restrict dst
, socklen_t cnt
));
146 # if !@HAVE_DECL_INET_NTOP@
147 _GL_FUNCDECL_SYS (inet_ntop
, const char *,
148 (int af
, const void *restrict src
,
149 char *restrict dst
, socklen_t cnt
),
150 _GL_ARG_NONNULL ((2, 3)));
152 /* Need to cast, because on NonStop Kernel, the fourth parameter is
154 _GL_CXXALIAS_SYS_CAST (inet_ntop
, const char *,
155 (int af
, const void *restrict src
,
156 char *restrict dst
, socklen_t cnt
));
159 _GL_CXXALIASWARN (inet_ntop
);
161 #elif defined GNULIB_POSIXCHECK
163 # if HAVE_RAW_DECL_INET_NTOP
164 _GL_WARN_ON_USE (inet_ntop
, "inet_ntop is unportable - "
165 "use gnulib module inet_ntop for portability");
169 #if @GNULIB_INET_PTON@
170 # if @REPLACE_INET_PTON@
171 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
173 # define inet_pton rpl_inet_pton
175 _GL_FUNCDECL_RPL (inet_pton
, int,
176 (int af
, const char *restrict src
, void *restrict dst
),
177 _GL_ARG_NONNULL ((2, 3)));
178 _GL_CXXALIAS_RPL (inet_pton
, int,
179 (int af
, const char *restrict src
, void *restrict dst
));
181 # if !@HAVE_DECL_INET_PTON@
182 _GL_FUNCDECL_SYS (inet_pton
, int,
183 (int af
, const char *restrict src
, void *restrict dst
),
184 _GL_ARG_NONNULL ((2, 3)));
186 _GL_CXXALIAS_SYS (inet_pton
, int,
187 (int af
, const char *restrict src
, void *restrict dst
));
190 _GL_CXXALIASWARN (inet_pton
);
192 #elif defined GNULIB_POSIXCHECK
194 # if HAVE_RAW_DECL_INET_PTON
195 _GL_WARN_ON_USE (inet_pton
, "inet_pton is unportable - "
196 "use gnulib module inet_pton for portability");
200 _GL_INLINE_HEADER_END
202 #endif /* _@GUARD_PREFIX@_ARPA_INET_H */
203 #endif /* _@GUARD_PREFIX@_ARPA_INET_H */