Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!racerx!ken From: ken@racerx.UUCP (Ken Hardy) Newsgroups: comp.protocols.tcp-ip Subject: Re: Internet broadcast: INADDR_BROADCAST Summary: Need valid net portion Message-ID: <567@racerx.UUCP> Date: 11 Apr 91 18:00:45 GMT References: Distribution: comp Organization: Bridge Information Systems, St. Louis Lines: 71 In article , benny@vlss.amdahl.com (Benny Schnaider) writes: > Hi, > > I am trying to broadcast a message over the internet by using the > INADDR_BROADCAST shorthand notation. I tried this on SunOS 4.01 > and got: Network is unreachable... On other system that I tried > the same code it worked. > Code is enclosed. > > 1. What is the problem ? > 2. How common is it to use INADDR_BROADCAST ? > > Thanks, > Benny. You need to have a valid network in the network portion of the internet address. This is a routine I use on Suns to build a broadcast address. May not be cleanest code, but it works on Sun 4.0 & 4.1. The print statements yield: Name = [racerx] Host ID 80420006 Net ID 00008042 Bcast ID 8042ffff This get physically resolved on our system to a broadcast ethernet address. This may or may not be passed by bridges. IP routers may not pass it based on the network portion of the IP address, and even if a bridge or router passes it, other IP hosts on another network may not pay attention to it if they have another network i.d. ---------------------------------------------------------------- int bcast_address () /* * */ { struct in_addr bcip; unsigned ipad, netp; extern struct hostent *getmyhostent () ; if (my_he == (struct hostent *)0) { my_he = getmyhostent () ; memcpy (&myip.s_addr, my_he->h_addr, sizeof (myip.s_addr)); memcpy (&my_ipaddr[0], my_he->h_addr, sizeof (myip.s_addr) ) ; } netp = inet_netof (myip); bcip = inet_makeaddr (netp, INADDR_BROADCAST); if (bug) { printf ("Name = [%s]\n", my_he->h_name); printf ("Host ID %08lx\n", htonl (myip.s_addr)); printf ("Net ID %08lx\n", netp); printf ("Bcast ID %08lx\n", htonl (bcip.s_addr)); } RETURN (bcip.s_addr); } ---------------------------------------------------------------- -- Ken Hardy uunet!racerx!ken ken@racerx.UUCP