diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 01431ef59..761ce3b75 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -37,6 +37,11 @@ #include #include +// to stop warnings about including winsock2.h before windows.h +#if defined(_WIN32) +#include +#endif + // For MSVC install the NUGet pthread package #if defined(_MSC_VER) #define HAVE_STRUCT_TIMESPEC @@ -2477,10 +2482,10 @@ struct multicast_s int seqnumber; int runflag; // = 0; pthread_t threadid; -#ifdef HAVE_ARPA_INET_H +//#ifdef HAVE_ARPA_INET_H struct ip_mreq mreq; // = {0}; struct sockaddr_in dest_addr; // = {0}; -#endif +//#endif }; /** diff --git a/src/multicast.c b/src/multicast.c index 89021db9b..edf3faa29 100644 --- a/src/multicast.c +++ b/src/multicast.c @@ -206,7 +206,7 @@ static int multicast_send_json(RIG *rig) json_add_vfoA(rig, msg); // send the thing - multicast_send(rig, (unsigned char *)msg, strlen(msg)); + multicast_send(rig, msg, strlen(msg)); return 0; } @@ -269,7 +269,7 @@ int multicast_init(RIG *rig, char *addr, int port) // Set the SO_REUSEADDR option to allow multiple processes to use the same address int optval = 1; - if (setsockopt(rig->state.multicast->sock, SOL_SOCKET, SO_REUSEADDR, &optval, + if (setsockopt(rig->state.multicast->sock, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof(optval)) < 0) { rig_debug(RIG_DEBUG_ERR, "%s: setsockopt: %s\n", __func__, strerror(errno)); @@ -295,7 +295,7 @@ int multicast_init(RIG *rig, char *addr, int port) rig->state.multicast->mreq.imr_interface.s_addr = htonl(INADDR_ANY); // Set the multicast TTL (time-to-live) to limit the scope of the packets - unsigned char ttl = 1; + char ttl = 1; if (setsockopt(rig->state.multicast->sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) @@ -322,7 +322,7 @@ int multicast_init(RIG *rig, char *addr, int port) rig->state.multicast->runflag = 1; pthread_create(&rig->state.multicast->threadid, NULL, multicast_thread, (void *)rig); - printf("threadid=%ld\n", rig->state.multicast->threadid); + //printf("threadid=%ld\n", rig->state.multicast->threadid); rig->state.multicast->multicast_running = 1; return RIG_OK; } @@ -348,7 +348,7 @@ void multicast_close(RIG *rig) } // if msglen=0 msg is assumed to be a string -int multicast_send(RIG *rig, unsigned char *msg, int msglen) +int multicast_send(RIG *rig, const char *msg, int msglen) { // Construct the message to send if (msglen == 0) { msglen = strlen((char *)msg); } diff --git a/src/multicast.h b/src/multicast.h index 1caf9f7e6..722056aeb 100644 --- a/src/multicast.h +++ b/src/multicast.h @@ -8,6 +8,10 @@ #ifdef HAVE_NETINET_IN_H #include #endif +#ifdef _WIN32 +#include +#include +#endif #ifdef HAVE_ARPA_INET_H #include @@ -53,5 +57,5 @@ struct multicast_broadcast // returns # of bytes sent int multicast_init(RIG *rig, char *addr, int port); -int multicast_send(RIG *rig, unsigned char *msg, int msglen); +int multicast_send(RIG *rig, const char *msg, int msglen); #endif //MULTICAST_H diff --git a/tests/Makefile.am b/tests/Makefile.am index 0dd92a3c7..900ca6e11 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -14,7 +14,7 @@ endif DISTCLEANFILES = rigctl.log rigctl.sum testbcd.log testbcd.sum -bin_PROGRAMS = rigctl rigctld rigmem rigsmtr rigswr rotctl rotctld rigctlcom rigctltcp rigctlsync ampctl ampctld multicastclient $(TESTLIBUSB) +bin_PROGRAMS = rigctl rigctld rigmem rigsmtr rigswr rotctl rotctld rigctlcom rigctltcp rigctlsync ampctl ampctld multicastclient multicastserver $(TESTLIBUSB) #check_PROGRAMS = dumpmem testrig testrigopen testrigcaps testtrn testbcd testfreq listrigs testloc rig_bench testcache cachetest cachetest2 testcookie testgrid testsecurity check_PROGRAMS = dumpmem testrig testrigopen testrigcaps testtrn testbcd testfreq listrigs testloc rig_bench testcache cachetest cachetest2 testcookie testgrid hamlibmodels diff --git a/tests/multicastserver.c b/tests/multicastserver.c new file mode 100644 index 000000000..22394245e --- /dev/null +++ b/tests/multicastserver.c @@ -0,0 +1,34 @@ +#include +#include + +#define TEST +#ifdef TEST +int main(int argc, char *argv[]) +{ + RIG *rig; + rig_model_t myrig_model; + rig_set_debug_level(RIG_DEBUG_NONE); + + if (argc > 1) { myrig_model = atoi(argv[1]); } + else + { + myrig_model = 1035; + } + + rig = rig_init(myrig_model); + + if (rig == NULL) + { + + } + + strncpy(rig->state.rigport.pathname, "/dev/ttyUSB0", HAMLIB_FILPATHLEN - 1); + rig->state.rigport.parm.serial.rate = 38400; + rig_open(rig); + multicast_init(rig, "224.0.0.1", 4532); + pthread_join(rig->state.multicast->threadid, NULL); + pthread_exit(NULL); + return 0; +} +#endif +