Alyssa Ross bfd995f9df tcpclientsrc, tcpserversrc: fix building for musl
musl only exposes struct tcp_info when _GNU_SOURCE is defined.

Fixes: b4bef7fd35 ("tcpclientsrc, tcpserversrc: fix tcp stats gathering")
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8612>
2025-03-11 12:43:55 +01:00

49 lines
1.5 KiB
C

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _GNU_SOURCE /* struct tcp_info */
/* macOS and iOS have the .h files but the tcp_info struct is private API */
#if defined(HAVE_NETINET_TCP_H) && defined(HAVE_NETINET_IN_H) && defined(HAVE_SYS_SOCKET_H)
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <sys/socket.h>
#if defined(TCP_INFO)
#define HAVE_SOCKET_METRIC_HEADERS
#endif
#endif
#include "gsttcpsrcstats.h"
void
gst_tcp_stats_from_socket (GstStructure * structure, GSocket * socket)
{
#ifdef HAVE_SOCKET_METRIC_HEADERS
struct tcp_info info = { 0, };
socklen_t info_len = sizeof (info);
int fd = g_socket_get_fd (socket);
if (getsockopt (fd, IPPROTO_TCP, TCP_INFO, &info, &info_len) == 0) {
/* this is system-specific */
#ifdef HAVE_BSD_TCP_INFO
gst_structure_set (structure,
"reordering", G_TYPE_UINT, info.__tcpi_reordering,
"unacked", G_TYPE_UINT, info.__tcpi_unacked,
"sacked", G_TYPE_UINT, info.__tcpi_sacked,
"lost", G_TYPE_UINT, info.__tcpi_lost,
"retrans", G_TYPE_UINT, info.__tcpi_retrans,
"fackets", G_TYPE_UINT, info.__tcpi_fackets, NULL);
#elif defined(HAVE_LINUX_TCP_INFO)
gst_structure_set (structure,
"reordering", G_TYPE_UINT, info.tcpi_reordering,
"unacked", G_TYPE_UINT, info.tcpi_unacked,
"sacked", G_TYPE_UINT, info.tcpi_sacked,
"lost", G_TYPE_UINT, info.tcpi_lost,
"retrans", G_TYPE_UINT, info.tcpi_retrans,
"fackets", G_TYPE_UINT, info.tcpi_fackets, NULL);
#endif
}
#endif
}