From 7e92d0caec8bbc9e1d9dbc7289342e78adbb08ac Mon Sep 17 00:00:00 2001 From: Robert Scheck Date: Mon, 28 Nov 2022 17:25:13 +0100 Subject: [PATCH] Add inet_net_pton() to compat layer (for musl libc) (#75) --- compat/Makefile.am | 4 ++++ configure.ac | 5 +++++ include/Makefile.am | 1 + include/arpa/inet.h | 15 +++++++++++++++ update.sh | 1 + 5 files changed, 26 insertions(+) create mode 100644 include/arpa/inet.h diff --git a/compat/Makefile.am b/compat/Makefile.am index 03f7109..66e97ad 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -43,6 +43,10 @@ if !HAVE_FREEZERO libcompat_la_SOURCES += freezero.c endif +if !HAVE_INET_NET_PTON +libcompat_la_SOURCES += inet_net_pton.c +endif + if !HAVE_PIPE2 libcompat_la_SOURCES += pipe2.c endif diff --git a/configure.ac b/configure.ac index 5fa11f5..ee4a736 100644 --- a/configure.ac +++ b/configure.ac @@ -233,6 +233,10 @@ fi AC_SEARCH_LIBS([ibuf_open], [util]) AC_CHECK_FUNCS([ibuf_open]) +# check functions that are expected to be in libresolv +AC_SEARCH_LIBS([inet_net_pton],[resolv]) +AC_CHECK_FUNCS([inet_net_pton]) + # check functions that may be in different libs on other systems AC_SEARCH_LIBS([fts_open],[fts]) AC_CHECK_FUNCS([fts_open]) @@ -255,6 +259,7 @@ AM_CONDITIONAL([HAVE_UNVEIL], [test "x$ac_cv_func_unveil" = xyes]) AM_CONDITIONAL([HAVE_GETDTABLECOUNT], [test "x$ac_cv_func_getdtablecount" = xyes]) AM_CONDITIONAL([HAVE_PIPE2], [test "x$ac_cv_func_pipe2" = xyes]) AM_CONDITIONAL([HAVE_PPOLL], [test "x$ac_cv_func_ppoll" = xyes]) +AM_CONDITIONAL([HAVE_INET_NET_PTON], [test "x$ac_cv_func_inet_net_pton" = xyes]) AM_CONDITIONAL([HAVE_STRNVIS], [test "x$ac_cv_func_strnvis" = xyes]) AM_CONDITIONAL([BROKEN_STRNVIS], [test "x$ac_cv_broken_strnvis" = xyes]) AM_CONDITIONAL([HAVE_IMSG], [test "x$ac_cv_func_ibuf_open" = xyes]) diff --git a/include/Makefile.am b/include/Makefile.am index 995783f..274f936 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,4 +1,5 @@ noinst_HEADERS = +noinst_HEADERS += arpa/inet.h noinst_HEADERS += sys/_null.h noinst_HEADERS += sys/queue.h noinst_HEADERS += sys/socket.h diff --git a/include/arpa/inet.h b/include/arpa/inet.h new file mode 100644 index 0000000..d7a6408 --- /dev/null +++ b/include/arpa/inet.h @@ -0,0 +1,15 @@ +/* + * Public domain + * arpa/inet.h compatibility shim + */ + +#include_next + +#ifndef LIBCOMPAT_ARPA_INET_H +#define LIBCOMPAT_ARPA_INET_H + +#ifndef HAVE_INET_NET_PTON +int inet_net_pton(int, const char *, void *, size_t); +#endif + +#endif diff --git a/update.sh b/update.sh index b3bf97b..e29ac9a 100755 --- a/update.sh +++ b/update.sh @@ -55,6 +55,7 @@ for i in reallocarray.c recallocarray.c strtonum.c; do done ${CP_LIBC} "${libc_src}/hash/sha2.c" compat ${CP_LIBC} "${libc_src}/gen/vis.c" compat +${CP_LIBC} "${libc_src}/net/inet_net_pton.c" compat ${CP} "${libutil_src}/imsg.c" compat/ ${CP} "${libutil_src}/imsg-buffer.c" compat/ (cd compat; ${PATCH} -p0 < "${patches}/patch-imsg.c")