你是先加入多播组吗?您必须明确告诉操作系统您要加入的组,然后它将向您发送组的消息。您可以使用一个命令setsockopt()
来加入多播组。从达尔文 ip6 联机帮助页:
IPV6_JOIN_GROUP struct ipv6_mreq *
Join a multicast group. A host must become a member of a multicast group before it can receive
datagrams sent to the group.
struct ipv6_mreq {
struct in6_addr ipv6mr_multiaddr;
unsigned int ipv6mr_interface;
};
ipv6mr_interface may be set to zeroes to choose the default multicast interface or to the index
of a particular multicast-capable interface if the host is multihomed. Membership is associ-
ated with a single interface; programs running on multihomed hosts may need to join the same
group on more than one interface.
If the multicast address is unspecified (i.e., all zeroes), messages from all multicast
addresses will be accepted by this group. Note that setting to this value requires superuser
privileges.
我在这里找到了一些示例代码:
struct ipv6_mreq mreq6;
memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr),
sizeof(struct in6_addr));
mreq6.ipv6mr_interface= 0;
err = setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq6));
if (err) fprintf(stderr, "setsockopt IPV6_JOIN_GROUP: %s\n", strerror (errno));
但也许你已经这样做了?