+
+ if (default_device)
+ tty_sid = getsid((pid_t)0);
+
+ pppfd = open("/dev/ppp", O_RDWR | O_NONBLOCK, 0);
+ if (pppfd < 0) {
+ syslog(LOG_ERR, "Can't open /dev/ppp: %m");
+ die(1);
+ }
+ if (kdebugflag & 1) {
+ x = PPPDBG_LOG + PPPDBG_DRIVER;
+ strioctl(pppfd, PPPIO_DEBUG, &x, sizeof(int), 0);
+ }
+
+ /* Assign a new PPA and get its unit number. */
+ if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0) {
+ syslog(LOG_ERR, "Can't create new PPP interface: %m");
+ die(1);
+ }
+
+ /*
+ * Open the ppp device again and link it under the ip multiplexor.
+ * IP will assign a unit number which hopefully is the same as ifunit.
+ * I don't know any way to be certain they will be the same. :-(
+ */
+ ifd = open("/dev/ppp", O_RDWR, 0);
+ if (ifd < 0) {
+ syslog(LOG_ERR, "Can't open /dev/ppp (2): %m");
+ die(1);
+ }
+ if (kdebugflag & 1) {
+ x = PPPDBG_LOG + PPPDBG_DRIVER;
+ strioctl(ifd, PPPIO_DEBUG, &x, sizeof(int), 0);
+ }
+#ifdef sun
+ if (ioctl(ifd, I_PUSH, "ip") < 0) {
+ syslog(LOG_ERR, "Can't push IP module: %m");
+ close(ifd);
+ die(1);
+ }
+#else
+ if (dlpi_attach(ifd, ifunit) < 0 ||
+ dlpi_get_reply(ifd, &reply.prim, DL_OK_ACK, sizeof(reply)) < 0) {
+ syslog(LOG_ERR, "Can't attach to ppp%d: %m", ifunit);
+ close(ifd);
+ die(1);
+ }
+#endif
+ ipmuxid = ioctl(ipfd, I_LINK, ifd);
+ close(ifd);
+ if (ipmuxid < 0) {
+ syslog(LOG_ERR, "Can't link PPP device to IP: %m");
+ die(1);
+ }
+
+#ifndef sun
+ /* Set the interface name for the link. */
+ (void) sprintf (ifr.ifr_name, "ppp%d", ifunit);
+ ifr.ifr_metric = ipmuxid;
+ if (strioctl(ipfd, SIOCSIFNAME, (char *)&ifr, sizeof ifr, 0) < 0) {
+ syslog(LOG_ERR, "Can't set interface name %s: %m", ifr.ifr_name);
+ die(1);
+ }
+#endif
+}
+
+/*
+ * sys_cleanup - restore any system state we modified before exiting:
+ * mark the interface down, delete default route and/or proxy arp entry.
+ * This should call die() because it's called from die().
+ */
+void
+sys_cleanup()
+{
+ struct ifreq ifr;
+
+ if (if_is_up)
+ sifdown(0);
+ if (default_route_gateway)
+ cifdefaultroute(0, default_route_gateway, default_route_gateway);
+ if (proxy_arp_addr)
+ cifproxyarp(0, proxy_arp_addr);
+}
+
+/*
+ * sys_close - Clean up in a child process before execing.
+ */
+void
+sys_close()
+{
+ close(ipfd);
+ if (pppfd >= 0)
+ close(pppfd);
+}
+
+/*
+ * sys_check_options - check the options that the user specified
+ */
+void
+sys_check_options()
+{