What happens if I don't send IP_DROP_MEMBERSHIP before closing my socket?

Viewed 1845

I'm working on some code which joins a multicast group using an IGMP join

struct ip_mreq mreq;
inet_pton(AF_INET, group, &mreq.imr_multiaddr.s_addr);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);

if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char*)&mreq, sizeof(mreq)) < 0)
    throw std::runtime_error(perror("setsockopt(IP_ADD_MEMBERSHIP)"));

When the application shuts down, it closes the socket

close(fd);

However, it doesn't perform an IP_DROP_MEMBERSHIP.

  • Will multicast continue to be delivered to my network interface by the upstream router?
  • Is the OS (in my case Linux) smart enough to send the drop membership request for me when the socket is closed?
2 Answers
Related