Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msunews!agate!howland.reston.ans.net!swrinde!elroy.jpl.nasa.gov!decwrl!purdue!news.bu.edu!dartvax.dartmouth.edu!usenet From: Ting Cai <tcai> Newsgroups: comp.unix.bsd.freebsd.misc Subject: Help on network status Date: 24 Oct 1995 00:09:07 GMT Organization: Dartmouth College, Hanover, NH, USA Lines: 107 Message-ID: <46har3$jbl@dartvax.dartmouth.edu> NNTP-Posting-Host: yosemite.cs.dartmouth.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 1.1N (X11; I; OSF1 V3.2 alpha) To: tcai@cs.dartmouth.edu X-URL: news:comp.unix.bsd.freebsd.misc/9785-9884#46g6c7$6tt@ida.interface-business.de Hi! All: I am trying to find out an easy and quick way to tell if the network is up or down.I found that ioctl could retrieve the 'ifflags' which contains the infomation on if the network is up, but after hours of trying, ioctl still returns error: ioctl: Device not configured Here is the little program I wrote: struct ifreq data; struct sockaddr_in address; size = sizeof(struct sockaddr_in); if ((id = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); exit(1); } bzero ((char *) &address, sizeof(address)); address.sin_family = PF_INET; address.sin_port = htons(SERV_TCP_PORT); address.sin_addr.s_addr = htonl (INADDR_ANY); if (bind(id,(struct sockaddr *) &address, size)) { perror("bind"); exit(1); } if ( ioctl(id,SIOCGIFFLAGS,&data ) < 0) { perror("ioctl"); exit(1); } /************* struct ifreq data; struct sockaddr_in address; size = sizeof(struct sockaddr_in); if ((id = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); exit(1); } bzero ((char *) &address, sizeof(address)); address.sin_family = PF_INET; address.sin_port = htons(SERV_TCP_PORT); address.sin_addr.s_addr = htonl (INADDR_ANY); if (bind(id,(struct sockaddr *) &address, size)) { perror("bind"); exit(1); } if ( ioctl(id,SIOCGIFFLAGS,&data ) < 0) { perror("ioctl"); exit(1); } struct ifreq data; struct sockaddr_in address; size = sizeof(struct sockaddr_in); if ((id = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); exit(1); } bzero ((char *) &address, sizeof(address)); address.sin_family = PF_INET; address.sin_port = htons(SERV_TCP_PORT); address.sin_addr.s_addr = htonl (INADDR_ANY); if (bind(id,(struct sockaddr *) &address, size)) { perror("bind"); exit(1); } if ( ioctl(id,SIOCGIFFLAGS,&data ) < 0) { perror("ioctl"); exit(1); } /*************** end of program ************************************/ Do you have some suggestions? or any other way to get the network status information? Many thanks to you all. Ting Cai at Dartmouth College email: tcai@cs.dartmouth.edu *****************/ -- Ting tcai@cs.dartmouth.edu