]> Savannah Git Hosting - gnulib.git/commitdiff
htonl: New module.
authorCollin Funk <collin.funk1@gmail.com>
Sun, 11 Aug 2024 00:15:07 +0000 (17:15 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Sun, 11 Aug 2024 00:15:07 +0000 (17:15 -0700)
* 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.

ChangeLog
doc/posix-functions/htonl.texi
doc/posix-functions/htons.texi
doc/posix-functions/ntohl.texi
doc/posix-functions/ntohs.texi
lib/arpa_inet.c [new file with mode: 0644]
lib/arpa_inet.in.h
m4/arpa_inet_h.m4
m4/htonl.m4 [new file with mode: 0644]
modules/arpa_inet
modules/htonl [new file with mode: 0644]

index e31657d97c7ed89fc89aa1dad03f5622bb5129ba..111c08d415f790c0ac6572cf1bd3d4497b417dbd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+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.
index c3248e6ef01f5356f2deac20b87d52082e975e8d..a4411b4206c0c5de83650e4b5c03a02944b914f1 100644 (file)
@@ -4,15 +4,15 @@
 
 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
index 3111dee25afa936705c3c0ec4e28da6c1612977a..ee413f223f865911a552af64a2cc3fa2c421a14f 100644 (file)
@@ -4,15 +4,15 @@
 
 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
index ba5b9560a2274ee13e4363f6c20bfa3d641433c4..17b61633253481b9923671d85b6f42329a18a4a5 100644 (file)
@@ -4,15 +4,15 @@
 
 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
index 4f11eb185685e0b850e0c42437a1b42f497e791c..2fe65fdb6be8cd3d00a5025cdb9cb1ef65701a18 100644 (file)
@@ -4,15 +4,15 @@
 
 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
diff --git a/lib/arpa_inet.c b/lib/arpa_inet.c
new file mode 100644 (file)
index 0000000..589ee9c
--- /dev/null
@@ -0,0 +1,21 @@
+/* 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>
index b04ff7212b9cc91c89d35dbfe381ec8a16376289..faaf958443d22375de1c2c45523afcdcec7f0b32 100644 (file)
 # 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.  */
@@ -150,6 +204,7 @@ _GL_WARN_ON_USE (inet_pton, "inet_pton is unportable - "
 # endif
 #endif
 
+_GL_INLINE_HEADER_END
 
 #endif /* _@GUARD_PREFIX@_ARPA_INET_H */
 #endif /* _@GUARD_PREFIX@_ARPA_INET_H */
index 9eac86d7e88677ca03b36c47469b775b7a5d623c..4a2538eaf5914a991c2c9e0b7c1f45304fce3a05 100644 (file)
@@ -70,6 +70,7 @@ AC_DEFUN([gl_ARPA_INET_H_DEFAULTS],
   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])
 ])
diff --git a/m4/htonl.m4 b/m4/htonl.m4
new file mode 100644 (file)
index 0000000..aee4f27
--- /dev/null
@@ -0,0 +1,42 @@
+# 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
+])
index 3a6fd695618a47b6e05434c8fc92d568fc6ad5eb..3134c706516e206b8ac3c246c9a889895c9d2ad0 100644 (file)
@@ -3,11 +3,13 @@ A GNU-like <arpa/inet.h>.
 
 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
@@ -22,6 +24,7 @@ AC_PROG_MKDIR_P
 
 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.
@@ -40,6 +43,7 @@ arpa/inet.h: arpa_inet.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON
              -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)' \
diff --git a/modules/htonl b/modules/htonl
new file mode 100644 (file)
index 0000000..cb393e0
--- /dev/null
@@ -0,0 +1,26 @@
+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