Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!adm!xadmx!bush%prg.oxford.ac.uk@nsfnet-relay.ac.uk From: bush%prg.oxford.ac.uk@nsfnet-relay.ac.uk (Mark Bush) Newsgroups: comp.unix.wizards Subject: Re: sockets Message-ID: <20713@adm.BRL.MIL> Date: 27 Aug 89 22:03:44 GMT Sender: news@adm.BRL.MIL Lines: 45 Firstly, I would like to thank Paul DuBois for his suggestion. Unfortunately it didn't answer my original question which was "how do I get broadcasting on sockets to work?". I hadn't worded it like that, but that was the intent. With a little work (and dbx and those usefully arranged `printf's) I managed to solve my problem. It appears that my problem was the line: dst.sin_addr = inet_makeaddr(net, INADDR_ANY); The value I was using for `net' was wrong. According to section 5.5 of the "IPC Primer", this value can be obtained from `inet_netof'. I found out that this returned an address of the form `129.67.0.0' where I wanted `129.67.14.0'. What I did was to use: char hostname[15]; struct hostent *thishost; struct in_addr *address; struct sockaddr_in dst; and set the address with the following code: gethostname(hostname, 15); thishost = gethostbyname(hostname); address = (struct in_addr *)(thishost->h_addr); address->S_un.S_addr &= 0x0ffffff00; : : dst.sin_addr = *address; This worked fine. The same chapter of the documentation mentions use of the ioctl call `SIOCGICONF'. I haven't tried this yet, so I don't know if this method also requires a kludge to work of if it supplies correct information. Of course, this problem may well just be relevant to SunOS 3.x. There is an option (SO_BROADCAST) that can be set with `setsockoption' in 4.x that probably does this correctly---again, I haven't tried this on 4.x yet. Section 5.5 of the "IPC Primer" in the SunOS 3.x manuals can thus be happily disregarded (unless, of course, you know different 8*) Mark Bush bush%uk.ac.oxford.prg@ac.uk Teaching Support Programmer bush%prg.oxford.ac.uk@nsfnet-relay.ac.uk OUCL ...!uunet!mcvax!ukc!ox-prg!bush