rsrv: failed to set mcast ttl 1

Bug #1790715 reported by Till Straumann
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
EPICS Base
Status tracked in 7.0
3.16
Fix Released
Medium
mdavidsaver
7.0
Fix Released
Medium
Andrew Johnson

Bug Description

EPICS V7 added

#ifdef IP_MULTICAST_TTL
    {
        int ttl;
        long val;
        if(envGetLongConfigParam(&EPICS_CA_MCAST_TTL, &val))
            val =1;
        ttl = val;
        if ( setsockopt(this->sock, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ttl, sizeof(ttl))) {
            char sockErrBuf[64];
            epicsSocketConvertErrnoToString (
                sockErrBuf, sizeof ( sockErrBuf ) );
            errlogPrintf("CAC: failed to set mcast ttl %d\n", ttl);
        }
    }
#endif

to modules/ca/src/client/udpiiu.cpp

Unfortunately this is not portable. The type of the IP_MULTICAST_TTL option is 'int' under linux but 'unsigned char' under BSDs (including solarix, OSX, rtems). DWORD under windows (and probably cygwin) and unknown (to me) under iOS. vxWorks is interesting as 5.5 seems to use 'char' and another (older?) version an 'int' (https://www.ee.ryerson.ca/%7Ecourses/ee8205/Data-Sheets/Tornado-VxWorks/vxworks/ref/sockLib.html#top).

Supplying the wrong type results in EINVAL (as experienced under RTEMS).

Suggested solutions:
a) Christmas-tree of 'ifdef's
b) try 'int' (at run-time) and if we run into EINVAL then try 'unsigned char'. Limit range to 0..127 (if you want so support vxWorks 5.5 and avoid issues with signed vs. unsigned char).
c) Remove altogether. The OSes I have looked at use '1' as a default anyways.

SIDENOTE: The code also misses passing the 'sockErrBuf' string to the errlogPrintf(). BTW: The same applies (obviously a copy/paste propagation) to the IP_ADD_MEMBERSHIP section just above (udpiiu.cpp).

Revision history for this message
Andrew Johnson (anj) wrote :

We have a standard solution for differing setsockopt argument sizes, see the typedefs in libcom/src/osi/os/*/osdSock.h and the section above in client/udpiiu.cpp

It might be Okay to re-use osiSockOptMcastLoop_t since it probably has the same size on all targets, but for safety's sake I would probably define a new typedef.

Revision history for this message
Andrew Johnson (anj) wrote :

Core Group review at ESS:

MD to add and use new typedef osiSockOptMcastTTL_t for this.

Revision history for this message
mdavidsaver (mdavidsaver) wrote :

Fixed as of 27ee078bc8433c214a7989a5e67074bc59449680, including an added case in osiSockTest. Verified on Linux and RTEMS, but not WIN32, Darwin, iOS, cygwin32, solaris, or vxWorks.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.