I have a code in which send multicast datagrams. A critical piece of code:
uint32_t port;
int sockfd, err_ip;
const uint32_t sizebuff = 65535 - (20 + 8);
uns
IP_ADD_MEMBERSHIP
and bind()
are only required for receiving multicast, use IP_MULTICAST_IF
instead for effectively a "send-only membership" of a multicast group.
IP_MULTICAST_IF
sets the kernel to send multicast packets for a given group on a given interface, it is effectively "send-only" as you will not be able to receive traffic on that group after setting. This varies by platform: Posix platforms generally function this way as an optimisation, whilst Win32 will perform software level routing to propagate locally generated packets.