• AVR Freaks

Multicast Options

Author
BillP
Super Member
  • Total Posts : 334
  • Reward points : 0
  • Joined: 2014/09/28 07:53:35
  • Location: CA
  • Status: offline
2019/10/08 09:30:03 (permalink)
0

Multicast Options

I am still having problems getting a simple multicast app working with a Windows10 PC as a listener and a PIC32 MZ as the server/multicaster.  I am using Hv3 and the Curiosity MX EF board.  In a previous post I questioned how to set the multicast options because the documentation was sketchy.  I was told that it is obvious and nothing more was needed.  

So here is what I wanted to do: set the multicast options and then read them back to verify they were set correctly.  Here is the code I used to set the options.  [The LogMsg() function is just a printf routine.]

 
               UDP_OPTION_MULTICAST_DATA mopt;
                mopt.flagsMask = 0; // no masks
                mopt.flagsValue = 0; // all flags OFF
                // turn on the flags we need
                mopt.flagsMask = UDP_MCAST_FLAG_IGNORE_SOURCE_ADD |
                                 UDP_MCAST_FLAG_IGNORE_SOURCE_PORT | UDP_MCAST_FLAG_DISABLE_SOURCE_CHECK;
                mopt.flagsValue = 1;

                if(!TCPIP_UDP_OptionsSet(MCASTSERVdata.socket, UDP_OPTION_MULTICAST, (void *)&mopt))
                {
                    LogMsg("UDP multicast options did not get set");
                    MCASTSERVdata.state = MCASTSERV_CLOSING_CONNECTION;
                    break;
                }
                else LogMsg("UDP multicast setup complete");

 
Here is the code I used to verify the options were set correctly.  



                int mcinfo;
                if(TCPIP_UDP_OptionsGet(MCASTSERVdata.socket, UDP_OPTION_MULTICAST, &mcinfo))
                {
                    LogMsg("MCAST flags = %x", mcinfo);
                }

 
The returned value = 1 (rather than the 0x26 that is the mask).
I then tried:

                 mopt.flagsValue = UDP_MCAST_FLAG_IGNORE_SOURCE_ADD |
                                 UDP_MCAST_FLAG_IGNORE_SOURCE_PORT | UDP_MCAST_FLAG_DISABLE_SOURCE_CHECK;

 
The returned value was the flagsValue.

So it appears the flagValue is used -- so what is the purpose of the mask or am I doing something wrong?  A simple example of how to use the set/get options in the documentation would be useful.




#1

5 Replies Related Threads

    rainad
    Moderator
    • Total Posts : 1224
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: Multicast Options 2019/10/08 13:45:37 (permalink)
    5 (1)
    The UDP_OPTION_MULTICAST_DATA used in the TCPIP_UDP_OptionsSet() uses 2 fields - as described in the header file:
    - flagsMask - indicates what exactly flags to touch/change with the operation
    - flagsValue - indicates the new value for the touched/changed flags.
    Since flags can be set and cleared, only one parameter is not enough (unless 2 options are provided: UDP_OPTION_MULTICAST_SET and UDP_OPTION_MULTICAST_CLR. However, there's currently only one option, therefore the 2 values).
     
    In your example:
    1. mopt.flagsMask = UDP_MCAST_FLAG_IGNORE_SOURCE_ADD |                                  UDP_MCAST_FLAG_IGNORE_SOURCE_PORT | UDP_MCAST_FLAG_DISABLE_SOURCE_CHECK; 
    (i.e. mopt.flagsMask == 0x24)
    mopt.flagsValue = 1; (i.e. mopt.flagsValue == 0x01 == LOOSE_NET_SOURCE_PORT). But this is not touched, since the mask doesn't contain this flag.
    The TCPIP_UDP_OptionsSet() will change flags in the mask: IGNORE_SOURCE_ADD,  IGNORE_SOURCE_PORT and DISABLE_SOURCE_CHECK.
    Exactly it will clear all of them, since all the corresponding values in flagsValue == 0.
     
    2. In the 2nd example all the flag values in the mask have a corresponding value of 1. So all those flags indicated in the mask, will be set.
     
    For example:
    - to clear all flags use: flagsMask = 0x3f; flagsValue = 0;
    - to set all flags use: flagsMask = 0x3f; flagsValue = 0x3f;
    - to clear flag 0x20, use: flagsMask = 0x20; flagsValue = 0;
    - to set flag 0x20, use: flagsMask = 0x20; flagsValue = 0x20;
     etc.
     
    Hope this provides some clarification.
    Please let us know if you think more details are needed.
     
     
     
    #2
    BillP
    Super Member
    • Total Posts : 334
    • Reward points : 0
    • Joined: 2014/09/28 07:53:35
    • Location: CA
    • Status: offline
    Re: Multicast Options 2019/10/09 10:33:52 (permalink)
    0
    @rainad - thanks, this helps a lot.

    I was stupid about clearing all flags - my bad.  As for setting the flags, I assumed that the mask is used to set a value (0 or 1) into the associated bit in some internal word used by the TCPIP stack.  Your examples suggest that the value must equal the mask value.  Why use 0x20 to set one bit instead of just a value = 1?
    #3
    rainad
    Moderator
    • Total Posts : 1224
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: Multicast Options 2019/10/09 12:26:47 (permalink)
    5 (1)
    I've used hex values thinking it's easier to calculate the operation outcome.
    But the flags themselves should be used.
     
    So 0x20 was for UDP_MCAST_FLAG_DISABLE_SOURCE_CHECK.
    A better example I guess would be:
    - to clear UDP_MCAST_FLAG_LOOP:
    flagsMask = UDP_MCAST_FLAG_LOOP;  this tells we want to change this flag
    flagsValue = 0; (or any value that has that particular flag cleared) // this tells the new value needed, i.e.0.
    - to set UDP_MCAST_FLAG_LOOP:
    flagsMask = UDP_MCAST_FLAG_LOOP;  this tells we want to change this flag
    flagsValue = UDP_MCAST_FLAG_LOOP; (or 0xffffffff - any value that has that particular bit set) // this tells the new value needed, i.e.1.
     The advantage of using the mask and value is that you can manipulate multiple flags in one operation.
    To go into details, in hex terms, what happens is:
    flags &= ~flagsMask;    // clear all flags touched by mask
    flags |= (flagsValue & flagsMask);  // set the corresponding flags that are set in flagsValue. All others will remain cleared.
     
    post edited by rainad - 2019/10/09 12:28:52
    #4
    BillP
    Super Member
    • Total Posts : 334
    • Reward points : 0
    • Joined: 2014/09/28 07:53:35
    • Location: CA
    • Status: offline
    Re: Multicast Options 2019/10/09 13:44:12 (permalink)
    0
    Thank you.  I understand it now.  Suggestion: Copy your last post to the TCPIP documentation (UDP_OPTION_MULTICAST_DATA Structure.
    #5
    rainad
    Moderator
    • Total Posts : 1224
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: offline
    Re: Multicast Options 2019/10/10 07:50:59 (permalink)
    0
    Sure, will add the details. Thank you for your suggestion.
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5