ptpd2提示failed to join the multicast group (strerror: No buffer space available)

下载交叉编译ptpd-ptpd-2.3.1源码,在IMX6板子上面运行ptpd2提示错误如下:

root@imx6qsabresd_genvict:~# ./ptpd2 -C -m -i eth0
2023-11-24 14:30:21.484399 ptpd2[6512].startup (info)      (___) Configuration OK
2023-11-24 14:30:21.487152 ptpd2[6512].startup (info)      (___) Successfully acquired lock on /var/run/ptpd2.lock
2023-11-24 14:30:21.487684 ptpd2[6512].startup (notice)    (___) PTPDv2 started successfully on eth0 using "masterslave" preset (PID 6512)
2023-11-24 14:30:21.487775 ptpd2[6512].startup (info)      (___) TimingService.PTP0: PTP service init
2023-11-24 14:30:21.491781 ptpd2[6512].eth0 (error)     (init) failed to join the multicast group      (strerror: No buffer space available)
2023-11-24 14:30:21.491880 ptpd2[6512].eth0 (error)     (init) Failed to initialize network
2023-11-24 14:30:21.491943 ptpd2[6512].eth0 (error)     (flt) PTPd init failed - will retry in 10 seconds

查看源码:src/dep/net.c,函数:netInitMulticastIPv4

	/* join multicast group (for receiving) on specified interface */
	if (setsockopt(netPath->eventSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, 
		       &imr, sizeof(struct ip_mreq)) < 0
	    || setsockopt(netPath->generalSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, 
			  &imr, sizeof(struct ip_mreq)) < 0) {
		PERROR("failed to join the multicast group");
		return FALSE;
	}

添加错误值打印:

	int ret1=0;
	int ret2=0;

	ret1=setsockopt(netPath->eventSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &imr, sizeof(struct ip_mreq));
	if(ret1 < 0){
		printf("errno = %d\n",errno);	//105	
		printf("ret1=%d\n",ret1);
		return FALSE;
	}

	ret2=setsockopt(netPath->generalSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &imr, sizeof(struct ip_mreq));
	if(ret2 < 0){
		printf("ret2=%d\n",ret2);
		return FALSE;
	}

setsockopt返回-1,错误值105,搜索系统头文件:/usr/include/asm-generic/errno.h

#define ENOBUFS     105 /* No buffer space available */

通过网上搜到https://www.jianshu.com/p/6dfaeefac922,UDP组播的内核参数为0导致问题,修改10解决问题:

root@imx6qsabresd_genvict:~# sysctl net.ipv4.igmp_max_memberships
net.ipv4.igmp_max_memberships = 0
root@imx6qsabresd_genvict:~# 
root@imx6qsabresd_genvict:~# sysctl -w net.ipv4.igmp_max_memberships=10
net.ipv4.igmp_max_memberships = 10

查看其他平台是设置的参数20,所以没有这个问题。

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值