* modules/htonl: New file.
* lib/arpa_inet.c: New file.
* m4/htonl.m4: New file.
* modules/arpa_inet (Files): Add lib/arpa_inet.c.
(Depends-on): Add extern-inline.
* lib/arpa_inet.in.h (htons, htonl, ntohs, ntohl): New declarations.
* m4/arpa_inet_h.m4 (gl_ARPA_INET_H_DEFAULTS): Define REPLACE_HTONL.
* doc/posix-functions/htons.texi (htons): Mention the module.
* doc/posix-functions/htonl.texi (htonl): Likewise.
* doc/posix-functions/ntohs.texi (ntohs): Likewise.
* doc/posix-functions/ntohl.texi (ntohl): Likewise.
+2024-08-10 Collin Funk <collin.funk1@gmail.com>
+
+ htonl: New module.
+ * modules/htonl: New file.
+ * lib/arpa_inet.c: New file.
+ * m4/htonl.m4: New file.
+ * modules/arpa_inet (Files): Add lib/arpa_inet.c.
+ (Depends-on): Add extern-inline.
+ * lib/arpa_inet.in.h (htons, htonl, ntohs, ntohl): New declarations.
+ * m4/arpa_inet_h.m4 (gl_ARPA_INET_H_DEFAULTS): Define REPLACE_HTONL.
+ * doc/posix-functions/htons.texi (htons): Mention the module.
+ * doc/posix-functions/htonl.texi (htonl): Likewise.
+ * doc/posix-functions/ntohs.texi (ntohs): Likewise.
+ * doc/posix-functions/ntohl.texi (ntohl): Likewise.
+
2024-08-10 Bruno Haible <bruno@clisp.org>
Make sure gperf-generated files are the same in VPATH builds.
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/htonl.html}
-Gnulib module: ---
+Gnulib module: htonl
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+HP-UX 11, mingw, MSVC 14, Android 4.4.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-HP-UX 11, mingw, MSVC 14, Android 4.4.
@end itemize
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/htons.html}
-Gnulib module: ---
+Gnulib module: htonl
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+HP-UX 11, mingw, MSVC 14, Android 4.4.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-HP-UX 11, mingw, MSVC 14, Android 4.4.
@end itemize
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/ntohl.html}
-Gnulib module: ---
+Gnulib module: htonl
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+HP-UX 11, mingw, MSVC 14, Android 4.4.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-HP-UX 11, mingw, MSVC 14, Android 4.4.
@end itemize
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/ntohs.html}
-Gnulib module: ---
+Gnulib module: htonl
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+HP-UX 11, mingw, MSVC 14, Android 4.4.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on some platforms:
-HP-UX 11, mingw, MSVC 14, Android 4.4.
@end itemize
--- /dev/null
+/* Inline functions for <arpa/inet.h>.
+
+ Copyright (C) 2024 Free Software Foundation, Inc.
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ This file is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#define _GL_ARPA_INET_INLINE _GL_EXTERN_INLINE
+#include <arpa/inet.h>
# include <ws2tcpip.h>
#endif
+#if @REPLACE_HTONL@
+# include <endian.h>
+#endif
+
+_GL_INLINE_HEADER_BEGIN
+#ifndef _GL_ARPA_INET_INLINE
+# define _GL_ARPA_INET_INLINE _GL_INLINE
+#endif
+
+
+#if @REPLACE_HTONL@
+
+/* Make sure we don't have any system definitions. */
+# undef htons
+# undef htonl
+# undef ntohs
+# undef ntohl
+
+/* Define our own. */
+# define htons rpl_htons
+# define htonl rpl_htonl
+# define ntohs rpl_ntohs
+# define ntohl rpl_ntohl
+
+/* Host to network byte order. */
+
+_GL_ARPA_INET_INLINE uint16_t
+htons (uint16_t value)
+{
+ return htobe16 (value);
+}
+
+_GL_ARPA_INET_INLINE uint32_t
+htonl (uint32_t value)
+{
+ return htobe32 (value);
+}
+
+/* Network to host byte order. */
+
+_GL_ARPA_INET_INLINE uint16_t
+ntohs (uint16_t value)
+{
+ return htobe16 (value);
+}
+
+_GL_ARPA_INET_INLINE uint32_t
+ntohl (uint32_t value)
+{
+ return htobe32 (value);
+}
+
+#endif
+
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
/* The definition of _GL_ARG_NONNULL is copied here. */
# endif
#endif
+_GL_INLINE_HEADER_END
#endif /* _@GUARD_PREFIX@_ARPA_INET_H */
#endif /* _@GUARD_PREFIX@_ARPA_INET_H */
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_DECL_INET_NTOP=1; AC_SUBST([HAVE_DECL_INET_NTOP])
HAVE_DECL_INET_PTON=1; AC_SUBST([HAVE_DECL_INET_PTON])
+ REPLACE_HTONL=0; AC_SUBST([REPLACE_HTONL])
REPLACE_INET_NTOP=0; AC_SUBST([REPLACE_INET_NTOP])
REPLACE_INET_PTON=0; AC_SUBST([REPLACE_INET_PTON])
])
--- /dev/null
+# htonl.m4
+# serial 1
+dnl Copyright (C) 2024 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Collin Funk.
+
+AC_DEFUN([gl_FUNC_HTONL],
+[
+ AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
+
+ if test $ac_cv_header_arpa_inet_h = yes; then
+ AC_CACHE_CHECK([if arpa/inet.h defines htonl, htons, ntohl, ntohs],
+ [gl_cv_func_htonl_working],
+ [gl_cv_func_htonl_working=no
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+[[
+#include <arpa/inet.h>
+]],
+[[
+/* Host to network. */
+int network_1 = htons (0.0);
+int network_2 = htonl (0.0);
+
+/* Network to host. */
+int host_1 = ntohs (0.0);
+int host_2 = ntohl (0.0);
+
+/* Make sure the variables get used. */
+return !(network_1 + network_2 + host_1 + host_2);
+]])],
+ [gl_cv_func_htonl_working=yes],
+ [gl_cv_func_htonl_working=no])
+ ])
+ if test $gl_cv_func_htonl_working = no; then
+ REPLACE_HTONL=1
+ fi
+ fi
+])
Files:
lib/arpa_inet.in.h
+lib/arpa_inet.c
m4/arpa_inet_h.m4
m4/sys_socket_h.m4
m4/socklen.m4
Depends-on:
+extern-inline
gen-header
include_next
snippet/arg-nonnull
Makefile.am:
BUILT_SOURCES += arpa/inet.h
+lib_SOURCES += arpa_inet.c
# We need the following in order to create <arpa/inet.h> when the system
# doesn't have one.
-e 's|@''HAVE_WS2TCPIP_H''@|$(HAVE_WS2TCPIP_H)|g' \
-e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \
-e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \
+ -e 's|@''REPLACE_HTONL''@|$(REPLACE_HTONL)|g' \
-e 's|@''REPLACE_INET_NTOP''@|$(REPLACE_INET_NTOP)|g' \
-e 's|@''REPLACE_INET_PTON''@|$(REPLACE_INET_PTON)|g' \
-e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
--- /dev/null
+Description:
+htonl, htons, ntohl, ntohs functions: convert between network and host
+byte order
+
+Files:
+m4/htonl.m4
+
+Depends-on:
+arpa_inet
+endian [test $REPLACE_HTONL = 1]
+
+configure.ac:
+gl_FUNC_HTONL
+
+Makefile.am:
+
+Include:
+<arpa/inet.h>
+
+Link:
+
+License:
+LGPLv2+
+
+Maintainer:
+all