我是ipv6和libcoap的新手。我正在使用libcoap中提供的“coap-server”示例来测试我的coap客户端。我不能让coap-server持续到多播才能正常工作。我尝试了以下命令
./coap-server -g FF02::FD
# return "join: setsockopt: Protocol error"
# this method is found in https://manpages.debian.org/stretch/libcoap-1-0-bin/coap-server.5.en.html
./coap-server -g FF02:FD
# return "join: cannot resolve multicast address: Name or service not known"
谁能帮我这个?谢谢。
查看Linux source code,文件source/net/ipv6/ipv6_sockglue.c
,此检查决定是否返回“协议错误”错误代码:
retv = -EPROTO;
if (inet_sk(sk)->is_icsk)
break;
因此,如果套接字是面向连接的(例如TCP套接字),则代码返回错误。
看起来像libcoap打开两个地址系列(IPv4和IPv6)的套接字,UDP和TCP以及它们的安全版本(分别是DTLS和TLS)。
因此,您可能需要更改示例以迭代所有打开的CoAP端点并找到IPv6 UDP端点(我没有看到任何命令行选项。因此,而不是使用当前的第一个:
setsockopt(ctx->endpoint->sock.fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (char *)&mreq, sizeof(mreq));
你应该迭代所有打开的,并检查proto
字段和地址系列是否匹配
coap_endpoint_t *ep = ctx->endpoint;
while (ep != NULL && ep->proto != COAP_PROTO_UDP
&& /* TODO: check address family */) {
ep = ep->next;
}
if (ep != NULL) {
result = setsockopt(ep->sock.fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (char *)&mreq, sizeof(mreq));
}