1 /* A GNU-like <arpa/inet.h>.
3 Copyright (C) 2005-2006, 2008-2023 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 /* Get all possible declarations of inet_ntop() and inet_pton(). */
53 #if (@GNULIB_INET_NTOP@ || @GNULIB_INET_PTON@ || defined GNULIB_POSIXCHECK) \
55 # include <ws2tcpip.h>
58 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
60 /* The definition of _GL_ARG_NONNULL is copied here. */
62 /* The definition of _GL_WARN_ON_USE is copied here. */
65 #if @GNULIB_INET_NTOP@
66 /* Converts an internet address from internal format to a printable,
68 AF is an internet address family, such as AF_INET or AF_INET6.
69 SRC points to a 'struct in_addr' (for AF_INET) or 'struct in6_addr'
71 DST points to a buffer having room for CNT bytes.
72 The printable representation of the address (in numeric form, not
73 surrounded by [...], no reverse DNS is done) is placed in DST, and
74 DST is returned. If an error occurs, the return value is NULL and
75 errno is set. If CNT bytes are not sufficient to hold the result,
76 the return value is NULL and errno is set to ENOSPC. A good value
79 For more details, see the POSIX:2008 specification
80 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/inet_ntop.html>. */
81 # if @REPLACE_INET_NTOP@
82 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
84 # define inet_ntop rpl_inet_ntop
86 _GL_FUNCDECL_RPL (inet_ntop
, const char *,
87 (int af
, const void *restrict src
,
88 char *restrict dst
, socklen_t cnt
)
89 _GL_ARG_NONNULL ((2, 3)));
90 _GL_CXXALIAS_RPL (inet_ntop
, const char *,
91 (int af
, const void *restrict src
,
92 char *restrict dst
, socklen_t cnt
));
94 # if !@HAVE_DECL_INET_NTOP@
95 _GL_FUNCDECL_SYS (inet_ntop
, const char *,
96 (int af
, const void *restrict src
,
97 char *restrict dst
, socklen_t cnt
)
98 _GL_ARG_NONNULL ((2, 3)));
100 /* Need to cast, because on NonStop Kernel, the fourth parameter is
102 _GL_CXXALIAS_SYS_CAST (inet_ntop
, const char *,
103 (int af
, const void *restrict src
,
104 char *restrict dst
, socklen_t cnt
));
107 _GL_CXXALIASWARN (inet_ntop
);
109 #elif defined GNULIB_POSIXCHECK
111 # if HAVE_RAW_DECL_INET_NTOP
112 _GL_WARN_ON_USE (inet_ntop
, "inet_ntop is unportable - "
113 "use gnulib module inet_ntop for portability");
117 #if @GNULIB_INET_PTON@
118 # if @REPLACE_INET_PTON@
119 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
121 # define inet_pton rpl_inet_pton
123 _GL_FUNCDECL_RPL (inet_pton
, int,
124 (int af
, const char *restrict src
, void *restrict dst
)
125 _GL_ARG_NONNULL ((2, 3)));
126 _GL_CXXALIAS_RPL (inet_pton
, int,
127 (int af
, const char *restrict src
, void *restrict dst
));
129 # if !@HAVE_DECL_INET_PTON@
130 _GL_FUNCDECL_SYS (inet_pton
, int,
131 (int af
, const char *restrict src
, void *restrict dst
)
132 _GL_ARG_NONNULL ((2, 3)));
134 _GL_CXXALIAS_SYS (inet_pton
, int,
135 (int af
, const char *restrict src
, void *restrict dst
));
138 _GL_CXXALIASWARN (inet_pton
);
140 #elif defined GNULIB_POSIXCHECK
142 # if HAVE_RAW_DECL_INET_PTON
143 _GL_WARN_ON_USE (inet_pton
, "inet_pton is unportable - "
144 "use gnulib module inet_pton for portability");
149 #endif /* _@GUARD_PREFIX@_ARPA_INET_H */
150 #endif /* _@GUARD_PREFIX@_ARPA_INET_H */