#include #include #include int main(int argc, char **argv) { struct sockaddr_storage dest; struct sockaddr_storage src; struct sockaddr_in *s = (struct sockaddr_in*) &src; struct sockaddr_in *d = (struct sockaddr_in *)&dest; int sock; char msg[] = "Hello Multicast"; int off = 0; memset(&dest, 0, sizeof(dest)); memset(&src, 0, sizeof(src)); if (argc < 3) { printf("Usage: \n"); return 1; } d->sin_family = s->sin_family = AF_INET; d->sin_port = htons(2000); inet_aton(argv[1], &s->sin_addr); inet_aton(argv[2], &d->sin_addr); sock = socket(AF_INET, SOCK_DGRAM, 0); if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, &off, sizeof(off))) { perror("setsockopt"); return 1; } if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, s, sizeof(*s))) { perror("setsockopt"); return 1; } sendto(sock, msg, sizeof(msg), 0, (struct sockaddr *)d, sizeof(*d)); close (socket); return 0; }