From owner-freebsd-hackers Fri Mar 6 16:59:07 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id QAA21490 for freebsd-hackers-outgoing; Fri, 6 Mar 1998 16:59:07 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from smtp02.primenet.com (smtp02.primenet.com [206.165.6.132]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA21484 for ; Fri, 6 Mar 1998 16:58:57 -0800 (PST) (envelope-from tlambert@usr09.primenet.com) Received: (from daemon@localhost) by smtp02.primenet.com (8.8.8/8.8.8) id RAA11908; Fri, 6 Mar 1998 17:58:53 -0700 (MST) Received: from usr09.primenet.com(206.165.6.209) via SMTP by smtp02.primenet.com, id smtpd011878; Fri Mar 6 17:58:50 1998 Received: (from tlambert@localhost) by usr09.primenet.com (8.8.5/8.8.5) id RAA24995; Fri, 6 Mar 1998 17:58:46 -0700 (MST) From: Terry Lambert Message-Id: <199803070058.RAA24995@usr09.primenet.com> Subject: Re: Detecting state of PPP To: bhlewis@gte.net (Benjamin Lewis) Date: Sat, 7 Mar 1998 00:58:46 +0000 (GMT) Cc: pvh@leftside.wcape.school.za, freebsd-hackers@FreeBSD.ORG In-Reply-To: <199803060014.TAA13234@gte.net> from "Benjamin Lewis" at Mar 5, 98 07:14:00 pm X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > How does one go about writing a program to check if a PPP link is up > > or down? > > I've seen lots of complicated responses to this, so there is probably > something inherintly wrong with what I've always done, check for the > existence of the /var/spool/lock/LCK..cuaa? file. If there is a possibility > that something else is using the serial line, one could check whether the > PID in the file matches the PPP process. #include #include #include #include #include #include #include #include #include main() { char *ppp_name = "tun0"; struct ifreq ifr; int s; if( ( s = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { perror( "socket"); exit( 1); } strcpy( ifr.ifr_name,ppp_name); if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) == -1) { perror( "ioctl"); exit( 1); } printf( "%s: %s\n", ppp_name, (ifr.ifs_flags & IFF_UP) ? "up" : "down"); exit( 0); } Of course, not all of the includes are needed; I ripped this out of an experimental piece of DHCP code. Change the interface name from "tun0" to whatever; I happen to run user space ppp, so mine is named tun0. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message