Path: utzoo!attcan!uunet!mcsun!ukc!icdoc!qmw-cs!kinawi From: kinawi@cs.qmw.ac.uk (Husam Kinawi) Newsgroups: comp.unix.questions Subject: How to know if the network supports broadcasting ? Keywords: broadcast, ioctl, SIOCGIFFLAGS Message-ID: <2588@sequent.cs.qmw.ac.uk> Date: 28 Jul 90 18:02:45 GMT Reply-To: kinawi@cs.qmw.ac.uk (Husam Kinawi) Organization: Computer Science Dept, QMW, University of London, UK. Lines: 99 Expires: References: Followup-To: Hello, The title really says it all. A trial of mine (code is shown at the end) was trying to read the network interface flags by using ioctl with the command as SIOCGIFFLAGS, the parameter to be of type "ifreq", and the file descriptor to be a socket of AF_INET protocol family, but that does not work, giving me an errno = ENXIO, ie. No such device or address!!. 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 ? The hardware used is MacIIcx running A/UX V1.1.1, connected to an Ethernet, or Sequent running DYNIX V3.0.14 connected to the same ethernet. Any reply is deeply appreciated, but please reply by e-mail. Thank you very much in advance, Husam Kinawi. Cut Here for the code: ______________________________________________________________________________ #include #include #include #include #include #include #include #include #include #include #define MACHINE_NAME 50 void main() { int SocketId, SocketSize = sizeof(struct sockaddr_in); struct hostent *hp; struct ifreq p; struct servent *service; struct sockaddr_in sa; char SelfName[MACHINE_NAME]; int bindErr; int port; struct rtentry rt; bzero((char *)&sa, SocketSize); gethostname(SelfName, MACHINE_NAME); hp = gethostbyname(SelfName); if(hp != NULL){ sa.sin_family = hp->h_addrtype; bcopy((char*)hp->h_addr,(char*)&sa.sin_addr,hp->h_length); } else{ printf("\nCannot find self identity!\n"); exit(); } /* intializing sockets, opening SuperQueue */ SocketId = socket(AF_INET, SOCK_DGRAM, 0); if (SocketId < 0){ printf("\nProblem for allocating the socket\n"); exit(); } service = getservbyname("project", "udp"); /* there is an entry in the /etc/services under this name */ port = sa.sin_port = htons(service->s_port); do{ bindErr=bind(SocketId, &sa, SocketSize, 0); if (bindErr<0){ printf("Failure ...\n"); perror("* "); sa.sin_port = htons(++port); } else ; } while (bindErr<0); printf("Address Type : %d\n", sa.sin_family); printf("Address Port : %d\n", sa.sin_port); printf("Address : %s\n", inet_ntoa(sa.sin_addr)); printf("SocketId : %d\n", SocketId); if(ioctl(SocketId, SIOCGIFADDR, p) == -1){ perror("Ioctl"); printf("Errno = %d\n", errno); } else printf("p.ifr_flags = %d\n", p.ifr_flags); } /*end of code */ ______________________________________________________________________________ Husam Kinawi (MSc Student) | ARPA : kinawi@cs.qmw.ac.uk Dept. of Computer Science | UUCP : kinawi@qmw-cs.UUCP Queen Mary & Westfield College | Tel : 071- 975 5261 Mile End Road | Fax : 081- 980 6533 LONDON, E1 4NS, United Kingdom | Home Tel: 081- 980 7223 (After 23.00 GMT)