Reading Socket Options (Windows CE 5.0)

Send Feedback

The TTL of a multicast for a socket can be determined by reading the value from the socket options. The following code example shows how the TTL value is read.

int ttl;  // Allocate space for TTL.
int sizeofttl = sizeof(ttl); // Create an integer that contains the size of the TTL value.
getsockopt( 
    sock,
    IPPROTO_IP,
    IP_MULTICAST_TTL,
    (char *)&ttl,
    &sizeofttl);

The ttl parameter in the preceding code example contains the current TTL set value for the multicasts through a socket defined as sock.

Each multicast transmission is sent from a single network interface, even if the host has more than one multicasting-capable interface. The following code example shows how a socket option is available to determine which interface is currently used for transmissions from a specified socket.

unsigned long addr;     //Allocate space for address.
int sizeofaddr = sizeof(addr); //Create an integer containing size of
        //address.
getsockopt( 
    sock,
    IPPROTO_IP,
    IP_MULTICAST_IF,
    (char *)&addr, 
    &sizeofaddr );

The addr parameter contains the local IP address of the current outgoing interface after a getsockopt call.

By default, if a multicast datagram is sent to a group, to which the sending host belongs, a copy of the datagram on the outgoing interface is looped back by IP for local delivery. Any attempt to disable this multicast loop-back results in the call failing with the error message WSAENOPROTOOPT.

See Also

Creating an IP Multicast Application

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.