blob: 9a6bd3ea8e662f572e1b7d64bf5852ead16b6707 [file] [log] [blame]
From 1ae38f7ba738c2adaaebc66576143f96cdd5e962 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
Date: Tue, 9 Jun 2015 10:59:42 +0200
Subject: [PATCH] ptp: Check for the actual API we use instead of just looking
for __APPLE__
Should fix the build on FreeBSD, DragonFly and other BSDs.
https://bugzilla.gnome.org/show_bug.cgi?id=750530
---
configure.ac | 38 ++++++++++++++++++++++++++++++++++++++
libs/gst/helpers/gst-ptp-helper.c | 14 +++++++++-----
2 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac
index 71309c9..3717518 100644
--- a/configure.ac
+++ b/configure.ac
@@ -325,6 +325,44 @@ AC_PATH_PROG([SETCAP], [setcap], [no], [$PATH:/usr/bin:/bin:/usr/sbin:/sbin])
if test "x$HAVE_PTP" = "xyes"; then
AC_DEFINE(HAVE_PTP, 1, [PTP support available])
+AC_MSG_CHECKING([for SIOCGIFCONF, SIOCGIFFLAGS and SIOCGIFHWADDR])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+ [[
+ #include <sys/ioctl.h>
+ #include <net/if.h>
+ ]],
+ [[
+ struct ifreq ifr;
+ struct ifconf ifc;
+ ioctl(0, SIOCGIFCONF, &ifc);
+ ioctl(0, SIOCGIFFLAGS, &ifr);
+ ioctl(0, SIOCGIFHWADDR, &ifr);
+ int dummy = ifr.ifr_hwaddr.sa_data[0];
+ ]])], [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_SIOCGIFCONF_SIOCGIFFLAGS_SIOCGIFHWADDR, 1, [SIOCGIFCONF, SIOCGIFFLAGS and SIOCGIFHWADDR is available])
+ ], [
+ AC_MSG_RESULT(no)
+])
+
+AC_MSG_CHECKING([for getifaddrs() and AF_LINK])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+ [[
+ #include <ifaddrs.h>
+ #include <net/if.h>
+ #include <net/if_dl.h>
+ ]],
+ [[
+ struct ifaddrs *ifaddr;
+ getifaddrs(&ifaddr);
+ int dummy = (ifaddr->ifa_flags & IFF_LOOPBACK) && ifaddr->ifa_addr->sa_family != AF_LINK;
+ ]])], [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_GETIFADDRS_AF_LINK, 1, [getifaddrs() and AF_LINK is available])
+ ], [
+ AC_MSG_RESULT(no)
+ ])
+
AC_MSG_CHECKING([how to install gst-ptp-helper])
if test "x$with_ptp_helper_permissions" = "xauto"; then
if test "x$gst_ptp_have_cap" = "xyes" -a "x$SETCAP" != "xno"; then
diff --git a/libs/gst/helpers/gst-ptp-helper.c b/libs/gst/helpers/gst-ptp-helper.c
index 45a0206..6c753df 100644
--- a/libs/gst/helpers/gst-ptp-helper.c
+++ b/libs/gst/helpers/gst-ptp-helper.c
@@ -41,7 +41,7 @@
#include <netinet/in.h>
#include <string.h>
-#ifdef __APPLE__
+#ifdef HAVE_GETIFADDRS_AF_LINK
#include <ifaddrs.h>
#include <net/if_dl.h>
#endif
@@ -240,7 +240,7 @@ setup_sockets (void)
/* Probe all non-loopback interfaces */
if (!ifaces) {
-#ifndef __APPLE__
+#if defined(HAVE_SIOCGIFCONF_SIOCGIFFLAGS_SIOCGIFHWADDR)
struct ifreq ifr;
struct ifconf ifc;
gchar buf[8192];
@@ -269,7 +269,7 @@ setup_sockets (void)
ifaces = probed_ifaces;
}
}
-#else
+#elif defined(HAVE_GETIFADDRS_AF_LINK)
struct ifaddrs *ifaddr, *ifa;
if (getifaddrs (&ifaddr) != -1) {
@@ -291,6 +291,8 @@ setup_sockets (void)
g_ptr_array_add (arr, NULL);
ifaces = probed_ifaces = (gchar **) g_ptr_array_free (arr, FALSE);
}
+#else
+#warning "Implement something to list all network interfaces"
#endif
}
@@ -298,7 +300,7 @@ setup_sockets (void)
if (clock_id == (guint64) - 1) {
gboolean success = FALSE;
-#ifndef __APPLE__
+#if defined(HAVE_SIOCGIFCONF_SIOCGIFFLAGS_SIOCGIFHWADDR)
struct ifreq ifr;
if (ifaces) {
@@ -356,7 +358,7 @@ setup_sockets (void)
}
}
}
-#else
+#elif defined(HAVE_GETIFADDRS_AF_LINK)
struct ifaddrs *ifaddr, *ifa;
if (getifaddrs (&ifaddr) != -1) {
@@ -405,6 +407,8 @@ setup_sockets (void)
freeifaddrs (ifaddr);
}
+#else
+#warning "Implement something to get MAC addresses of network interfaces"
#endif
if (!success) {
--
2.1.4