bin_PROGRAMS = nqptp
nqptp_SOURCES = nqptp.c nqptp-clock-sources.c nqptp-message-handlers.c nqptp-utilities.c general-utilities.c debug.c
-AM_CFLAGS = -fno-common -Wno-multichar -Wall -Wextra -Wno-clobbered -Wno-psabi -pthread
+AM_CFLAGS = -fno-common -Wall -Wextra -pthread --include=config.h
CLEANFILES =
if USE_GIT
install-exec-hook:
+if BUILD_FOR_LINUX
[ -e /lib/systemd/system ] || mkdir -p /lib/systemd/system
cp nqptp.service /lib/systemd/system
+endif
+ # no installer for FreeBSD yet
+
AC_PREREQ([2.68])
AC_INIT([nqptp], [1.1-dev], [4265913+mikebrady@users.noreply.github.com])
AM_INIT_AUTOMAKE
+AC_CANONICAL_HOST
+
+build_linux=no
+build_freebsd=no
+
+# Detect the target system
+case "${host_os}" in
+ linux*)
+ build_linux=yes
+ ;;
+ freebsd*)
+ build_freebsd=yes
+ ;;
+ *)
+ AC_MSG_ERROR(["OS $host_os is not supported"])
+ ;;
+esac
+
+# Pass the conditionals to automake
+AM_CONDITIONAL([BUILD_FOR_LINUX], [test "$build_linux" = "yes"])
+AM_CONDITIONAL([BUILD_FOR_FREEBSD], [test "$build_freebsd" = "yes"])
+
+if test "x$build_linux" = "xyes" ; then
+ AC_DEFINE([CONFIG_FOR_LINUX], 1, [Build for Linux.])
+fi
+if test "x$build_freebsd" = "xyes" ; then
+ AC_DEFINE([CONFIG_FOR_FREEBSD], 1, [Build for FreeBSD.])
+fi
AC_CHECK_PROGS([GIT], [git])
if test -n "$GIT"; then
#include <string.h>
#include <sys/types.h>
+#ifdef CONFIG_FOR_FREEBSD
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+
#ifndef FIELD_SIZEOF
#define FIELD_SIZEOF(t, f) (sizeof(((t *)0)->f))
#endif
#include <errno.h>
#include <fcntl.h> // fcntl etc.
#include <ifaddrs.h> // getifaddrs
+
+#ifdef CONFIG_FOR_LINUX
#include <linux/if_packet.h> // sockaddr_ll
+#endif
+
+#ifdef CONFIG_FOR_FREEBSD
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <net/if_types.h>
+#include <net/if_dl.h>
+#endif
+
#include <netdb.h> // getaddrinfo etc.
#include <stdio.h> // snprintf
#include <stdlib.h> // malloc, free
}
}
+
uint64_t get_self_clock_id() {
// make up a clock ID based on an interfaces' MAC
char local_clock_id[8];
} else {
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)) {
found = 1;
}
}
+#else
+// This AF_LINK stuff hasn't been tested!
+#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);
+ int i;
+ 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);
}
uint64_t result;
memcpy(&result, local_clock_id, sizeof(result));
return result;
-}
\ No newline at end of file
+}
#include <signal.h> // SIGTERM and stuff like that
+#ifdef CONFIG_FOR_FREEBSD
+#include <sys/socket.h>
+#include <netinet/in.h>
+#endif
+
#ifndef FIELD_SIZEOF
#define FIELD_SIZEOF(t, f) (sizeof(((t *)0)->f))
#endif
if (ftruncate(shm_fd, sizeof(struct shm_structure)) == -1) {
die("failed to set size of shared memory \"%s\".", STORAGE_ID);
}
+
+#ifdef CONFIG_FOR_FREEBSD
+ shared_memory =
+ (struct shm_structure *)mmap(NULL, sizeof(struct shm_structure), PROT_READ | PROT_WRITE,
+ MAP_SHARED, shm_fd, 0);
+#endif
+
+#ifdef CONFIG_FOR_LINUX
shared_memory =
(struct shm_structure *)mmap(NULL, sizeof(struct shm_structure), PROT_READ | PROT_WRITE,
MAP_LOCKED | MAP_SHARED, shm_fd, 0);
+#endif
+
if (shared_memory == (struct shm_structure *)-1) {
die("failed to mmap shared memory \"%s\".", STORAGE_ID);
}