From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,25cf5bec739a3c26,start X-Google-Attributes: gidfee84,public From: "Igor A. Lefterov" Subject: IP multicasting doesn't work Date: 1996/02/27 Message-ID: <27Feb96.175528left@niti.spb.su>#1/1 X-Deja-AN: 141404829 distribution: world sender: news@dragon.infopro.spb.su organization: unknown newsgroups: comp.unix.osf.osf1 x-return-path: niti!niti.spb.su!left@infopro.spb.su Please help me to solve my problem. I cannot make my program to exchange multicast datagrams via IP. It seems that I write everything following my Programmer's Guide: the client joins the multicast group; the server issues 'sento' at the group address. What more? What I do wrong? Little simple programs go below. Running the programs on Alpha OSF1 V3.2, got diagnostics: "sendto: Host is unreachable" Is our TCP/IP configuration wrong? Any suggestions are appreciated. -------------8<--- client.c ---------------------- #include #include #include #include #include struct ip_mreq mreq; char mcastad [16] = "225.0.0.1"; char myad [16] = "198.76.54.32"; /* my ip */ int sockfd; int serveraddrlen; struct sockaddr_in serveraddr; int n; char buffer [2048]; main () { /* Create a socket for the communications */ if ((sockfd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { perror ("socket_create"); exit (1); } bzero ((char *) &serveraddr, sizeof (struct sockaddr_in)); serveraddr.sin_family = AF_INET; serveraddr.sin_port = htons (1234); serveraddr.sin_addr.s_addr = inet_addr (myad); /* * We want to receive mcast datagrams: */ mreq.imr_multiaddr.s_addr = inet_addr (mcastad); mreq.imr_interface.s_addr = inet_addr (myad); if (setsockopt (sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof (mreq)) == -1) perror ("CLIENT: IP_ADD_MEMBERSHIP"); /* Bind the address to this socket to make it 'known' */ if (bind (sockfd, (struct sockaddr *) &serveraddr, sizeof (struct sockaddr_in)) < 0) { perror ("CLIENT: socket_bind"); exit (2); } printf ("CLIENT: waiting for message...\n"); while (1) { /* receive info */ if ((n = recvfrom (sockfd, buffer, sizeof (buffer), 0, (struct sockaddr *) &serveraddr, &serveraddrlen)) < 0) { perror("CLIENT: recvfrom"); exit(1); } printf ("CLIENT: received %d bytes\n", n); } } -------------8<--- server.c ---------------------- #include #include #include #include #include int fd; struct sockaddr_in mmaddr; int mmaddrlen = sizeof (mmaddr); char data [2048]; int dcount = sizeof (data); int n = 10; main () { /* Create a socket for the communications */ if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { perror ("socket_create"); exit (1); } bzero ((char *) &mmaddr, sizeof (struct sockaddr_in)); mmaddr.sin_family = AF_INET; mmaddr.sin_addr.s_addr = inet_addr ("198.76.54.32"); /* my ip */ mmaddr.sin_port = htons (1234); /* Specify interface for multicasting: */ if (setsockopt (fd, IPPROTO_IP, IP_MULTICAST_IF, &mmaddr.sin_addr, sizeof (struct in_addr)) == -1) perror ("setsockopt IP_MULTICAST_IF"); /* Group address to send to: */ mmaddr.sin_addr.s_addr = inet_addr ("225.0.0.1"); while (n --) { if (sendto (fd, data, dcount, 0, (struct sockaddr *) &mmaddr, mmaddrlen) < 0) perror ("sendto"); printf ("SERVER: sent %d bytes\n", dcount); sleep (5); } close (fd); } -- Igor A.Lefterov Sosnovy Bor, S-Peterburg reg., Russia E-mail: left@niti.spb.su