diff --git a/CronosAgent.c b/CronosAgent.c index b763a76..822fe3e 100644 --- a/CronosAgent.c +++ b/CronosAgent.c @@ -123,6 +123,7 @@ int main(int argc, const char* argv[]) print("\n"); print("CronosAgent for BrandMeister DMR Master Server\n"); print("Copyright 2016 Artem Prilutskiy (R3ABM, cyanide.burnout@gmail.com)\n"); + print("Software revision " STRING(VERSION) " build " BUILD "\n"); print("\n"); // Parameters for server @@ -283,20 +284,13 @@ int main(int argc, const char* argv[]) int mediaHandle; int remoteHandle; struct sockaddr_in proxySocketAddress; + socklen_t proxySocketLength = sizeof(proxySocketAddress); + int socketOptionValue = true; proxySocketAddress.sin_family = AF_INET; proxySocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); - proxySocketAddress.sin_port = 0; - remoteHandle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if((remoteHandle < 0) || - (bind(remoteHandle, (struct sockaddr*)&proxySocketAddress, proxySocketLength) < 0)) - { - print("Error opening port for Remote Control\n"); - return EXIT_FAILURE; - } - proxySocketAddress.sin_port = htons(proxyTrapPort); trapHandle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if((trapHandle < 0) || @@ -306,6 +300,16 @@ int main(int argc, const char* argv[]) return EXIT_FAILURE; } + proxySocketAddress.sin_port = 0; + remoteHandle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if((remoteHandle < 0) || + (bind(remoteHandle, (struct sockaddr*)&proxySocketAddress, proxySocketLength) < 0) || + (setsockopt(remoteHandle, IPPROTO_IP, IP_PKTINFO, &socketOptionValue, sizeof(socketOptionValue)) < 0)) + { + print("Error opening port for Remote Control\n"); + return EXIT_FAILURE; + } + proxySocketAddress.sin_port = 0; mediaHandle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if((mediaHandle < 0) || @@ -334,11 +338,6 @@ int main(int argc, const char* argv[]) return EXIT_FAILURE; } - // Configure socket options - - int value = true; - setsockopt(remoteHandle, IPPROTO_IP, IP_PKTINFO, &value, sizeof(value)); - #ifdef __linux__ // Initialize timer handle @@ -522,7 +521,7 @@ int main(int argc, const char* argv[]) if ((length >= sizeof(struct RewindData)) && ((serverAddress->ai_addr->sa_family == AF_INET) || /* Work-around for Linux */ (memcmp(&address, serverAddress->ai_addr, serverAddress->ai_addrlen) == 0)) && - (memcmp(incomingBuffer->sign, REWIND_PROTOCOL_SIGN, REWIND_SIGN_LENGTH) == 0)) + (memcmp(incomingBuffer->sign, REWIND_PROTOCOL_SIGN, REWIND_SIGN_LENGTH) == 0)) { uint16_t type = le16toh(incomingBuffer->type); size_t length = le16toh(incomingBuffer->length); @@ -701,6 +700,7 @@ int main(int argc, const char* argv[]) } // Handle timer to transmit keep-alive + #ifdef __linux__ if (event->data.fd == timerHandle) {