From a7310137cf09e382e2642e39d4ade88942d564c3 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 19 Jun 2026 17:21:47 +0200 Subject: [PATCH 1/3] tests: treat Glibc-style sendmmsg as default case As requested. Link: https://gitlab.freedesktop.org/libnice/libnice/-/merge_requests/353#note_3526962 Signed-off-by: Alyssa Ross --- tests/instrument-send.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/instrument-send.c b/tests/instrument-send.c index 3f79de87..65576dea 100644 --- a/tests/instrument-send.c +++ b/tests/instrument-send.c @@ -190,23 +190,23 @@ sendmsg (int sockfd, const struct msghdr *msg, int flags) } } -#ifndef __FreeBSD__ -int -sendmmsg (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags) -#else +#ifdef __FreeBSD__ ssize_t sendmmsg (int sockfd, struct mmsghdr *msgvec, size_t vlen, int flags) +#else +int +sendmmsg (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags) #endif { if (should_inject_ewouldblock ()) { errno = EWOULDBLOCK; return -1; } else { -#ifndef __FreeBSD__ - int ret = ((int (*) (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags)) ( +#ifdef __FreeBSD__ + ssize_t ret = ((int (*) (int sockfd, struct mmsghdr *msgvec, size_t vlen, int flags)) ( dlsym (RTLD_NEXT, "sendmmsg"))) (sockfd, msgvec, vlen, flags); #else - ssize_t ret = ((int (*) (int sockfd, struct mmsghdr *msgvec, size_t vlen, int flags)) ( + int ret = ((int (*) (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags)) ( dlsym (RTLD_NEXT, "sendmmsg"))) (sockfd, msgvec, vlen, flags); #endif if (ret != -1) { -- GitLab From 145c542b442f4deb89e1cc8bb92e1ca02456f918 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 15 Jun 2026 17:54:12 +0200 Subject: [PATCH 2/3] tests: check sendmmsg prototype in Meson Checking the actual prototype we have rather than using hardcoded libc checks improves portability by being compatible with libcs that aren't explictly handled, but use the same prototype as a known libc. For example, uClibc-ng uses the same prototype as FreeBSD, but wouldn't have been caught be the __FreeBSD__ check. --- tests/instrument-send.c | 4 ++-- tests/meson.build | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/instrument-send.c b/tests/instrument-send.c index 65576dea..9903619a 100644 --- a/tests/instrument-send.c +++ b/tests/instrument-send.c @@ -190,7 +190,7 @@ sendmsg (int sockfd, const struct msghdr *msg, int flags) } } -#ifdef __FreeBSD__ +#if defined(HAVE_FREEBSD_STYLE_SENDMMSG) ssize_t sendmmsg (int sockfd, struct mmsghdr *msgvec, size_t vlen, int flags) #else @@ -202,7 +202,7 @@ sendmmsg (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags) errno = EWOULDBLOCK; return -1; } else { -#ifdef __FreeBSD__ +#if defined(HAVE_FREEBSD_STYLE_SENDMMSG) ssize_t ret = ((int (*) (int sockfd, struct mmsghdr *msgvec, size_t vlen, int flags)) ( dlsym (RTLD_NEXT, "sendmmsg"))) (sockfd, msgvec, vlen, flags); #else diff --git a/tests/meson.build b/tests/meson.build index 7a4ce651..29888c29 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -102,9 +102,25 @@ if gst_dep.found() and not static_build ] gst_env = environment() dl_dep = cc.find_library('dl') + + instrument_send_lib_c_args = ['-DG_LOG_DOMAIN="libnice-instrument-send"'] + if cc.compiles(''' + #include + static int (*f) (int, struct mmsghdr *, unsigned int, int) = &sendmmsg; + ''', args: ['-D_GNU_SOURCE', '-Werror=incompatible-pointer-types'], name: 'Glibc-style sendmmsg') + # We consider this the default. + elif cc.compiles(''' + #include + static ssize_t (*f) (int, struct mmsghdr *, size_t, int) = &sendmmsg; + ''', args: ['-D_GNU_SOURCE', '-Werror=incompatible-pointer-types'], name: 'FreeBSD-style sendmmsg') + instrument_send_lib_c_args += ['-DHAVE_FREEBSD_STYLE_SENDMMSG'] + else + error('sendmmsg not present or has unknown prototype') + endif + instrument_send_lib = shared_library('instrument-send', 'instrument-send.c', - c_args: '-DG_LOG_DOMAIN="libnice-instrument-send"', + c_args: instrument_send_lib_c_args, dependencies: [dl_dep, gio_deps], ) gst_env.append('LD_PRELOAD', instrument_send_lib.full_path()) -- GitLab From 4565af6fe9fe01164b072710ad18e537608d3a40 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 17 Jun 2026 11:53:11 +0200 Subject: [PATCH 3/3] tests: support NetBSD/musl-style sendmmsg Fixes compilation for these platforms. --- tests/instrument-send.c | 6 ++++++ tests/meson.build | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/tests/instrument-send.c b/tests/instrument-send.c index 9903619a..20c02b30 100644 --- a/tests/instrument-send.c +++ b/tests/instrument-send.c @@ -193,6 +193,9 @@ sendmsg (int sockfd, const struct msghdr *msg, int flags) #if defined(HAVE_FREEBSD_STYLE_SENDMMSG) ssize_t sendmmsg (int sockfd, struct mmsghdr *msgvec, size_t vlen, int flags) +#elif defined(HAVE_NETBSD_STYLE_SENDMMSG) +int +sendmmsg (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags) #else int sendmmsg (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags) @@ -205,6 +208,9 @@ sendmmsg (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags) #if defined(HAVE_FREEBSD_STYLE_SENDMMSG) ssize_t ret = ((int (*) (int sockfd, struct mmsghdr *msgvec, size_t vlen, int flags)) ( dlsym (RTLD_NEXT, "sendmmsg"))) (sockfd, msgvec, vlen, flags); +#elif defined(HAVE_NETBSD_STYLE_SENDMMSG) + int ret = ((int (*) (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags)) ( + dlsym (RTLD_NEXT, "sendmmsg"))) (sockfd, msgvec, vlen, flags); #else int ret = ((int (*) (int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags)) ( dlsym (RTLD_NEXT, "sendmmsg"))) (sockfd, msgvec, vlen, flags); diff --git a/tests/meson.build b/tests/meson.build index 29888c29..3827dc2b 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -114,6 +114,11 @@ if gst_dep.found() and not static_build static ssize_t (*f) (int, struct mmsghdr *, size_t, int) = &sendmmsg; ''', args: ['-D_GNU_SOURCE', '-Werror=incompatible-pointer-types'], name: 'FreeBSD-style sendmmsg') instrument_send_lib_c_args += ['-DHAVE_FREEBSD_STYLE_SENDMMSG'] + elif cc.compiles(''' + #include + static int (*f) (int, struct mmsghdr *, unsigned int, unsigned int) = &sendmmsg; + ''', args: ['-D_GNU_SOURCE', '-Werror=incompatible-pointer-types'], name: 'NetBSD-style sendmmsg') + instrument_send_lib_c_args += ['-DHAVE_NETBSD_STYLE_SENDMMSG'] else error('sendmmsg not present or has unknown prototype') endif -- GitLab