How to know if the network supports broadcasting ?

Husam Kinawi kinawi at cs.qmw.ac.uk
Sun Jul 29 04:02:45 AEST 1990


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 <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/route.h>
#include <net/if.h>
#include <sys/ioctl.h>

#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 at cs.qmw.ac.uk
Dept. of Computer Science      | UUCP    : kinawi at 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)



More information about the Comp.unix.questions mailing list