From owner-freebsd-hackers Mon Oct 23 17:37:40 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id RAA12278 for hackers-outgoing; Mon, 23 Oct 1995 17:37:40 -0700 Received: from dartvax.dartmouth.edu (dartvax.dartmouth.edu [129.170.16.4]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id RAA12268 for ; Mon, 23 Oct 1995 17:37:38 -0700 Received: from vixen.Dartmouth.EDU (vixen.dartmouth.edu [129.170.208.15]) by dartvax.dartmouth.edu (8.6.12-DND/8.6.12) with SMTP id UAA25675 for ; Mon, 23 Oct 1995 20:37:35 -0400 Message-id: <9872290@vixen.Dartmouth.EDU> Date: 23 Oct 95 20:37:35 EDT From: Ting.Cai@Dartmouth.EDU (Ting Cai) Subject: Network Status Problem To: freebsd-hackers@freebsd.org Sender: owner-hackers@freebsd.org Precedence: bulk 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); } /************* 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 --UAA25927.814494928/dartvax.dartmouth.edu--