diff --git a/src/ca/client/udpiiu.cpp b/src/ca/client/udpiiu.cpp index beae07560..ccb2556e8 100644 --- a/src/ca/client/udpiiu.cpp +++ b/src/ca/client/udpiiu.cpp @@ -165,7 +165,7 @@ udpiiu::udpiiu ( #ifdef IP_ADD_MEMBERSHIP { - int flag = 1; + osiSockOptMcastLoop_t flag = 1; if ( setsockopt ( this->sock, IPPROTO_IP, IP_MULTICAST_LOOP, (char *) &flag, sizeof ( flag ) ) == -1 ) { char sockErrBuf[64]; diff --git a/src/ioc/rsrv/caservertask.c b/src/ioc/rsrv/caservertask.c index 50bc650c2..fda442168 100644 --- a/src/ioc/rsrv/caservertask.c +++ b/src/ioc/rsrv/caservertask.c @@ -308,7 +308,7 @@ void rsrv_build_addr_lists(void) } #ifdef IP_ADD_MEMBERSHIP { - int flag = 1; + osiSockOptMcastLoop_t flag = 1; if (setsockopt(beaconSocket, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&flag, sizeof(flag))<0) { char sockErrBuf[64]; diff --git a/src/libCom/osi/os/Darwin/osdSock.h b/src/libCom/osi/os/Darwin/osdSock.h index 1d4556eee..e7c344062 100644 --- a/src/libCom/osi/os/Darwin/osdSock.h +++ b/src/libCom/osi/os/Darwin/osdSock.h @@ -31,6 +31,7 @@ typedef int SOCKET; #define socket_ioctl(A,B,C) ioctl(A,B,C) typedef int osiSockIoctl_t; typedef socklen_t osiSocklen_t; +typedef int osiSockOptMcastLoop_t; #define FD_IN_FDSET(FD) ((FD)=0) #ifndef SHUT_RD #define SHUT_RD 0 diff --git a/src/libCom/osi/os/freebsd/osdSock.h b/src/libCom/osi/os/freebsd/osdSock.h index fe28d4cd5..b402ec120 100644 --- a/src/libCom/osi/os/freebsd/osdSock.h +++ b/src/libCom/osi/os/freebsd/osdSock.h @@ -36,6 +36,7 @@ typedef int SOCKET; #define socket_ioctl(A,B,C) ioctl(A,B,C) typedef int osiSockIoctl_t; typedef socklen_t osiSocklen_t; +typedef int osiSockOptMcastLoop_t; #define FD_IN_FDSET(FD) ((FD)=0) diff --git a/src/libCom/test/Makefile b/src/libCom/test/Makefile index ee4d11071..1ce7a6431 100755 --- a/src/libCom/test/Makefile +++ b/src/libCom/test/Makefile @@ -210,6 +210,11 @@ ipAddrToAsciiTest_SRCS += ipAddrToAsciiTest.cpp testHarness_SRCS += ipAddrToAsciiTest.cpp TESTS += ipAddrToAsciiTest +TESTPROD_HOST += osiSockTest +osiSockTest_SRCS += osiSockTest.c +testHarness_SRCS += osiSockTest.c +TESTS += osiSockTest + # The testHarness runs all the test programs in a known working order. testHarness_SRCS += epicsRunLibComTests.c @@ -254,4 +259,3 @@ cvtFastPerform_SRCS += cvtFastPerform.cpp testHarness_SRCS += cvtFastPerform.cpp include $(TOP)/configure/RULES - diff --git a/src/libCom/test/epicsRunLibComTests.c b/src/libCom/test/epicsRunLibComTests.c index c4a76e777..29c5eda3f 100644 --- a/src/libCom/test/epicsRunLibComTests.c +++ b/src/libCom/test/epicsRunLibComTests.c @@ -51,6 +51,7 @@ int epicsInlineTest(void); int ipAddrToAsciiTest(void); int macDefExpandTest(void); int macLibTest(void); +int osiSockTest(void); int ringBytesTest(void); int ringPointerTest(void); int taskwdTest(void); @@ -104,6 +105,7 @@ void epicsRunLibComTests(void) runTest(ipAddrToAsciiTest); runTest(macDefExpandTest); runTest(macLibTest); + runTest(osiSockTest); runTest(ringBytesTest); runTest(ringPointerTest); runTest(taskwdTest); diff --git a/src/libCom/test/osiSockTest.c b/src/libCom/test/osiSockTest.c new file mode 100644 index 000000000..d9bbd29f7 --- /dev/null +++ b/src/libCom/test/osiSockTest.c @@ -0,0 +1,59 @@ +/*************************************************************************\ +* Copyright (c) 2017 UChicago Argonne LLC, as Operator of Argonne +* National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#include +#include + +#include "osiSock.h" +#include "epicsUnitTest.h" +#include "testMain.h" + +void udpSockTest(void) +{ + SOCKET s; + int status, one = 1, get = 0; + osiSocklen_t len; + osiSockOptMcastLoop_t flag = 1; + + s = epicsSocketCreate(AF_INET, SOCK_DGRAM, 0); + testOk(s != INVALID_SOCKET, "epicsSocketCreate INET, DGRAM, 0"); + + status = setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&one, sizeof(one)); + testOk(status >= 0, "setsockopt BROADCAST, 1"); + + len = sizeof(get); + status = getsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&get, &len); + testOk(status >= 0 && len == sizeof(get) && get == 1, + "getsockopt BROADCAST == 1"); + + status = setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, + (char *)&flag, sizeof(flag)); + testOk(status >= 0, "setsockopt MULTICAST_LOOP, 1"); + + flag = 0; + len = sizeof(flag); + status = getsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&flag, &len); + testOk(status >= 0 && len == sizeof(flag) && flag == 1, + "getsockopt MULTICAST_LOOP == 1"); + + epicsSocketDestroy(s); +} + + +MAIN(osiSockTest) +{ + int status; + testPlan(6); + + status = osiSockAttach(); + testOk(status, "osiSockAttach"); + + udpSockTest(); + + osiSockRelease(); + return testDone(); +}