#include #include #include #include #include main() { struct sockaddr_in ServerAddr; int sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP); int reuse = 1; setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int)); memset(&ServerAddr, 0, sizeof(ServerAddr)); ServerAddr.sin_family = AF_INET; ServerAddr.sin_addr.s_addr = htonl(INADDR_ANY); int port = 15922; ServerAddr.sin_port = htons((short) port); bind(sock, (struct sockaddr *)&ServerAddr, sizeof(ServerAddr)); struct ip_mreq mreq; memset(&mreq, 0, sizeof(mreq)); mreq.imr_multiaddr.s_addr = inet_addr("227.234.253.9"); mreq.imr_interface.s_addr = htonl(INADDR_ANY); setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); char str[100]; memset(&str, 0, sizeof(str)); recv(sock, str, 100, 0); printf(":%s:\n", str); close (sock); }