Subscribing to multiple multicast groups on one socket (Linux, C)

前端 未结 6 1475
悲哀的现实
悲哀的现实 2020-12-31 15:29

Is it possible to receive data from more than one multicast group on a single socket?

For example:

void AddGroup(int sock,
              const char*          


        
6条回答
  •  离开以前
    2020-12-31 15:59

    Yes, it's possible: look on the example in the link (http://www.tenouk.com/Module41c.html) To shorten this up in a few steps:

    1. You setsockopt with SO_REUSEADDR
    2. You bind on INADDR_ANY
    3. You setsockopt with IP_ADD_MEMBERSHIP on every group you want to receive datagram from.
    4. It seems to me that using IP_PKTINFO gives an option to distinguish received packets, but sender must take care about preparing them(Setting the source IP for a UDP socket)

提交回复
热议问题