]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Changes to allow it to compile in FreeBSD and fix a few issues that were picked up...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Tue, 22 Jun 2021 12:49:11 +0000 (13:49 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Tue, 22 Jun 2021 12:49:11 +0000 (13:49 +0100)
common.c
configure.ac
dacp.c
definitions.h
pair_ap
ptp-utilities.c
rtp.c
shairport.c

index f87b7d29bd0e9822520acc24edf018a82ef294e4..fcbf4fb5f253192f9495c1dc372d63e3ace5cf70 100644 (file)
--- a/common.c
+++ b/common.c
 #include <unistd.h>
 
 #include <ifaddrs.h>
+
+#ifdef COMPILE_FOR_LINUX
 #include <netpacket/packet.h>
+#endif
+
+#ifdef COMPILE_FOR_FREEBSD
+#include <netinet/in.h>
+#include <net/if_types.h>
+#include <net/if_dl.h>
+#endif
 
 #ifdef COMPILE_FOR_OSX
 #include <CoreServices/CoreServices.h>
@@ -1954,6 +1963,7 @@ int get_device_id(uint8_t *id, int int_length) {
     t = id;
     int found = 0;
     for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ #ifdef AF_PACKET
       if ((ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET)) {
         struct sockaddr_ll *s = (struct sockaddr_ll *)ifa->ifa_addr;
         if ((strcmp(ifa->ifa_name, "lo") != 0) && (found == 0)) {
@@ -1963,8 +1973,25 @@ int get_device_id(uint8_t *id, int int_length) {
           found = 1;
         }
       }
+ #else
+ #ifdef AF_LINK
+       struct sockaddr_dl * sdl = (struct sockaddr_dl *) ifa->ifa_addr;
+       if ((sdl) && (sdl->sdl_family == AF_LINK)) {
+        if (sdl->sdl_type == IFT_ETHER) {
+          char *s = LLADDR(sdl);
+          for (i = 0; i < sdl->sdl_alen; i++) {
+            debug(1,"char %d: \"%c\".", i, *s);
+            *t++ = (uint8_t)*s++;   
+          }   
+          found = 1;
+        }
+      }
+ #endif
+ #endif
+
     }
     freeifaddrs(ifaddr);
   }
   return response;
-}
\ No newline at end of file
+}
+
index 5849019adf6e84201451ae958e147e7ad888dcb5..4b107b339f4238523b67d9f99d0d53de2605d3d8 100644 (file)
@@ -25,7 +25,7 @@ fi
 with_os=`echo ${with_os} | tr '[[:upper:]]' '[[:lower:]]' `
 
 if test "x${with_os}" != xlinux && "x${with_os}" != xfreebsd && "x${with_os}" != xdarwin ; then
-       AC_MSG_ERROR(--with-os=<arg> argument must linux, freebsd, openbsd or darwin)
+       AC_MSG_ERROR(--with-os=<arg> argument must linux freebsd openbsd or darwin)
 fi
 
 # Checks for programs.
@@ -44,11 +44,11 @@ if test "x${with_os}" = xopenbsd ; then
  AC_CHECK_LIB([c],[clock_gettime], , AC_MSG_ERROR(libc needed))
 fi
 
+# Pass the conditionals to automake
 AM_CONDITIONAL([BUILD_FOR_LINUX], [test "x${with_os}" = xlinux ])
 AM_CONDITIONAL([BUILD_FOR_FREEBSD], [test "x${with_os}" = xfreebsd ])
 AM_CONDITIONAL([BUILD_FOR_OPENBSD], [test "x${with_os}" = xopenbsd ])
 
-
 ##### Some build systems are not fully using pkg-config, so we can use the flag ${with_pkg_config} on a case-by-case basis
 ##### to control how to deal with them
 ##### Note -- this flag is sometimes ignored, especially for newer packages
