errno-h: document Haiku errors can’t be -1
[gnulib.git] / lib / arpa_inet.in.h
blobd7417bfdab718ec5499d91e44daeddd1b9e245eb
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
20 #if __GNUC__ >= 3
21 @PRAGMA_SYSTEM_HEADER@
22 #endif
23 @PRAGMA_COLUMNS@
25 #if @HAVE_FEATURES_H@
26 # include <features.h> /* for __GLIBC__ */
27 #endif
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. */
32 #ifndef __GLIBC__
33 # include <sys/socket.h>
34 #endif
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__
39 # include <netdb.h>
40 #endif
42 #if @HAVE_ARPA_INET_H@
44 /* The include_next requires a split double-inclusion guard. */
45 # @INCLUDE_NEXT@ @NEXT_ARPA_INET_H@
47 #endif
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."
55 #endif
57 /* Get all possible declarations of inet_ntop() and inet_pton(). */
58 #if (@GNULIB_INET_NTOP@ || @GNULIB_INET_PTON@ || defined GNULIB_POSIXCHECK) \
59 && @HAVE_WS2TCPIP_H@
60 # include <ws2tcpip.h>
61 #endif
63 #if !(@HAVE_DECL_HTONL@ || @HAVE_DECL_HTONS@ || @HAVE_DECL_NTOHL@ || @HAVE_DECL_NTOHS@)
64 # include <endian.h>
65 #endif
67 _GL_INLINE_HEADER_BEGIN
68 #ifndef _GL_ARPA_INET_INLINE
69 # define _GL_ARPA_INET_INLINE _GL_INLINE
70 #endif
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);
81 #endif
83 #if !@HAVE_DECL_HTONL@
84 _GL_ARPA_INET_INLINE uint32_t
85 htonl (uint32_t value)
87 return htobe32 (value);
89 #endif
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);
99 #endif
101 #if !@HAVE_DECL_NTOHL@
102 _GL_ARPA_INET_INLINE uint32_t
103 ntohl (uint32_t value)
105 return htobe32 (value);
107 #endif
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,
119 presentable format.
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'
122 (for AF_INET6).
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
129 for CNT is 46.
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)
135 # undef inet_ntop
136 # define inet_ntop rpl_inet_ntop
137 # endif
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));
145 # else
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)));
151 # endif
152 /* Need to cast, because on NonStop Kernel, the fourth parameter is
153 size_t cnt. */
154 _GL_CXXALIAS_SYS_CAST (inet_ntop, const char *,
155 (int af, const void *restrict src,
156 char *restrict dst, socklen_t cnt));
157 # endif
158 # if __GLIBC__ >= 2
159 _GL_CXXALIASWARN (inet_ntop);
160 # endif
161 #elif defined GNULIB_POSIXCHECK
162 # undef inet_ntop
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");
166 # endif
167 #endif
169 #if @GNULIB_INET_PTON@
170 # if @REPLACE_INET_PTON@
171 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
172 # undef inet_pton
173 # define inet_pton rpl_inet_pton
174 # endif
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));
180 # else
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)));
185 # endif
186 _GL_CXXALIAS_SYS (inet_pton, int,
187 (int af, const char *restrict src, void *restrict dst));
188 # endif
189 # if __GLIBC__ >= 2
190 _GL_CXXALIASWARN (inet_pton);
191 # endif
192 #elif defined GNULIB_POSIXCHECK
193 # undef inet_pton
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");
197 # endif
198 #endif
200 _GL_INLINE_HEADER_END
202 #endif /* _@GUARD_PREFIX@_ARPA_INET_H */
203 #endif /* _@GUARD_PREFIX@_ARPA_INET_H */