Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions DigestPlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
#include <unistd.h>
#include <getopt.h>
#include <sys/time.h>
#ifdef __linux__
#include <sys/timerfd.h>
#include <endian.h>
#elif __APPLE__
#include <dispatch/dispatch.h>
#include <mach/mach_time.h>
#include <libkern/OSByteOrder.h>
// macOS compatibility macros for endian conversion
#define htole32(x) OSSwapHostToLittleInt32(x)
#define htole16(x) OSSwapHostToLittleInt16(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#endif

#include "Version.h"
#include "RewindClient.h"
Expand Down Expand Up @@ -217,6 +229,7 @@ int main(int argc, char* argv[])

// Initialize timer handle

#ifdef __linux__
int handle;
struct itimerspec interval;

Expand All @@ -228,6 +241,12 @@ int main(int argc, char* argv[])

handle = timerfd_create(CLOCK_MONOTONIC, 0);
timerfd_settime(handle, 0, &interval, NULL);
#elif __APPLE__
// macOS timer implementation using nanosleep
struct timespec timer_interval;
timer_interval.tv_sec = 0;
timer_interval.tv_nsec = TDMA_FRAME_DURATION * 1000000;
#endif

// Transmit voice header

Expand All @@ -247,8 +266,17 @@ int main(int argc, char* argv[])
uint8_t* limit = buffer + 3 * size;

// Wait for timer event (60 milliseconds)
#ifdef __linux__
while (read(handle, &mark, sizeof(uint64_t)) > 0)
#elif __APPLE__
while (1)
#endif
{
#ifdef __APPLE__
// Sleep for the timer interval on macOS
nanosleep(&timer_interval, NULL);
#endif

pointer = buffer;
while ((pointer < limit) &&
(read(STDIN_FILENO, pointer, size) == size))
Expand Down Expand Up @@ -299,7 +327,9 @@ int main(int argc, char* argv[])

// Clean up

#ifdef __linux__
close(handle);
#endif
TransmitRewindClose(context);
ReleaseRewindContext(context);

Expand Down
11 changes: 10 additions & 1 deletion RewindClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,18 @@ static int CompareAddresses(struct sockaddr* value1, struct sockaddr_in6* value2
(IN6_IS_ADDR_V4MAPPED(&value2->sin6_addr)))
{
value = (struct sockaddr_in*)value1;
#ifdef __linux__
return
(value->sin_addr.s_addr - value2->sin6_addr.__in6_u.__u6_addr32[3]) |
(value->sin_port - value2->sin6_port);
#else
// For macOS and other systems, access the IPv6 address bytes directly
uint32_t ipv4_from_v6;
memcpy(&ipv4_from_v6, &value2->sin6_addr.s6_addr[12], 4);
return
(value->sin_addr.s_addr - ipv4_from_v6) |
(value->sin_port - value2->sin6_port);
#endif
}

if ((value1->sa_family == AF_INET6) &&
Expand Down Expand Up @@ -265,7 +274,7 @@ int ConnectRewindClient(struct RewindContext* context, const char* location, con
if (attempt < ATTEMPT_COUNT)
{
length -= sizeof(struct RewindData);
length += sprintf(buffer->data + length, "%s", password);
length += sprintf((char*)buffer->data + length, "%s", password);
SHA256(buffer->data, length, digest);
TransmitRewindData(context, REWIND_TYPE_AUTHENTICATION, REWIND_FLAG_NONE, digest, SHA256_DIGEST_LENGTH);
attempt ++;
Expand Down