broadcast sockets

Kevin Davidson tkld at cs.ed.ac.uk
Tue Jan 29 02:39:45 AEST 1991


zahra at wolfen.cc.uow.oz (Andrew Zahra Telecom), babbling inanely in article <6746 at wolfen.cc.uow.oz>, claimed:
>I am trying to write a program which will be able to broadcast messages to all
>other machines on the local network. I am using a datagram socket and have not 
>had much success with various combinations of setting socket options 
>(SO_BROADCAST) and doing a connect to INADDR_BROADCAST. I either get a network
>unreachable error or an error from the bind indicating it can't allocate the
>requested address.
>

  I too am trying to do this, and get the same kinds of errors. I notice there
is a comment in the Sun include file <netinet/in.h> that INADDR_BROADCAST
should be masked - how ? To what ? Can I limit the broadcast to subnets - I
don't really want to wake up every machine on a large net, just the local ones?

  I have also tried the code in the Sun manual that queries each ether
interface for broadcast addresses and tries those. My messages just seem to
disappear. (sendto() thinks everything's hunky-dory, but I can't recvfrom()
it.)
  

>If anyone has a minimal code example of how to do this it would be very welcome
>and may stop me tearing my hair out.

  Baldness is a sign of maturity....:-)

--
	.Kevin.		<tkld at lfcs.ed.ac.uk>
			<tkld at tardis.cs.ed.ac.uk>



More information about the Comp.unix.programmer mailing list