/*将本机加入多播组*/ err = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,&mreq, sizeof(mreq)); if (err < 0) { perror("setsockopt():IP_ADD_MEMBERSHIP"); exit(1); }
因为不同的socket版本,定义IP_ADD_MEMBERSHIP 的值不同:
in socket ver1.0中:
#define IP_ADD_MEMBERSHIP 5
in socket ver2.0中:
#define IP_ADD_MEMBERSHIP 12
改为:
err = setsockopt(fd, IPPROTO_IP, 12,&mreq, sizeof(mreq));