Код (Text): int __cdecl _tmain(int argc, _TCHAR **argv, _TCHAR **envp){ WSAStartup(MAKEWORD(2,2),&wsad); if((sl=socket(PF_INET,SOCK_DGRAM,0))==SOCKET_ERROR) return printf("Can't create socket\n"); sa.sin_family=AF_INET; sa.sin_port=htons(SERVER_PORT); sa.sin_addr.s_addr=htonl(INADDR_ANY); if(bind(sl,(SOCKADDR*) &sa,sizeof(sa))== SOCKET_ERROR) return printf("Can't bind socket\n"); /* join the multicast group we want to receive datagrams from */ stIpMreq.imr_multiaddr.s_addr = htonl(0xE0E0E0E0); /* group addr */ stIpMreq.imr_interface.s_addr = htonl(INADDR_ANY); /* use default */ int nRet; nRet = setsockopt (sl, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char FAR *)&stIpMreq, sizeof (struct ip_mreq)); setsockopt возвращает -1, а код ошибки 10042 - WSAENOPROTOOPT, что я делаю не так?
winsock.h: Код (Text): //Options for use with [gs]etsockopt at the IP level. #define IP_OPTIONS 1 /* set/get IP per-packet options */ #define IP_MULTICAST_IF 2 /* set/get IP multicast interface */ #define IP_MULTICAST_TTL 3 /* set/get IP multicast timetolive */ #define IP_MULTICAST_LOOP 4 /* set/get IP multicast loopback */ #define IP_ADD_MEMBERSHIP 5 /* add an IP group membership */ #define IP_DROP_MEMBERSHIP 6 /* drop an IP group membership */ #define IP_TTL 7 /* set/get IP Time To Live */ #define IP_TOS 8 /* set/get IP Type Of Service */ #define IP_DONTFRAGMENT 9 /* set/get IP Don't Fragment flag */ ws2tcpip.h: Код (Text): /* Option to use with [gs]etsockopt at the IPPROTO_IP level */ #define IP_OPTIONS 1 /* set/get IP options */ #define IP_HDRINCL 2 /* header is included with data */ #define IP_TOS 3 /* IP type of service and preced*/ #define IP_TTL 4 /* IP time to live */ #define IP_MULTICAST_IF 9 /* set/get IP multicast i/f */ #define IP_MULTICAST_TTL 10 /* set/get IP multicast ttl */ #define IP_MULTICAST_LOOP 11 /*set/get IP multicast loopback */ #define IP_ADD_MEMBERSHIP 12 /* add an IP group membership */ #define IP_DROP_MEMBERSHIP 13/* drop an IP group membership */ ... вбил в код 12 и теперь всё работает