Skip to content

Commit

Permalink
Changes to allow it to compile in FreeBSD and fix a few issues that w…
Browse files Browse the repository at this point in the history
…ere picked up by clang 10.
  • Loading branch information
mikebrady committed Jun 22, 2021
1 parent 6295b35 commit e925e19
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 16 deletions.
29 changes: 28 additions & 1 deletion common.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@
#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>
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}
}

14 changes: 10 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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])])
Expand Down
2 changes: 1 addition & 1 deletion dacp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 12 additions & 5 deletions definitions.h
Original file line number Diff line number Diff line change
@@ -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). ------------------------------ */
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pair_ap
Submodule pair_ap updated 1 files
+7 −1 pair_homekit.c
5 changes: 5 additions & 0 deletions ptp-utilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include "definitions.h"
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <pthread.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>
Expand Down
10 changes: 6 additions & 4 deletions rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions shairport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e925e19

Please sign in to comment.