Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* IP multicasting doesn't work
@ 1996-02-27  5:00 Igor A. Lefterov
  0 siblings, 0 replies; only message in thread
From: Igor A. Lefterov @ 1996-02-27  5:00 UTC (permalink / raw)


	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 <sys/socket.h>
#include <sys/errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>

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 <sys/socket.h>
#include <sys/errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>

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

 



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-02-27  5:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-02-27  5:00 IP multicasting doesn't work Igor A. Lefterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox