Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!nsc!amdahl!juts!benny From: benny@vlss.amdahl.com (Benny Schnaider) Newsgroups: comp.protocols.tcp-ip Subject: Internet broadcast: INADDR_BROADCAST Message-ID: Date: 10 Apr 91 18:09:56 GMT Sender: netnews@ccc.amdahl.com Distribution: comp Organization: Amdahl Corp., Sunnyvale CA Lines: 87 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. ____________________________________________________________________________ int sd, on; struct sockaddr_in sockAddr; /* * zero out the socket structures */ bzero(&sockAddr, sizeof(sockAddr)); /* * Open the socket */ if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { close(sd); BPCerror(LOG_WARNING, "in socket creation (request)"); return(ERROR); } /* * Mark the socket to allow broadcast. */ on = 1; if ((setsockopt(sd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on))) == -1) { close(sd); BPCerror(LOG_WARNING, "in SO_BROADCAST"); return(ERROR); } /* * Fill sockAddrAs */ sockAddr.sin_family = AF_INET; sockAddr.sin_port = IPPORT_BOOTPS; sockAddr.sin_addr.s_addr = INADDR_ANY; /* * Bind the socket */ if (bind(sd, &sockAddr, sizeof(sockAddr)) == -1) { close(sd); BPCerror(LOG_WARNING, "in socket binding (request)"); return(ERROR); } /* * Broadcast the request */ sockAddr.sin_addr.s_addr = INADDR_BROADCAST; if (sendto(sd, msg, sizeof(*msg), 0, &sockAddr, sizeof(sockAddr)) == -1) { close(sd); BPCerror(LOG_WARNING, "sendto"); return(ERROR); } /* sendto */ close(sd); return(OK); } /* BPCrequestIP() */ ----------------------------------------------------------------- Benny Schnaider benny@vlss.amdahl.com Amdahl Corporation, 1250 EAST Arques Avenue, M/S 246, Sunnyvale CA, 94088-3470 (408) 296 - 0596, (408) 746-3440 ----------------------------------------------------------------- -- ----------------------------------------------------------------- Benny Schnaider benny@vlss.amdahl.com Amdahl Corporation, 1250 EAST Arques Avenue, M/S 246, Sunnyvale CA, 94088-3470 (408) 296 - 0596, (408) 746-3440 -----------------------------------------------------------------