diff --git a/QnetGateway.cpp b/QnetGateway.cpp index 2a3a38b..ef4f6be 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -54,7 +54,7 @@ #define CFG_DIR "/usr/local/etc" #endif -const std::string GW_VERSION("QnetGateway-331"); +const std::string GW_VERSION("QnetGateway-408"); static std::atomic keep_running(true); @@ -346,7 +346,7 @@ int CQnetGateway::open_port(const SPORTIP *pip, int family) // return -1; //} - if (bind(sock, sin.GetPointer(), sizeof(struct sockaddr_storage)) != 0) { + if (bind(sock, sin.GetCPointer(), sizeof(struct sockaddr_storage)) != 0) { printf("Failed to bind %s:%d, errno=%d, %s\n", pip->ip.c_str(), pip->port, errno, strerror(errno)); close(sock); return -1; @@ -437,7 +437,7 @@ void CQnetGateway::GetIRCDataThread(const int i) to.Initialize(AF_INET, (unsigned short)g2_external.port, addr.c_str()); else to.Initialize(AF_INET6, (unsigned short)g2_ipv6_external.port, addr.c_str()); - sendto(g2_sock[i], "PONG", 4, 0, to.GetPointer(), to.GetSize()); + sendto(g2_sock[i], "PONG", 4, 0, to.GetCPointer(), to.GetSize()); if (LOG_QSO) printf("Sent 'PONG' to %s\n", addr.c_str()); } @@ -627,7 +627,7 @@ void CQnetGateway::ProcessTimeouts() if ((t_now - to_remote_g2[i].last_time) > TIMING_TIMEOUT_LOCAL_RPTR) { printf("Inactivity from local rptr mod %c, removing stream id %04x\n", 'A'+i, ntohs(to_remote_g2[i].streamid)); - to_remote_g2[i].toDstar.Initialize(AF_UNSPEC); + to_remote_g2[i].toDstar.Clear(); to_remote_g2[i].streamid = 0; to_remote_g2[i].last_time = 0; } @@ -1337,7 +1337,7 @@ void CQnetGateway::ProcessModem() // send to remote gateway for (int j=0; j<5; j++) - sendto(g2_sock[Index[i]], dsvt.title, 56, 0, to_remote_g2[i].toDstar.GetPointer(), to_remote_g2[i].toDstar.GetSize()); + sendto(g2_sock[Index[i]], dsvt.title, 56, 0, to_remote_g2[i].toDstar.GetCPointer(), to_remote_g2[i].toDstar.GetSize()); printf("id=%04x zone route to [%s]:%u ur=%.8s r1=%.8s r2=%.8s my=%.8s/%.4s\n", ntohs(dsvt.streamid), to_remote_g2[i].toDstar.GetAddress(), to_remote_g2[i].toDstar.GetPort(), @@ -1390,7 +1390,7 @@ void CQnetGateway::ProcessModem() /* send to remote gateway */ for (int j=0; j<5; j++) - sendto(g2_sock[Index[i]], dsvt.title, 56, 0, to_remote_g2[i].toDstar.GetPointer(), to_remote_g2[i].toDstar.GetSize()); + sendto(g2_sock[Index[i]], dsvt.title, 56, 0, to_remote_g2[i].toDstar.GetCPointer(), to_remote_g2[i].toDstar.GetSize()); printf("Callsign route to [%s]:%u id=%04x my=%.8s/%.4s ur=%.8s rpt1=%.8s rpt2=%.8s\n", to_remote_g2[i].toDstar.GetAddress(), to_remote_g2[i].toDstar.GetPort(), ntohs(dsvt.streamid), dsvt.hdr.mycall, dsvt.hdr.sfx, dsvt.hdr.urcall, dsvt.hdr.rpt1, dsvt.hdr.rpt2); @@ -1722,13 +1722,13 @@ void CQnetGateway::ProcessModem() for (int i=0; i<3; i++) { /* find out if data must go to the remote G2 */ if (to_remote_g2[i].streamid==dsvt.streamid && Index[i]>=0) { - sendto(g2_sock[Index[i]], dsvt.title, 27, 0, to_remote_g2[i].toDstar.GetPointer(), to_remote_g2[i].toDstar.GetSize()); + sendto(g2_sock[Index[i]], dsvt.title, 27, 0, to_remote_g2[i].toDstar.GetCPointer(), to_remote_g2[i].toDstar.GetSize()); time(&(to_remote_g2[i].last_time)); /* Is this the end-of-stream */ if (dsvt.ctrl & 0x40) { - to_remote_g2[i].toDstar.Initialize(AF_UNSPEC); + to_remote_g2[i].toDstar.Clear(); to_remote_g2[i].streamid = 0; to_remote_g2[i].last_time = 0; } @@ -1784,7 +1784,7 @@ void CQnetGateway::ProcessModem() if (dsvt.ctrl & 0x40) { toRptr[i].last_time = 0; toRptr[i].streamid = 0; - toRptr[i].addr.Initialize(AF_UNSPEC); + toRptr[i].addr.Clear(); } break; } @@ -2471,10 +2471,10 @@ bool CQnetGateway::Init(char *cfgfile) // the repeater modules run on these ports memset(toRptr[i].saved_hdr.title, 0, 56); - toRptr[i].saved_addr.Initialize(AF_UNSPEC); + toRptr[i].saved_addr.Clear(); toRptr[i].streamid = 0; - toRptr[i].addr.Initialize(AF_UNSPEC); + toRptr[i].addr.Clear(); toRptr[i].last_time = 0; @@ -2491,7 +2491,7 @@ bool CQnetGateway::Init(char *cfgfile) /* to remote systems */ for (i = 0; i < 3; i++) { - to_remote_g2[i].toDstar.Initialize(AF_UNSPEC); + to_remote_g2[i].toDstar.Clear(); to_remote_g2[i].streamid = 0; to_remote_g2[i].last_time = 0; } diff --git a/QnetLink.cpp b/QnetLink.cpp index cee2d14..da152e2 100644 --- a/QnetLink.cpp +++ b/QnetLink.cpp @@ -52,7 +52,7 @@ #include "QnetConfigure.h" #include "QnetLink.h" -#define LINK_VERSION "QnetLink-329" +#define LINK_VERSION "QnetLink-407" #ifndef BIN_DIR #define BIN_DIR "/usr/local/bin" #endif @@ -126,7 +126,7 @@ void CQnetLink::send_heartbeat() { for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { SINBOUND *inbound = (SINBOUND *)pos->second; - sendto(ref_g2_sock, REF_ACK, 3, 0, inbound->addr.GetPointer(), inbound->addr.GetSize()); + sendto(ref_g2_sock, REF_ACK, 3, 0, inbound->addr.GetCPointer(), inbound->addr.GetSize()); if (inbound->countdown >= 0) inbound->countdown --; @@ -828,7 +828,7 @@ void CQnetLink::g2link(const char from_mod, const char *call, const char to_mod) printf("sending link request from mod %c to link with: [%s] mod %c [%s]\n", to_remote_g2[i].from_mod, to_remote_g2[i].cs, to_remote_g2[i].to_mod, payload); for (int j=0; j<5; j++) - sendto(xrf_g2_sock, link_request, CALL_SIZE + 3, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, link_request, CALL_SIZE + 3, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else if (port_i == rmt_dcs_port) { strcpy(link_request, owner.c_str()); link_request[8] = from_mod; @@ -838,7 +838,7 @@ void CQnetLink::g2link(const char from_mod, const char *call, const char to_mod) strcpy(link_request + 19, "
REPEATER QnetGateway v1.0+
"); printf("sending link request from mod %c to link with: [%s] mod %c [%s]\n", to_remote_g2[i].from_mod, to_remote_g2[i].cs, to_remote_g2[i].to_mod, payload); - sendto(dcs_g2_sock, link_request, 519, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(dcs_g2_sock, link_request, 519, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else if (port_i == rmt_ref_port) { int counter; for (counter = 0; counter < 3; counter++) { @@ -856,7 +856,7 @@ void CQnetLink::g2link(const char from_mod, const char *call, const char to_mod) queryCommand[3] = 0; queryCommand[4] = 1; - sendto(ref_g2_sock, queryCommand, 5, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, queryCommand, 5, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else { if (to_remote_g2[counter].is_connected) { to_remote_g2[i].is_connected = true; @@ -977,13 +977,13 @@ void CQnetLink::Process() /* send heartbeat to linked XRF repeaters/reflectors */ if (to_remote_g2[0].addr.GetPort() == rmt_xrf_port) - sendto(xrf_g2_sock, owner.c_str(), CALL_SIZE+1, 0, to_remote_g2[0].addr.GetPointer(), to_remote_g2[0].addr.GetSize()); + sendto(xrf_g2_sock, owner.c_str(), CALL_SIZE+1, 0, to_remote_g2[0].addr.GetCPointer(), to_remote_g2[0].addr.GetSize()); if ((to_remote_g2[1].addr.GetPort() == rmt_xrf_port) && (strcmp(to_remote_g2[1].cs, to_remote_g2[0].cs) != 0)) - sendto(xrf_g2_sock, owner.c_str(), CALL_SIZE+1, 0, to_remote_g2[1].addr.GetPointer(), to_remote_g2[1].addr.GetSize()); + sendto(xrf_g2_sock, owner.c_str(), CALL_SIZE+1, 0, to_remote_g2[1].addr.GetCPointer(), to_remote_g2[1].addr.GetSize()); if ((to_remote_g2[2].addr.GetPort() == rmt_xrf_port) && (strcmp(to_remote_g2[2].cs, to_remote_g2[0].cs) != 0) && (strcmp(to_remote_g2[2].cs, to_remote_g2[1].cs) != 0)) - sendto(xrf_g2_sock, owner.c_str(), CALL_SIZE+1, 0, to_remote_g2[2].addr.GetPointer(), to_remote_g2[2].addr.GetSize()); + sendto(xrf_g2_sock, owner.c_str(), CALL_SIZE+1, 0, to_remote_g2[2].addr.GetCPointer(), to_remote_g2[2].addr.GetSize()); /* send heartbeat to linked DCS reflectors */ if (to_remote_g2[0].addr.GetPort() == rmt_dcs_port) { @@ -991,32 +991,32 @@ void CQnetLink::Process() cmd_2_dcs[7] = to_remote_g2[0].from_mod; memcpy(cmd_2_dcs + 9, to_remote_g2[0].cs, 8); cmd_2_dcs[16] = to_remote_g2[0].to_mod; - sendto(dcs_g2_sock, cmd_2_dcs, 17, 0, to_remote_g2[0].addr.GetPointer(), to_remote_g2[0].addr.GetSize()); + sendto(dcs_g2_sock, cmd_2_dcs, 17, 0, to_remote_g2[0].addr.GetCPointer(), to_remote_g2[0].addr.GetSize()); } if (to_remote_g2[1].addr.GetPort() == rmt_dcs_port) { strcpy(cmd_2_dcs, owner.c_str()); cmd_2_dcs[7] = to_remote_g2[1].from_mod; memcpy(cmd_2_dcs + 9, to_remote_g2[1].cs, 8); cmd_2_dcs[16] = to_remote_g2[1].to_mod; - sendto(dcs_g2_sock, cmd_2_dcs, 17, 0, to_remote_g2[1].addr.GetPointer(), to_remote_g2[1].addr.GetSize()); + sendto(dcs_g2_sock, cmd_2_dcs, 17, 0, to_remote_g2[1].addr.GetCPointer(), to_remote_g2[1].addr.GetSize()); } if (to_remote_g2[2].addr.GetPort() == rmt_dcs_port) { strcpy(cmd_2_dcs, owner.c_str()); cmd_2_dcs[7] = to_remote_g2[2].from_mod; memcpy(cmd_2_dcs + 9, to_remote_g2[2].cs, 8); cmd_2_dcs[16] = to_remote_g2[2].to_mod; - sendto(dcs_g2_sock, cmd_2_dcs, 17, 0, to_remote_g2[2].addr.GetPointer(), to_remote_g2[2].addr.GetSize()); + sendto(dcs_g2_sock, cmd_2_dcs, 17, 0, to_remote_g2[2].addr.GetCPointer(), to_remote_g2[2].addr.GetSize()); } /* send heartbeat to linked REF reflectors */ if (to_remote_g2[0].is_connected && to_remote_g2[0].addr.GetPort()==rmt_ref_port) - sendto(ref_g2_sock, REF_ACK, 3, 0, to_remote_g2[0].addr.GetPointer(), to_remote_g2[0].addr.GetSize()); + sendto(ref_g2_sock, REF_ACK, 3, 0, to_remote_g2[0].addr.GetCPointer(), to_remote_g2[0].addr.GetSize()); if (to_remote_g2[1].is_connected && to_remote_g2[1].addr.GetPort()==rmt_ref_port && strcmp(to_remote_g2[1].cs, to_remote_g2[0].cs)) - sendto(ref_g2_sock, REF_ACK, 3, 0, to_remote_g2[1].addr.GetPointer(), to_remote_g2[1].addr.GetSize()); + sendto(ref_g2_sock, REF_ACK, 3, 0, to_remote_g2[1].addr.GetCPointer(), to_remote_g2[1].addr.GetSize()); if (to_remote_g2[2].is_connected && to_remote_g2[2].addr.GetPort()==rmt_ref_port && strcmp(to_remote_g2[2].cs, to_remote_g2[0].cs) && strcmp(to_remote_g2[2].cs, to_remote_g2[1].cs)) - sendto(ref_g2_sock, REF_ACK, 3, 0, to_remote_g2[2].addr.GetPointer(), to_remote_g2[2].addr.GetSize()); + sendto(ref_g2_sock, REF_ACK, 3, 0, to_remote_g2[2].addr.GetCPointer(), to_remote_g2[2].addr.GetSize()); for (int i=0; i<3; i++) { /* check for timeouts from remote */ @@ -1058,7 +1058,7 @@ void CQnetLink::Process() queryCommand[2] = 24; queryCommand[3] = 0; queryCommand[4] = 0; - sendto(ref_g2_sock, queryCommand, 5, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, queryCommand, 5, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); /* zero out any other entries here that match that system */ for (int j=0; j<3; j++) { @@ -1081,7 +1081,7 @@ void CQnetLink::Process() unlink_request[10] = '\0'; for (int j=0; j<5; j++) - sendto(xrf_g2_sock, unlink_request, CALL_SIZE+3, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, unlink_request, CALL_SIZE+3, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else if (to_remote_g2[i].addr.GetPort() == rmt_dcs_port) { strcpy(cmd_2_dcs, owner.c_str()); cmd_2_dcs[8] = to_remote_g2[i].from_mod; @@ -1090,7 +1090,7 @@ void CQnetLink::Process() memcpy(cmd_2_dcs + 11, to_remote_g2[i].cs, 8); for (int j=0; j<2; j++) - sendto(dcs_g2_sock, cmd_2_dcs, 19 ,0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(dcs_g2_sock, cmd_2_dcs, 19 ,0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } qnDB.DeleteLS(to_remote_g2[i].addr.GetAddress()); sprintf(notify_msg[i], "%c_unlinked.dat_UNLINKED_TIMEOUT", to_remote_g2[i].from_mod); @@ -1140,7 +1140,7 @@ void CQnetLink::Process() (void)select(max_nfds + 1, &fdset, 0, 0, &tv); if (keep_running && FD_ISSET(xrf_g2_sock, &fdset)) { - socklen_t fromlen = sizeof(struct sockaddr_in); + socklen_t fromlen = sizeof(struct sockaddr_storage); unsigned char buf[100]; int length = recvfrom(xrf_g2_sock, buf, 100, 0, fromDst4.GetPointer(), &fromlen); @@ -1256,7 +1256,7 @@ void CQnetLink::Process() /* send back an ACK */ memcpy(buf + 10, "ACK", 4); - sendto(xrf_g2_sock, buf, CALL_SIZE+6, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, buf, CALL_SIZE+6, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); if (to_remote_g2[i].from_mod != buf[9]) { to_remote_g2[i].from_mod = buf[9]; @@ -1330,10 +1330,10 @@ void CQnetLink::Process() /* send back an ACK */ memcpy(buf + 10, "ACK", 4); - sendto(xrf_g2_sock, buf, CALL_SIZE+6, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, buf, CALL_SIZE+6, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } } else { - if (! (fromDst4 == to_remote_g2[i].addr)) { + if (fromDst4 != to_remote_g2[i].addr) { /* Our repeater module is linked to another repeater-reflector */ memcpy(buf + 10, "NAK", 4); if (fromDst4.GetPort() != rmt_xrf_port) { @@ -1452,7 +1452,7 @@ void CQnetLink::Process() rdsvt.head[1] = (unsigned char)(rdsvt.head[1] | 0xFFFFFF80); memcpy(rdsvt.dsvt.title, dsvt.title, 56); - sendto(ref_g2_sock, rdsvt.head, 58, 0, inbound->addr.GetPointer(), inbound->addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 58, 0, inbound->addr.GetCPointer(), inbound->addr.GetSize()); } } @@ -1504,7 +1504,7 @@ void CQnetLink::Process() } } - if ((!(to_remote_g2[i].addr==fromDst4)) && to_remote_g2[i].is_connected) { + if ((to_remote_g2[i].addr != fromDst4) && to_remote_g2[i].is_connected) { if (to_remote_g2[i].addr.GetPort() == rmt_xrf_port) { if ( /*** (memcmp(readBuffer2 + 42, owner, 8) != 0) && ***/ /* block repeater announcements */ (memcmp(dsvt.hdr.urcall, "CQCQCQ", 6) == 0) && /* CQ calls only */ @@ -1525,7 +1525,7 @@ void CQnetLink::Process() dsvt.hdr.rpt2[7] = 'G'; calcPFCS(dsvt.title, 56); - sendto(xrf_g2_sock, dsvt.title, 56, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, dsvt.title, 56, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } } else if (to_remote_g2[i].addr.GetPort() == rmt_ref_port) { if ( /*** (memcmp(readBuffer2 + 42, owner, 8) != 0) && ***/ /* block repeater announcements */ @@ -1555,7 +1555,7 @@ void CQnetLink::Process() calcPFCS(rdsvt.dsvt.title, 56); - sendto(ref_g2_sock, rdsvt.head, 58, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 58, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } } else if (to_remote_g2[i].addr.GetPort() == rmt_dcs_port) { if ( /*** (memcmp(readBuffer2 + 42, owner, 8) != 0) && ***/ /* block repeater announcements */ @@ -1595,7 +1595,7 @@ void CQnetLink::Process() /* no changes here */ for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { SINBOUND *inbound = (SINBOUND *)pos->second; - if (! (fromDst4 == inbound->addr)) { + if (fromDst4 != inbound->addr) { SREFDSVT rdsvt; rdsvt.head[0] = (unsigned char)(29 & 0xFF); rdsvt.head[1] = (unsigned char)(29 >> 8 & 0x1F); @@ -1603,7 +1603,7 @@ void CQnetLink::Process() memcpy(rdsvt.dsvt.title, dsvt.title, 27); - sendto(ref_g2_sock, rdsvt.head, 29, 0, inbound->addr.GetPointer(), inbound->addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 29, 0, inbound->addr.GetCPointer(), inbound->addr.GetSize()); } } @@ -1628,12 +1628,12 @@ void CQnetLink::Process() } for (int i=0; i<3; i++) { - if (to_remote_g2[i].is_connected && (! (to_remote_g2[i].addr==fromDst4)) && to_remote_g2[i].in_streamid==dsvt.streamid) { + if (to_remote_g2[i].is_connected && (to_remote_g2[i].addr != fromDst4) && to_remote_g2[i].in_streamid==dsvt.streamid) { if (to_remote_g2[i].addr.GetPort() == rmt_xrf_port) { /* inform XRF about the source */ dsvt.flagb[2] = to_remote_g2[i].from_mod; - sendto(xrf_g2_sock, dsvt.title, 27, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, dsvt.title, 27, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else if (to_remote_g2[i].addr.GetPort() == rmt_ref_port) { SREFDSVT rdsvt; rdsvt.head[0] = (unsigned char)(29 & 0xFF); @@ -1642,7 +1642,7 @@ void CQnetLink::Process() memcpy(rdsvt.dsvt.title, dsvt.title, 27); - sendto(ref_g2_sock, rdsvt.head, 29, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 29, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else if (to_remote_g2[i].addr.GetPort() == rmt_dcs_port) { memset(dcs_buf, 0x00, 600); dcs_buf[0] = dcs_buf[1] = dcs_buf[2] = '0'; @@ -1668,7 +1668,7 @@ void CQnetLink::Process() dcs_buf[61] = 0x01; dcs_buf[62] = 0x00; - sendto(dcs_g2_sock, dcs_buf, 100, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(dcs_g2_sock, dcs_buf, 100, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } if (dsvt.ctrl & 0x40) { @@ -1683,9 +1683,9 @@ void CQnetLink::Process() } if (keep_running && FD_ISSET(ref_g2_sock, &fdset)) { - socklen_t fromlen = sizeof(struct sockaddr_in); + socklen_t fromlen = sizeof(struct sockaddr_storage); unsigned char buf[100]; - int length = recvfrom(ref_g2_sock, buf, 100, 0, (struct sockaddr *)&fromDst4,&fromlen); + int length = recvfrom(ref_g2_sock, buf, 100, 0, fromDst4.GetPointer(), &fromlen); ip.assign(fromDst4.GetAddress()); @@ -2032,7 +2032,7 @@ void CQnetLink::Process() // ATTENTION: I should ONLY send once for each distinct // remote IP, so get out of the loop immediately - sendto(ref_g2_sock, queryCommand, 28, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, queryCommand, 28, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); break; } @@ -2319,10 +2319,10 @@ void CQnetLink::Process() if (fromDst4 == inbound->addr) inbound->mod = rdsvt.dsvt.hdr.rpt1[7]; else - sendto(ref_g2_sock, rdsvt.head, 58, 0, inbound->addr.GetPointer(), inbound->addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 58, 0, inbound->addr.GetCPointer(), inbound->addr.GetSize()); } - if ((! (to_remote_g2[i].addr==fromDst4)) && to_remote_g2[i].is_connected) { + if ((to_remote_g2[i].addr != fromDst4) && to_remote_g2[i].is_connected) { if ( /*** (memcmp(readBuffer2 + 44, owner, 8) != 0) && ***/ /* block repeater announcements */ 0==memcmp(rdsvt.dsvt.hdr.urcall, "CQCQCQ", 6) && /* CQ calls only */ (rdsvt.dsvt.hdr.flag[0]==0x00 || /* normal */ @@ -2343,9 +2343,9 @@ void CQnetLink::Process() if (to_remote_g2[i].addr.GetPort() == rmt_xrf_port) { /* inform XRF about the source */ rdsvt.dsvt.flagb[2] = to_remote_g2[i].from_mod; - sendto(xrf_g2_sock, rdsvt.dsvt.title, 56, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, rdsvt.dsvt.title, 56, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else - sendto(ref_g2_sock, rdsvt.head, 58, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 58, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else if (to_remote_g2[i].addr.GetPort() == rmt_dcs_port) { memcpy(ref_2_dcs[i].mycall, rdsvt.dsvt.hdr.mycall, 8); memcpy(ref_2_dcs[i].sfx, rdsvt.dsvt.hdr.sfx, 4); @@ -2374,19 +2374,19 @@ void CQnetLink::Process() /* send the data to the donglers */ for (pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { SINBOUND *inbound = (SINBOUND *)pos->second; - if (! (fromDst4 == inbound->addr)) { - sendto(ref_g2_sock, rdsvt.head, 29, 0, inbound->addr.GetPointer(), inbound->addr.GetSize()); + if (fromDst4 != inbound->addr) { + sendto(ref_g2_sock, rdsvt.head, 29, 0, inbound->addr.GetCPointer(), inbound->addr.GetSize()); } } for (int i=0; i<3; i++) { - if (to_remote_g2[i].is_connected && (! (to_remote_g2[i].addr==fromDst4)) && to_remote_g2[i].in_streamid==rdsvt.dsvt.streamid) { + if (to_remote_g2[i].is_connected && (to_remote_g2[i].addr != fromDst4) && to_remote_g2[i].in_streamid==rdsvt.dsvt.streamid) { if (to_remote_g2[i].addr.GetPort() == rmt_xrf_port) { /* inform XRF about the source */ rdsvt.dsvt.flagb[2] = to_remote_g2[i].from_mod; - sendto(xrf_g2_sock, rdsvt.dsvt.title, 27, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, rdsvt.dsvt.title, 27, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else if (to_remote_g2[i].addr.GetPort() == rmt_ref_port) - sendto(ref_g2_sock, rdsvt.head, 29, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 29, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); else if (to_remote_g2[i].addr.GetPort() == rmt_dcs_port) { memset(dcs_buf, 0x00, 600); dcs_buf[0] = dcs_buf[1] = dcs_buf[2] = '0'; @@ -2413,7 +2413,7 @@ void CQnetLink::Process() dcs_buf[61] = 0x01; dcs_buf[62] = 0x00; - sendto(dcs_g2_sock, dcs_buf, 100, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(dcs_g2_sock, dcs_buf, 100, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } if (rdsvt.dsvt.ctrl & 0x40) { @@ -2428,8 +2428,8 @@ void CQnetLink::Process() } if (keep_running && FD_ISSET(dcs_g2_sock, &fdset)) { - socklen_t fromlen = sizeof(struct sockaddr_in); - int length = recvfrom(dcs_g2_sock, dcs_buf, 1000, 0, (struct sockaddr *)&fromDst4, &fromlen); + socklen_t fromlen = sizeof(struct sockaddr_storage); + int length = recvfrom(dcs_g2_sock, dcs_buf, 1000, 0, fromDst4.GetPointer(), &fromlen); ip.assign(fromDst4.GetAddress()); @@ -2524,7 +2524,7 @@ void CQnetLink::Process() for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { SINBOUND *inbound = (SINBOUND *)pos->second; for (int j=0; j<5; j++) - sendto(ref_g2_sock, rdsvt.head, 58, 0, inbound->addr.GetPointer(), inbound->addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 58, 0, inbound->addr.GetCPointer(), inbound->addr.GetSize()); } } @@ -2556,7 +2556,7 @@ void CQnetLink::Process() /* send the data to the donglers */ for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { SINBOUND *inbound = (SINBOUND *)pos->second; - sendto(ref_g2_sock, rdsvt.head, 29, 0, inbound->addr.GetPointer(), inbound->addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 29, 0, inbound->addr.GetCPointer(), inbound->addr.GetSize()); } if ((dcs_buf[45] & 0x40) != 0) { @@ -2766,7 +2766,7 @@ void CQnetLink::Process() queryCommand[2] = 24; queryCommand[3] = 0; queryCommand[4] = 0; - sendto(ref_g2_sock, queryCommand, 5, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, queryCommand, 5, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } } else if (to_remote_g2[i].addr.GetPort() == rmt_xrf_port) { strcpy(unlink_request, owner.c_str()); @@ -2775,7 +2775,7 @@ void CQnetLink::Process() unlink_request[10] = '\0'; for (int j=0; j<5; j++) - sendto(xrf_g2_sock, unlink_request, CALL_SIZE+3, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, unlink_request, CALL_SIZE+3, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else { strcpy(cmd_2_dcs, owner.c_str()); cmd_2_dcs[8] = to_remote_g2[i].from_mod; @@ -2784,7 +2784,7 @@ void CQnetLink::Process() memcpy(cmd_2_dcs + 11, to_remote_g2[i].cs, 8); for (int j=0; j<5; j++) - sendto(dcs_g2_sock, cmd_2_dcs, 19, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(dcs_g2_sock, cmd_2_dcs, 19, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } printf("Unlinked from [%s] mod %c\n", to_remote_g2[i].cs, to_remote_g2[i].to_mod); @@ -2863,7 +2863,7 @@ void CQnetLink::Process() for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { SINBOUND *inbound = (SINBOUND *)pos->second; for (int j=0; j<5; j++) - sendto(ref_g2_sock, rdsvt.head, 58, 0, inbound->addr.GetPointer(), inbound->addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 58, 0, inbound->addr.GetCPointer(), inbound->addr.GetSize()); } } @@ -2925,10 +2925,10 @@ void CQnetLink::Process() rdsvt.dsvt.flagb[2] = to_remote_g2[i].from_mod; calcPFCS(rdsvt.dsvt.title, 56); for (int j=0; j<5; j++) - sendto(xrf_g2_sock, rdsvt.dsvt.title, 56, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, rdsvt.dsvt.title, 56, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else { for (int j=0; j<5; j++) - sendto(ref_g2_sock, rdsvt.head, 58, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 58, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } } else if (to_remote_g2[i].addr.GetPort() == rmt_dcs_port) { memcpy(rptr_2_dcs[i].mycall, dsvt.hdr.mycall, CALL_SIZE); @@ -2950,7 +2950,7 @@ void CQnetLink::Process() for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { SINBOUND *inbound = (SINBOUND *)pos->second; - sendto(ref_g2_sock, rdsvt.head, 29, 0, inbound->addr.GetPointer(), inbound->addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 29, 0, inbound->addr.GetCPointer(), inbound->addr.GetSize()); } } @@ -2987,9 +2987,9 @@ void CQnetLink::Process() /* inform XRF about the source */ rdsvt.dsvt.flagb[2] = to_remote_g2[i].from_mod; - sendto(xrf_g2_sock, rdsvt.dsvt.title, 27, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, rdsvt.dsvt.title, 27, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else if (to_remote_g2[i].addr.GetPort() == rmt_ref_port) - sendto(ref_g2_sock, rdsvt.head, 29, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, rdsvt.head, 29, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else if (to_remote_g2[i].addr.GetPort() == rmt_dcs_port) { memset(dcs_buf, 0x0, 600); dcs_buf[0] = dcs_buf[1] = dcs_buf[2] = '0'; @@ -3015,7 +3015,7 @@ void CQnetLink::Process() dcs_buf[61] = 0x01; dcs_buf[62] = 0x00; - sendto(dcs_g2_sock, dcs_buf, 100, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(dcs_g2_sock, dcs_buf, 100, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } if (dsvt.ctrl & 0x40U) { @@ -3411,14 +3411,14 @@ void CQnetLink::Shutdown() for (int i=0; i<3; i++) { if (to_remote_g2[i].cs[0] != '\0') { if (to_remote_g2[i].addr.GetPort() == rmt_ref_port) - sendto(ref_g2_sock, queryCommand, 5, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(ref_g2_sock, queryCommand, 5, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); else if (to_remote_g2[i].addr.GetPort() == rmt_xrf_port) { strcpy(unlink_request, owner.c_str()); unlink_request[8] = to_remote_g2[i].from_mod; unlink_request[9] = ' '; unlink_request[10] = '\0'; for (int j=0; j<5; j++) - sendto(xrf_g2_sock, unlink_request, CALL_SIZE+3, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(xrf_g2_sock, unlink_request, CALL_SIZE+3, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } else { strcpy(cmd_2_dcs, owner.c_str()); cmd_2_dcs[8] = to_remote_g2[i].from_mod; @@ -3427,7 +3427,7 @@ void CQnetLink::Shutdown() memcpy(cmd_2_dcs + 11, to_remote_g2[i].cs, 8); for (int j=0; j<5; j++) - sendto(dcs_g2_sock, cmd_2_dcs, 19, 0, to_remote_g2[i].addr.GetPointer(), to_remote_g2[i].addr.GetSize()); + sendto(dcs_g2_sock, cmd_2_dcs, 19, 0, to_remote_g2[i].addr.GetCPointer(), to_remote_g2[i].addr.GetSize()); } } to_remote_g2[i].cs[0] = '\0'; @@ -3442,7 +3442,7 @@ void CQnetLink::Shutdown() for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { SINBOUND *inbound = (SINBOUND *)pos->second; qnDB.DeleteLS(pos->first.c_str()); - sendto(ref_g2_sock, queryCommand, 5, 0, inbound->addr.GetPointer(), inbound->addr.GetSize()); + sendto(ref_g2_sock, queryCommand, 5, 0, inbound->addr.GetCPointer(), inbound->addr.GetSize()); } inbound_list.clear(); diff --git a/SockAddress.h b/SockAddress.h index c84b721..b7b761e 100644 --- a/SockAddress.h +++ b/SockAddress.h @@ -1,7 +1,7 @@ #pragma once /* - * Copyright (C) 2019 by Thomas Early N7TAE + * Copyright (C) 2019-2020 by Thomas Early N7TAE * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,17 +34,22 @@ public: CSockAddress(const struct sockaddr_storage &from) { Clear(); - if (AF_INET == from.ss_family) + if (AF_INET == from.ss_family) { memcpy(&addr, &from, sizeof(struct sockaddr_in)); - else + auto addr4 = (struct sockaddr_in *)&addr; + inet_ntop(AF_INET, &(addr4->sin_addr), straddr, INET6_ADDRSTRLEN); + } else { memcpy(&addr, &from, sizeof(struct sockaddr_in6)); + auto addr6 = (struct sockaddr_in6 *)&addr; + inet_ntop(AF_INET, &(addr6->sin6_addr), straddr, INET6_ADDRSTRLEN); + } } CSockAddress(const int family, const unsigned short port, const char *address) { Clear(); if (AF_INET==family && address) { - struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; + auto addr4 = (struct sockaddr_in *)&addr; addr4->sin_family = AF_INET; addr4->sin_port = htons(port); if (0 == strncasecmp(address, "loc", 3)) @@ -53,8 +58,9 @@ public: inet_pton(AF_INET, "0.0.0.0", &(addr4->sin_addr)); else inet_pton(AF_INET, address, &(addr4->sin_addr)); + inet_ntop(AF_INET, &(addr4->sin_addr), straddr, INET6_ADDRSTRLEN); } else if (AF_INET6==family && address) { - struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; + auto addr6 = (struct sockaddr_in6 *)&addr; addr6->sin6_family = AF_INET6; addr6->sin6_port = htons(port); if (0 == strncasecmp(address, "loc", 3)) @@ -63,19 +69,18 @@ public: inet_pton(AF_INET6, "::", &(addr6->sin6_addr)); else inet_pton(AF_INET6, address, &(addr6->sin6_addr)); - } else if (AF_UNSPEC == family) { - memset(&addr, 0, sizeof(struct sockaddr_storage)); + inet_ntop(AF_INET6, &(addr6->sin6_addr), straddr, INET6_ADDRSTRLEN); } } ~CSockAddress() {} - void Initialize(int family, uint16_t port = 0U, const char *address = NULL) + void Initialize(const int family, const uint16_t port = 0U, const char *address = NULL) { Clear(); addr.ss_family = (sa_family_t)family; if (AF_INET == family) { - struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; + auto addr4 = (struct sockaddr_in *)&addr; addr4->sin_port = htons(port); if (address) { if (0 == strncasecmp(address, "loc", 3)) @@ -84,9 +89,10 @@ public: inet_pton(AF_INET, "0.0.0.0", &(addr4->sin_addr)); else inet_pton(AF_INET, address, &(addr4->sin_addr)); + inet_ntop(AF_INET, &(addr4->sin_addr), straddr, INET6_ADDRSTRLEN); } } else { - struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; + auto addr6 = (struct sockaddr_in6 *)&addr; addr6->sin6_port = htons(port); if (address) { if (0 == strncasecmp(address, "loc", 3)) @@ -95,39 +101,41 @@ public: inet_pton(AF_INET6, "::", &(addr6->sin6_addr)); else inet_pton(AF_INET6, address, &(addr6->sin6_addr)); + inet_ntop(AF_INET6, &(addr6->sin6_addr), straddr, INET6_ADDRSTRLEN); } } } - CSockAddress &operator=(CSockAddress &from) + CSockAddress &operator=(const CSockAddress &from) { Clear(); if (AF_INET == from.addr.ss_family) - memcpy(&addr, &from, sizeof(struct sockaddr_in)); + memcpy(&addr, &from.addr, sizeof(struct sockaddr_in)); else - memcpy(&addr, &from, sizeof(struct sockaddr_in6)); + memcpy(&addr, &from.addr, sizeof(struct sockaddr_in6)); + strcpy(straddr, from.straddr); return *this; } - bool operator==(CSockAddress &from) + bool operator==(const CSockAddress &from) const // doesn't compare ports, only addresses and, implicitly, families { - if (addr.ss_family == from.addr.ss_family) { - if (AF_INET == addr.ss_family) { - return (0==memcmp(&addr, &from, sizeof(struct sockaddr_in))); - } else { - return (0==memcmp(&addr, &from, sizeof(struct sockaddr_in6))); - } - } else - return false; + const std::string addr(straddr); + return addr.compare(from.straddr) ? false : true; } - bool AddressIsZero() + bool operator!=(const CSockAddress &from) const // doesn't compare ports, only addresses and, implicitly, families + { + const std::string addr(straddr); + return addr.compare(from.straddr) ? true : false; + } + + bool AddressIsZero() const { if (AF_INET == addr.ss_family) { - struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; + auto addr4 = (struct sockaddr_in *)&addr; return (addr4->sin_addr.s_addr == 0U); } else { - struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; + auto addr6 = (struct sockaddr_in6 *)&addr; for (unsigned int i=0; i<16; i++) { if (addr6->sin6_addr.s6_addr[i]) return false; @@ -139,51 +147,57 @@ public: void ClearAddress() { if (AF_INET == addr.ss_family) { - struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; + auto addr4 = (struct sockaddr_in *)&addr; addr4->sin_addr.s_addr = 0U; } else { - struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; + auto addr6 = (struct sockaddr_in6 *)&addr; memset(&(addr6->sin6_addr.s6_addr), 0, 16); } } - const char *GetAddress() + const char *GetAddress() const { - if (AF_INET == addr.ss_family) { - struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; - if (NULL == inet_ntop(AF_INET, &(addr4->sin_addr), straddr, INET6_ADDRSTRLEN)) - return "ERROR"; - } else { - struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; - if (NULL == inet_ntop(AF_INET6, &(addr6->sin6_addr), straddr, INET6_ADDRSTRLEN)) - return "ERROR"; - } - return straddr; } - int GetFamily() + int GetFamily() const { return addr.ss_family; } - unsigned short GetPort() + unsigned short GetPort() const { if (AF_INET == addr.ss_family) { - struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; + auto addr4 = (struct sockaddr_in *)&addr; return ntohs(addr4->sin_port); } else { - struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr; + auto addr6 = (struct sockaddr_in6 *)&addr; return ntohs(addr6->sin6_port); } } + void SetPort(const uint16_t newport) + { + if (AF_INET == addr.ss_family) { + auto addr4 = (struct sockaddr_in *)&addr; + addr4->sin_port = newport; + } else { + auto addr6 = (struct sockaddr_in6 *)&addr; + addr6->sin6_port = newport; + } + } + struct sockaddr *GetPointer() { return (struct sockaddr *)&addr; } - size_t GetSize() + const struct sockaddr *GetCPointer() const + { + return (const sockaddr *)&addr; + } + + size_t GetSize() const { if (AF_INET == addr.ss_family) return sizeof(struct sockaddr_in); @@ -194,6 +208,7 @@ public: void Clear() { memset(&addr, 0, sizeof(struct sockaddr_storage)); + memset(straddr, 0, INET6_ADDRSTRLEN); } private: diff --git a/Timer.h b/Timer.h index 218c76a..f3a6e3a 100644 --- a/Timer.h +++ b/Timer.h @@ -30,8 +30,8 @@ public: starttime = std::chrono::steady_clock::now(); } double time() { - std::chrono::steady_clock::duration elapsed = std::chrono::steady_clock::now() - starttime; - return double(elapsed.count()) * std::chrono::steady_clock::period::num / std::chrono::steady_clock::period::den; + std::chrono::duration elapsed(std::chrono::steady_clock::now() - starttime); + return elapsed.count(); } private: std::chrono::steady_clock::time_point starttime; diff --git a/aprs.h b/aprs.h index 139d739..13874bb 100644 --- a/aprs.h +++ b/aprs.h @@ -35,6 +35,14 @@ using SPORTIP = struct portip_tag { int port; }; +using SMOD = struct aprs_module { + std::string call; /* KJ4NHF-B */ + bool defined; + std::string band; /* 23cm ... */ + double frequency, offset, latitude, longitude, range, agl; + std::string desc1, desc2, url, package_version; +}; + using SRPTR = struct aprs_info { SPORTIP aprs; std::string aprs_filter; @@ -42,13 +50,7 @@ using SRPTR = struct aprs_info { int aprs_interval; /* 0=A, 1=B, 2=C */ - struct aprs_module { - std::string call; /* KJ4NHF-B */ - bool defined; - std::string band; /* 23cm ... */ - double frequency, offset, latitude, longitude, range, agl; - std::string desc1, desc2, url, package_version; - } mod[3]; + SMOD mod[3]; }; class CAPRS {