4
Fork 0

External Server port is allocated dynamically starting now

This commit is contained in:
R3ABM Artem 2016-07-10 09:56:15 +03:00
parent fb9e8c3bf0
commit bca4ec2c2e

View file

@ -125,14 +125,14 @@ int main(int argc, const char* argv[])
print("Copyright 2016 Artem Prilutskiy (R3ABM, cyanide.burnout@gmail.com)\n");
print("\n");
// Parameters of server
// Parameters for server
const char* serverPort = STRING(REWIND_DEFAULT_PORT);
const char* serverLocation = NULL;
const char* serverPassword = NULL;
struct addrinfo* serverAddress = NULL;
// Parameters of repeater
// Parameters for repeater
int proxyTrapPort = 162;
int proxyMediaPort = KAIROS_HAM_DEFAULT_PORT;
@ -154,14 +154,13 @@ int main(int argc, const char* argv[])
{ "server-password", required_argument, NULL, 'w' },
{ "server-address", required_argument, NULL, 's' },
{ "server-port", required_argument, NULL, 'p' },
{ "media-port", required_argument, NULL, 'b' },
{ "trap-port", required_argument, NULL, 't' },
{ "service-mode", required_argument, NULL, 'm' },
{ NULL, 0, NULL, 0 }
};
int selection = 0;
while ((selection = getopt_long(argc, CAST(char* const*, argv), "n:r:c:w:s:p:b:t:m:", options, NULL)) != EOF)
while ((selection = getopt_long(argc, CAST(char* const*, argv), "n:r:c:w:s:p:t:m:", options, NULL)) != EOF)
switch (selection)
{
case 'n':
@ -188,10 +187,6 @@ int main(int argc, const char* argv[])
serverPort = optarg;
break;
case 'b':
proxyMediaPort = strtol(optarg, NULL, 10);
break;
case 't':
proxyTrapPort = strtol(optarg, NULL, 10);
break;
@ -215,7 +210,6 @@ int main(int argc, const char* argv[])
" --server-password <access password of BrandMeister DMR Server>\n"
" --server-address <domain name of BrandMeister DMR Server>\n"
" --server-port <local port for BrandMeister DMR Server>\n"
" --media-port <media port for KAIROS External Servier>\n"
" --trap-port <port for SNMP Traps>\n"
" --service-mode <set of bits>\n"
" bit 0 - print to standard output\n"
@ -289,6 +283,7 @@ int main(int argc, const char* argv[])
int mediaHandle;
int remoteHandle;
struct sockaddr_in proxySocketAddress;
socklen_t proxySocketLength = sizeof(proxySocketAddress);
proxySocketAddress.sin_family = AF_INET;
proxySocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);
@ -296,7 +291,7 @@ int main(int argc, const char* argv[])
proxySocketAddress.sin_port = 0;
remoteHandle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if((remoteHandle < 0) ||
(bind(remoteHandle, (struct sockaddr*)&proxySocketAddress, sizeof(proxySocketAddress)) < 0))
(bind(remoteHandle, (struct sockaddr*)&proxySocketAddress, proxySocketLength) < 0))
{
print("Error opening port for Remote Control\n");
return EXIT_FAILURE;
@ -305,18 +300,19 @@ int main(int argc, const char* argv[])
proxySocketAddress.sin_port = htons(proxyTrapPort);
trapHandle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if((trapHandle < 0) ||
(bind(trapHandle, (struct sockaddr*)&proxySocketAddress, sizeof(proxySocketAddress)) < 0))
(bind(trapHandle, (struct sockaddr*)&proxySocketAddress, proxySocketLength) < 0))
{
print("Error opening port for SNMP Traps\n");
return EXIT_FAILURE;
}
proxySocketAddress.sin_port = htons(proxyMediaPort);
proxySocketAddress.sin_port = 0;
mediaHandle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if((mediaHandle < 0) ||
(bind(mediaHandle, (struct sockaddr*)&proxySocketAddress, sizeof(proxySocketAddress)) < 0))
(bind(mediaHandle, (struct sockaddr*)&proxySocketAddress, proxySocketLength) < 0) ||
(getsockname(mediaHandle, (struct sockaddr*)&proxySocketAddress, &proxySocketLength) < 0))
{
print("Error opening port for KAIROS External Server\n");
print("Error opening port for External Server\n");
return EXIT_FAILURE;
}
@ -662,7 +658,7 @@ int main(int argc, const char* argv[])
size_t length = sizeof(struct RewindAddressData);
struct RewindAddressData* data = (struct RewindAddressData*)outgoingBuffer->data;
data->address = information->ipi_addr;
data->port = htons(proxyMediaPort);
data->port = proxySocketAddress.sin_port;
outgoingBuffer->type = htole16(REWIND_TYPE_ADDRESS_NOTICE);
outgoingBuffer->number = htole32(++ sequenceNumbers[0]);