[comp.unix.wizards] Help with sending broadcast messages using Ultrix

pato@apollo.uucp (Joe Pato) (06/23/87)

I have code that I've ported to a number of Unix implementations that
sends broadcast messages over a UDP datagram socket.   This code (with
some variations) works on bsd4.2, bsd4.3, sun OS, alliant concentrix, 
apollo domain/ix, ....

Most recently I've tried to get it to work under DEC Ultrix 1.2 with
little success.  (I know that rwhod runs under Ultrix, so I must be
doing something wrong...)   I've run my test code as both a regular user
and as root (some bsd4.2 derived systems require you to be root in order
to send a broadcast message) and in both cases I get no errors, and
the receiving side sees none of the messages.

I would appreciate any words of wisdom from anyone who has had experience 
with this under Ultirx.

The following code fragments show the critical parts of the code:

	sock = socket(AF_INET, SOCK_DGRAM, 0);
#ifdef SO_BROADCAST
	if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, NULL, NULL) == -1) {
		perror("setsockopt: SO_BROADCAST");
	}
#endif

	... set port, and get interface configuration

    ... check that Interface is up, running and supports broadcast

#if sun || alliant
		inet_addr = (struct sockaddr_in *) &ifr->ifr_addr;
		saddr.sin_addr = inet_makeaddr(
			inet_netof(inet_addr->sin_addr), INADDR_ANY);
#else		
		if (ioctl(sock, (int) SIOCGIFBRDADDR, &ifreq) == -1) {
			perror("transmit/get broadcast address: ");
			continue;
		}
		inet_addr = (struct sockaddr_in *) &ifreq.ifr_broadaddr;
		saddr.sin_addr.s_addr = inet_addr->sin_addr.s_addr;
#endif
		retcode = sendto(sock, buf, 5, 0, &saddr, sizeof(saddr));




  Joe Pato              UUCP: ...{attunix,uw-beaver,brunix}!apollo!pato
  Apollo Computer Inc.  ARPA: apollo!pato@mit-eddie.arpa