From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 22 Jun 2021 12:49:11 +0000 (+0100) Subject: Changes to allow it to compile in FreeBSD and fix a few issues that were picked up... X-Git-Tag: 4.1-dev~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e925e196c837df5ec7e876aff13eb90d8054dfcd;p=thirdparty%2Fshairport-sync.git Changes to allow it to compile in FreeBSD and fix a few issues that were picked up by clang 10. --- diff --git a/common.c b/common.c index f87b7d29..fcbf4fb5 100644 --- a/common.c +++ b/common.c @@ -49,7 +49,16 @@ #include #include + +#ifdef COMPILE_FOR_LINUX #include +#endif + +#ifdef COMPILE_FOR_FREEBSD +#include +#include +#include +#endif #ifdef COMPILE_FOR_OSX #include @@ -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 +} + diff --git a/configure.ac b/configure.ac index 5849019a..4b107b33 100644 --- a/configure.ac +++ b/configure.ac @@ -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= argument must linux, freebsd, openbsd or darwin) + AC_MSG_ERROR(--with-os= 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 906519fd..35dbabd0 100644 --- 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) { diff --git a/definitions.h b/definitions.h index 02b09eb8..f6263026 100644 --- a/definitions.h +++ b/definitions.h @@ -1,14 +1,9 @@ #ifndef _DEFINITIONS_H #define _DEFINITIONS_H -//#include -//#include -//#include #include -//#include "audio.h" #include "config.h" -//#include "mdns.h" #if defined(__APPLE__) && defined(__MACH__) /* Apple OSX and iOS (Darwin). ------------------------------ */ @@ -23,6 +18,18 @@ #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 6d5933a2..d955c447 160000 --- a/pair_ap +++ b/pair_ap @@ -1 +1 @@ -Subproject commit 6d5933a2aa982fb8e7eb3f953ffa3bcf0e43a989 +Subproject commit d955c447dac0545803dee9c90312c9d42310e9b1 diff --git a/ptp-utilities.c b/ptp-utilities.c index 9890028d..bda461ff 100644 --- a/ptp-utilities.c +++ b/ptp-utilities.c @@ -24,6 +24,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "definitions.h" #include #include #include @@ -31,6 +32,10 @@ #include #include #include +#ifdef COMPILE_FOR_FREEBSD +#include +#include +#endif #define __STDC_FORMAT_MACROS #include "common.h" #include diff --git a/rtp.c b/rtp.c index 74110cfe..5050ea7b 100644 --- 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) diff --git a/shairport.c b/shairport.c index d143de66..45a08c7f 100644 --- a/shairport.c +++ b/shairport.c @@ -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);