@@ -383,8 +383,14 @@ AC_ARG_WITH(airplay-2, [AS_HELP_STRING([--with-airplay-2],[Build for AirPlay 2])
 if test "x$with_airplay_2" = "xyes" ; then
   AC_DEFINE([CONFIG_AIRPLAY_2], 1, [Build for AirPlay 2])
   AC_MSG_RESULT(>>Include libraries required for AirPlay 2)
-  PKG_CHECK_MODULES([plist], [libplist >= 2.0.0],[CFLAGS="${plist_CFLAGS} ${CFLAGS}" LIBS="${plist_LIBS} ${LIBS}"],[AC_MSG_ERROR(AirPlay 2 support requires libplist 2.0.0 or later -- libplist-dev suggested!)])
-  AC_CHECK_LIB([sodium], [sodium_init], ,[AC_MSG_ERROR([AirPlay 2 support requires libsodium -- libsodium-dev suggested])])
+  if test "x${with_os}" = xlinux  ; then
+      PKG_CHECK_MODULES([libplist], [libplist >= 2.0.0],[CFLAGS="${libplist_CFLAGS} ${CFLAGS}" LIBS="${libplist_LIBS} ${LIBS}"],[AC_MSG_ERROR(AirPlay 2 support requires libplist 2.0.0 or later -- libplist-dev suggested!)])
+  fi
+  if test "x${with_os}" = xfreebsd  ; then
+      PKG_CHECK_MODULES([libplist], [libplist-2.0 >= 2.0.0],[CFLAGS="${libplist_CFLAGS} ${CFLAGS}" LIBS="${libplist_LIBS} ${LIBS}"],[AC_MSG_ERROR(AirPlay 2 support requires libplist 2.0.0 or later -- search for pkg libplist-2.2.0 or later!)])
+  fi
+  PKG_CHECK_MODULES([libsodium], [libsodium],[CFLAGS="${libsodium_CFLAGS} ${CFLAGS}" LIBS="${libsodium_LIBS} ${LIBS}"],[AC_MSG_ERROR(AirPlay 2 support requires libsodium -- libsodium-dev suggested)])
+#  AC_CHECK_LIB([sodium], [sodium_init], ,[AC_MSG_ERROR([AirPlay 2 support requires libsodium -- libsodium-dev suggested])])
   AC_CHECK_LIB([avutil],[av_malloc], [], [AC_MSG_ERROR([Airplay 2 support requires libavutil -- libavutil-dev suggested])])
   AC_CHECK_LIB([avcodec],[avcodec_find_encoder], [], [AC_MSG_ERROR([AirPlay 2 support requires libavcodec -- libavcodec-dev suggested])])
   AC_CHECK_LIB([avformat],[avformat_new_stream], [], [AC_MSG_ERROR([AirPlay 2 support requires libavformat -- libavformat-dev suggested])])
diff --git a/dacp.c b/dacp.c
index 906519fd7e2c63c7b1ec231c9f047a221ca442cf..35dbabd0ccc04069ebae3c9cc2e6e300bcd26ba5 100644 (file)
--- a/dacp.c
+++ b/dacp.c
@@ -465,7 +465,7 @@ void dacp_monitor_port_update_callback(char *dacp_id, uint16_t port) {
         "dacp_monitor_port_update_callback with Remote ID \"%s\", target ID \"%s\" and port "
         "number %d.",
         dacp_id, dacp_server.dacp_id, port);
-  if ((dacp_id == NULL) || (dacp_server.dacp_id == NULL)) {
+  if ((dacp_id == NULL) || (dacp_server.dacp_id[0] == '\0')) {
     warn("dacp_id or dacp_server.dacp_id NULL detected");
   } else {
     if (strcmp(dacp_id, dacp_server.dacp_id) == 0) {
index 02b09eb8b762b6b9e1229fea77701bc1bac2bc8c..f626302611aebc8bfcf35557fff619a8e0e70e8d 100644 (file)
@@ -1,14 +1,9 @@
 #ifndef _DEFINITIONS_H
 #define _DEFINITIONS_H
 
-//#include <libconfig.h>
-//#include <signal.h>
-//#include <stdint.h>
 #include <sys/socket.h>
 
-//#include "audio.h"
 #include "config.h"
-//#include "mdns.h"
 
 #if defined(__APPLE__) && defined(__MACH__)
 /* Apple OSX and iOS (Darwin). ------------------------------ */
 #define COMPILE_FOR_LINUX_AND_FREEBSD_AND_CYGWIN_AND_OPENBSD 1
 #endif
 
+#if defined(__linux__)
+#define COMPILE_FOR_LINUX 1
+#endif
+
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+#define COMPILE_FOR_BSD 1
+#endif
+
+#if defined(__FreeBSD__)
+#define COMPILE_FOR_FREEBSD 1
+#endif
+
 // struct sockaddr_in6 is bigger than struct sockaddr. derp
 #ifdef AF_INET6
 #define SOCKADDR struct sockaddr_storage
diff --git a/pair_ap b/pair_ap
index 6d5933a2aa982fb8e7eb3f953ffa3bcf0e43a989..d955c447dac0545803dee9c90312c9d42310e9b1 160000 (submodule)
--- a/pair_ap
+++ b/pair_ap
@@ -1 +1 @@
-Subproject commit 6d5933a2aa982fb8e7eb3f953ffa3bcf0e43a989
+Subproject commit d955c447dac0545803dee9c90312c9d42310e9b1
index 9890028db8ace8f927621051c3c7651337d52081..bda461ff50e37f3ed280c2627f981acb58746fd7 100644 (file)
@@ -24,6 +24,7 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include "definitions.h"
 #include <arpa/inet.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/mman.h>
+#ifdef COMPILE_FOR_FREEBSD
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
 #define __STDC_FORMAT_MACROS
 #include "common.h"
 #include <inttypes.h>
diff --git a/rtp.c b/rtp.c
index 74110cfedf40570e12ef0fb7ba5702589874f437..5050ea7b5bd9304dea684a27da87e63f3d201523 100644 (file)
--- a/rtp.c
+++ b/rtp.c
@@ -1498,7 +1498,8 @@ void *rtp_event_receiver(void *arg) {
   socklen_t addr_size = sizeof(remote_addr);
 
   int fd = accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
-  pthread_cleanup_push(socket_cleanup, (void *)fd);
+  intptr_t pfd = fd;
+  pthread_cleanup_push(socket_cleanup, (void *)pfd);
   int finished = 0;
   do {
     nread = recv(fd, packet, sizeof(packet), 0);
@@ -1792,11 +1793,11 @@ void *rtp_realtime_audio_receiver(void *arg) {
 }
 
 ssize_t buffered_read(buffered_tcp_desc *descriptor, void *buf, size_t count) {
-  ssize_t response;
+  ssize_t response = -1;
   if (pthread_mutex_lock(&descriptor->mutex) != 0)
     debug(1, "problem with mutex");
   pthread_cleanup_push(mutex_unlock, (void *)&descriptor->mutex);
-  if ((descriptor->closed == 0)) {
+  if (descriptor->closed == 0) {
     while ((descriptor->buffer_occupancy == 0) && (descriptor->error_code == 0)) {
       if (pthread_cond_wait(&descriptor->not_empty_cv, &descriptor->mutex))
         debug(1, "Error waiting for buffered read");
@@ -1848,7 +1849,8 @@ void *buffered_tcp_reader(void *arg) {
   socklen_t addr_size = sizeof(remote_addr);
   int finished = 0;
   int fd = accept(descriptor->sock_fd, (struct sockaddr *)&remote_addr, &addr_size);
-  pthread_cleanup_push(socket_cleanup, (void *)fd);
+  intptr_t pfd = fd;
+  pthread_cleanup_push(socket_cleanup, (void *)pfd);
 
   do {
     if (pthread_mutex_lock(&descriptor->mutex) != 0)
index d143de66f645a38fb448dbcb184f49079c85e26d..45a08c7f6259852d2b469b5102e9fe69dde3eb95 100644 (file)
@@ -115,6 +115,10 @@ pid_t pid;
 int this_is_the_daemon_process = 0;
 #endif
 
+#ifndef UUID_STR_LEN
+#define UUID_STR_LEN 36
+#endif
+
 pthread_t rtsp_listener_thread;
 
 int killOption = 0;
@@ -1616,6 +1620,7 @@ int main(int argc, char **argv) {
   // with thanks
   uuid_t binuuid;
   uuid_generate_random(binuuid);
+  
   char *uuid = malloc(UUID_STR_LEN);
   /* Produces a UUID string at uuid consisting of lower-case letters. */
   uuid_unparse_lower(binuuid, uuid);