Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!rex!ames!excelan!murthy From: murthy@la.excelan.com (M.D. Srinivas Murthy) Newsgroups: comp.unix.questions Subject: Re: How to know if the network supports broadcasting ? Keywords: broadcast, ioctl, SIOCGIFFLAGS Message-ID: <1620@excelan.COM> Date: 30 Jul 90 18:25:27 GMT References: <2588@sequent.cs.qmw.ac.uk> Sender: news@excelan.COM Reply-To: murthy@la.excelan.com (M.D. Srinivas Murthy) Organization: Excelan, Inc., San Jose, Califonia Lines: 37 In article <2588@sequent.cs.qmw.ac.uk> kinawi@cs.qmw.ac.uk (Husam Kinawi) writes: >Hello, >SIOCGIFFLAGS, the parameter to be of type "ifreq", and the file descriptor to > >My Questions are: >i) Is this the right way to detect ifa network supports broadcast, and if yes, > what makes my ioctl fail to work ? >ii)If I am not on the right way, then is there a possible way to detect > whether the network used supports broadcast ? > > if(ioctl(SocketId, SIOCGIFADDR, p) == -1){ > perror("Ioctl"); > printf("Errno = %d\n", errno); > } The approach is right. But - 1. The ioctl code should be SIOCGIFFLAGS. 2. The third parameter has to be a pointer to ifreq structure. 3. You have to specify the interface name (p.ifr_name) for which you want the flags. here is the part of the code which worked on a SUN system. strcpy(p.ifr_name,"ie0"); if(ioctl(SocketId, SIOCGIFFLAGS, &p) == -1){ perror("Ioctl"); printf("Errno = %d\n", errno); } I hardcoded the interface name in the example. But you can get the interface name of all the interfaces using the SIOCGIFCONF ioctl. SIOCGIFCONF take an array of ifreq structures and fills them with interface name and interface address. murthy