*/
#ifndef lint
-static char rcsid[] = "$Id: sys-svr4.c,v 1.2 1995/06/01 01:31:28 paulus Exp $";
+static char rcsid[] = "$Id: sys-svr4.c,v 1.4 1995/08/10 06:53:39 paulus Exp $";
#endif
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
+#include <signal.h>
#include <sys/types.h>
#include <sys/ioccom.h>
#include <sys/stream.h>
static int restore_term;
static struct termios inittermios;
+static pid_t tty_sid; /* original session ID for terminal */
static int link_mtu, link_mru;
void
establish_ppp()
{
- int i;
+ int i, ifd;
+
+ if (default_device)
+ tty_sid = getsid((pid_t)0);
pppfd = open("/dev/ppp", O_RDWR | O_NONBLOCK, 0);
if (pppfd < 0) {
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 (ioctl(ifd, I_PUSH, "ip") < 0) {
+ syslog(LOG_ERR, "Can't push IP module: %m");
+ close(ifd);
+ die(1);
+ }
+ ipmuxid = ioctl(ipfd, I_LINK, ifd);
+ close(ifd);
+ if (ipmuxid < 0) {
+ syslog(LOG_ERR, "Can't link PPP device to IP: %m");
+ die(1);
+ }
+
/* Pop any existing modules off the tty stream. */
for (i = 0;; ++i)
if (ioctl(fd, I_LOOK, tty_modules[i]) < 0
syslog(LOG_ERR, "Couldn't restore tty module %s: %m",
tty_modules[i]);
}
+ if (hungup && default_device && tty_sid > 0) {
+ /*
+ * If we have received a hangup, we need to send a SIGHUP
+ * to the terminal's controlling process. The reason is
+ * that the original stream head for the terminal hasn't
+ * seen the M_HANGUP message (it went up through the ppp
+ * driver to the stream head for our fd to /dev/ppp).
+ */
+ kill(tty_sid, SIGHUP);
+ }
}
}
{
struct ifreq ifr;
- if (ipmuxid < 0) {
- syslog(LOG_DEBUG, "sifup: not plumbed!");
- return 0;
- }
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) {
syslog(LOG_ERR, "Couldn't mark interface up (get): %m");
int u;
u_int32_t o, h, m;
{
- int fd;
struct ifreq ifr;
- fd = open("/dev/ppp", O_RDWR, 0);
- if (fd < 0) {
- syslog(LOG_ERR, "Can't open /dev/ppp (2): %m");
- die(1);
- }
- if (ioctl(fd, I_PUSH, "ip") < 0) {
- syslog(LOG_ERR, "Can't push IP module: %m");
- close(fd);
- return 0;
- }
- ipmuxid = ioctl(ipfd, I_LINK, fd);
- close(fd);
- if (ipmuxid < 0) {
- syslog(LOG_ERR, "Can't link PPP device to IP: %m");
- return 0;
- }
-
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
ifr.ifr_addr.sa_family = AF_INET;
int u;
u_int32_t o, h;
{
+#if 0
if (ipmuxid >= 0) {
if (ioctl(ipfd, I_UNLINK, ipmuxid) < 0) {
syslog(LOG_ERR, "Can't remove ppp interface unit: %m");
}
ipmuxid = -1;
}
+#endif
return 1;
}
syslog(LOG_ERR, "sysinfo: %m");
return 0;
}
- return strtol(buf, NULL, 16);
+ return (int) strtoul(buf, NULL, 16);
}
int