Date: Sat, 7 Mar 1998 00:58:46 +0000 (GMT) From: Terry Lambert <tlambert@primenet.com> To: bhlewis@gte.net (Benjamin Lewis) Cc: pvh@leftside.wcape.school.za, freebsd-hackers@FreeBSD.ORG Subject: Re: Detecting state of PPP Message-ID: <199803070058.RAA24995@usr09.primenet.com> In-Reply-To: <199803060014.TAA13234@gte.net> from "Benjamin Lewis" at Mar 5, 98 07:14:00 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> > 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 <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <stdio.h>
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199803070058.RAA24995>
