+/*
+ * Procedure to determine if the PPP line dicipline is registered.
+ */
+
+int
+ppp_registered(void)
+ {
+ int local_fd;
+ int ppp_disc = N_PPP;
+ int init_disc = -1;
+ int initfdflags;
+
+ local_fd = open(devnam, O_NONBLOCK | O_RDWR, 0);
+ if (local_fd < 0)
+ {
+ syslog(LOG_ERR, "Failed to open %s: %m", devnam);
+ return 0;
+ }
+
+ initfdflags = fcntl(local_fd, F_GETFL);
+ if (initfdflags == -1)
+ {
+ syslog(LOG_ERR, "Couldn't get device fd flags: %m");
+ close (local_fd);
+ return 0;
+ }
+
+ initfdflags &= ~O_NONBLOCK;
+ fcntl(local_fd, F_SETFL, initfdflags);
+/*
+ * Read the initial line dicipline and try to put the device into the
+ * PPP dicipline.
+ */
+ if (ioctl(local_fd, TIOCGETD, &init_disc) < 0)
+ {
+ syslog(LOG_ERR, "ioctl(TIOCGETD): %m");
+ close (local_fd);
+ return 0;
+ }
+
+ if (ioctl(local_fd, TIOCSETD, &ppp_disc) < 0)
+ {
+ syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+ close (local_fd);
+ return 0;
+ }
+
+ if (ioctl(local_fd, TIOCSETD, &init_disc) < 0)
+ {
+ syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+ close (local_fd);
+ return 0;
+ }
+
+ close (local_fd);
+ return 1;
+ }
+