]> git.ozlabs.org Git - ppp.git/blob - pppd/sys-NeXT.c
NetBSD-1.1 files
[ppp.git] / pppd / sys-NeXT.c
1 /*
2  * sys-next.c - System-dependent procedures for setting up
3  * PPP interfaces on NeXT 3.2/3.3  systems
4  *
5  * Copyright (c) 1989 Carnegie Mellon University.
6  * Copyright (c) 1994 Philippe-Andre Prindeville.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms are permitted
10  * provided that the above copyright notice and this paragraph are
11  * duplicated in all such forms and that any documentation,
12  * advertising materials, and other materials related to such
13  * distribution and use acknowledge that the software was developed
14  * by Carnegie Mellon University.  The name of the
15  * University may not be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20  */
21
22 #ifndef lint
23 static char rcsid[] = "$Id: sys-NeXT.c,v 1.2 1995/10/27 03:44:56 paulus Exp $";
24 #endif
25
26 #include <stdio.h>
27 #include <syslog.h>
28 #include <termios.h>
29 #include <utmp.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <strings.h>
33 #include <sys/types.h>
34 #include <sys/file.h>
35 #include <sys/socket.h>
36 #include <sys/ioctl.h>
37 #include <sys/time.h>
38 #include <sys/errno.h>
39 #include <sys/stat.h>
40 #include <sys/fcntl.h>
41
42 #include <net/if.h>
43 #include <net/ppp_defs.h>
44 #include <net/if_ppp.h>
45 #include <netdb.h>
46 #include <netinet/in.h>
47 #include <netinet/in_systm.h>
48 #include <netinet/in_var.h>
49 #include <netinet/ip.h>
50 #include <netinet/if_ether.h>
51 #include <net/route.h>
52 #include <netinet/in.h>
53
54 #include <netinfo/ni.h>
55
56 #include "pppd.h"
57
58 static int initdisc = -1;       /* Initial TTY discipline */
59 static int initfdflags = -1;    /* Initial file descriptor flags for fd */
60
61 extern int errno;
62
63 static int      restore_term;   /* 1 => we've munged the terminal */
64 static struct termios inittermios; /* Initial TTY termios */
65
66 static char *lock_file;
67
68 static int sockfd;              /* socket for doing interface ioctls */
69
70 #if defined(i386) && defined(HAS_BROKEN_IOCTL)
71 #define ioctl   myioctl
72 #endif
73
74 static int if_is_up;            /* the interface is currently up */
75 static u_int32_t default_route_gateway; /* gateway addr for default route */
76 static u_int32_t proxy_arp_addr;        /* remote addr for proxy arp */
77
78 /* Prototypes for procedures local to this file. */
79 static int translate_speed __P((int));
80 static int baud_rate_of __P((int));
81 static int dodefaultroute __P((u_int32_t, int));
82 static int get_ether_addr __P((u_int32_t, struct sockaddr *));
83 static int ether_by_host __P((char *, struct ether_addr *));
84
85
86 /*
87  * sys_init - System-dependent initialization.
88  */
89 void
90 sys_init()
91 {
92     openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP);
93     setlogmask(LOG_UPTO(LOG_INFO));
94     if (debug)
95         setlogmask(LOG_UPTO(LOG_DEBUG));
96
97     /* Get an internet socket for doing socket ioctl's on. */
98     if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
99         syslog(LOG_ERR, "Couldn't create IP socket: %m");
100         die(1);
101     }
102 }
103
104 /*
105  * sys_cleanup - restore any system state we modified before exiting:
106  * mark the interface down, delete default route and/or proxy arp entry.
107  * This should call die() because it's called from die().
108  */
109 void
110 sys_cleanup()
111 {
112     struct ifreq ifr;
113
114     if (if_is_up) {
115         strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
116         if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) >= 0
117             && ((ifr.ifr_flags & IFF_UP) != 0)) {
118             ifr.ifr_flags &= ~IFF_UP;
119             ioctl(sockfd, SIOCSIFFLAGS, &ifr);
120         }
121     }
122
123     if (default_route_gateway)
124         cifdefaultroute(0, default_route_gateway);
125     if (proxy_arp_addr)
126         cifproxyarp(0, proxy_arp_addr);
127 }
128
129 /*
130  * note_debug_level - note a change in the debug level.
131  */
132 void
133 note_debug_level()
134 {
135     if (debug) {
136         syslog(LOG_INFO, "Debug turned ON, Level %d", debug);
137         setlogmask(LOG_UPTO(LOG_DEBUG));
138     } else {
139         setlogmask(LOG_UPTO(LOG_WARNING));
140     }
141 }
142
143 /*
144  * ppp_available - check whether the system has any ppp interfaces
145  * (in fact we check whether we can do an ioctl on ppp0).
146  */
147 int
148 ppp_available()
149 {
150     int s, ok;
151     struct ifreq ifr;
152
153     if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
154         return 1;               /* can't tell - maybe we're not root */
155
156     strncpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name));
157     ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0;
158     close(s);
159
160     return ok;
161 }
162
163 /*
164  * establish_ppp - Turn the serial port into a ppp interface.
165  */
166 void
167 establish_ppp()
168 {
169     int pppdisc = PPPDISC;
170     int x;
171
172     if (ioctl(fd, TIOCGETD, &initdisc) < 0) {
173         syslog(LOG_ERR, "ioctl(TIOCGETD): %m");
174         die(1);
175     }
176     if (ioctl(fd, TIOCSETD, &pppdisc) < 0) {
177         syslog(LOG_ERR, "ioctl(establish TIOCSETD): %m");
178         die(1);
179     }
180
181     /*
182      * Find out which interface we were given.
183      */
184     if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {  
185         syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
186         die(1);
187     }
188
189     /*
190      * Enable debug in the driver if requested.
191      */
192     if (kdebugflag) {
193         if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
194             syslog(LOG_WARNING, "ioctl(PPPIOCGFLAGS): %m");
195         } else {
196             x |= (kdebugflag & 0xFF) * SC_DEBUG;
197             if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
198                 syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
199         }
200     }
201
202     /*
203      * Set device for non-blocking reads.
204      */
205     if ((initfdflags = fcntl(fd, F_GETFL)) == -1
206         || fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
207         syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
208     }
209 }
210
211
212 /*
213  * disestablish_ppp - Restore the serial port to normal operation.
214  * This shouldn't call die() because it's called from die().
215  */
216 void
217 disestablish_ppp()
218 {
219     int x;
220     char *s;
221
222     /* Reset non-blocking mode on the file descriptor. */
223     if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
224         syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
225     initfdflags = -1;
226
227     if (initdisc >= 0) {
228         /*
229          * Check whether the link seems not to be 8-bit clean.
230          */
231         if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) == 0) {
232             s = NULL;
233             switch (~x & (SC_RCV_B7_0|SC_RCV_B7_1|SC_RCV_EVNP|SC_RCV_ODDP)) {
234             case SC_RCV_B7_0:
235                 s = "bit 7 set to 1";
236                 break;
237             case SC_RCV_B7_1:
238                 s = "bit 7 set to 0";
239                 break;
240             case SC_RCV_EVNP:
241                 s = "odd parity";
242                 break;
243             case SC_RCV_ODDP:
244                 s = "even parity";
245                 break;
246             }
247             if (s != NULL) {
248                 syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
249                 syslog(LOG_WARNING, "All received characters had %s", s);
250             }
251         }
252         if (ioctl(fd, TIOCSETD, &initdisc) < 0)
253             syslog(LOG_ERR, "ioctl(disestablish TIOCSETD): %m");
254     }
255 }
256
257 /*
258  * List of valid speeds.
259  */
260 struct speed {
261     int speed_int, speed_val;
262 } speeds[] = {
263 #ifdef B50
264     { 50, B50 },
265 #endif
266 #ifdef B75
267     { 75, B75 },
268 #endif
269 #ifdef B110
270     { 110, B110 },
271 #endif
272 #ifdef B134
273     { 134, B134 },
274 #endif
275 #ifdef B150
276     { 150, B150 },
277 #endif
278 #ifdef B200
279     { 200, B200 },
280 #endif
281 #ifdef B300
282     { 300, B300 },
283 #endif
284 #ifdef B600
285     { 600, B600 },
286 #endif
287 #ifdef B1200
288     { 1200, B1200 },
289 #endif
290 #ifdef B1800
291     { 1800, B1800 },
292 #endif
293 #ifdef B2000
294     { 2000, B2000 },
295 #endif
296 #ifdef B2400
297     { 2400, B2400 },
298 #endif
299 #ifdef B3600
300     { 3600, B3600 },
301 #endif
302 #ifdef B4800
303     { 4800, B4800 },
304 #endif
305 #ifdef B7200
306     { 7200, B7200 },
307 #endif
308 #ifdef B9600
309     { 9600, B9600 },
310 #endif
311 #ifdef B19200
312     { 19200, B19200 },
313 #endif
314 #ifdef B38400
315     { 38400, B38400 },
316 #endif
317 #ifdef EXTA
318     { 19200, EXTA },
319 #endif
320 #ifdef EXTB
321     { 38400, EXTB },
322 #endif
323 #ifdef B14400
324     { 14400, B14400 },
325 #endif
326 #ifdef B28800
327     { 28800, B28800 },
328 #endif
329 #ifdef B43200
330     { 43200, B43200 },
331 #endif
332 #ifdef B57600
333     { 57600, B57600 },
334 #endif
335 #ifdef B115200
336     { 115200, B115200 },
337 #endif
338     { 0, 0 }
339 };
340
341 /*
342  * Translate from bits/second to a speed_t.
343  */
344 int
345 translate_speed(bps)
346     int bps;
347 {
348     struct speed *speedp;
349
350     if (bps == 0)
351         return 0;
352     for (speedp = speeds; speedp->speed_int; speedp++)
353         if (bps == speedp->speed_int)
354             return speedp->speed_val;
355     syslog(LOG_WARNING, "speed %d not supported", bps);
356     return 0;
357 }
358
359 /*
360  * Translate from a speed_t to bits/second.
361  */
362 static int
363 baud_rate_of(speed)
364     int speed;
365 {
366     struct speed *speedp;
367
368     if (speed == 0)
369         return 0;
370     for (speedp = speeds; speedp->speed_int; speedp++)
371         if (speed == speedp->speed_val)
372             return speedp->speed_int;
373     return 0;
374 }
375
376
377 /*
378  * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity,
379  * at the requested speed, etc.  If `local' is true, set CLOCAL
380  * regardless of whether the modem option was specified.
381  */
382 void
383 set_up_tty(fd, local)
384     int fd, local;
385 {
386     int speed, x, modembits;
387     struct termios tios;
388
389     if (tcgetattr(fd, &tios) < 0) {
390         syslog(LOG_ERR, "tcgetattr: %m");
391         die(1);
392     }
393
394     if (!restore_term)
395         inittermios = tios;
396
397     tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
398
399     tios.c_cflag |= CS8 | CREAD | HUPCL;
400     if (local || !modem)
401         tios.c_cflag |= CLOCAL;
402     tios.c_iflag = IGNBRK | IGNPAR;
403     tios.c_oflag = 0;
404     tios.c_lflag = 0;
405     tios.c_cc[VMIN] = 1;
406     tios.c_cc[VTIME] = 0;
407
408     if (crtscts == -2) {
409         tios.c_iflag |= IXON | IXOFF;
410         tios.c_cc[VSTOP] = 0x13;        /* DC3 = XOFF = ^S */
411         tios.c_cc[VSTART] = 0x11;       /* DC1 = XON  = ^Q */
412     }
413
414     speed = translate_speed(inspeed);
415     if (speed) {
416         cfsetospeed(&tios, speed);
417         cfsetispeed(&tios, speed);
418     } else {
419         speed = cfgetospeed(&tios);
420     }
421
422     if (modem) {
423       modembits = TIOCM_RTS | TIOCM_CTS;
424       if (ioctl(fd, (crtscts ? TIOCMBIS : TIOCMBIC), &modembits) < 0)
425         syslog(LOG_ERR, "ioctl: TIOCMBIS/BIC: %m");
426     }
427
428     if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
429         syslog(LOG_ERR, "tcsetattr: %m");
430         die(1);
431     }
432
433    baud_rate = inspeed = baud_rate_of(speed);
434    restore_term = 1;
435 }
436
437 /*
438  * restore_tty - restore the terminal to the saved settings.
439  */
440 void
441 restore_tty()
442 {
443     if (restore_term) {
444         if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
445             if (errno != ENXIO)
446                 syslog(LOG_WARNING, "tcsetattr: %m");
447         restore_term = 0;
448     }
449 }
450
451 /*
452  * setdtr - control the DTR line on the serial port.
453  * This is called from die(), so it shouldn't call die().
454  *
455  * The write hack is to get NXFax to recognize that there is
456  * activity on the port.  Not using the write nukes
457  * NXFax's capability to determine port usage.
458  *
459  */
460 void
461 setdtr(fd, on)
462 int fd, on;
463 {
464     int modembits = TIOCM_DTR;
465
466     if (!on)
467       {
468         write(fd, " ", 1);
469         sleep(1);
470       }
471
472 /*    ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits); */
473     ioctl(fd, (on? TIOCSDTR: TIOCCDTR), 0);
474 }
475
476
477 /*
478  * output - Output PPP packet.
479  */
480 void
481 output(unit, p, len)
482     int unit;
483     u_char *p;
484     int len;
485 {
486     if (debug)
487         log_packet(p, len, "sent ");
488
489     if (write(fd, p, len) < 0) {
490         if (errno == EWOULDBLOCK || errno == ENOBUFS
491             || errno == ENXIO || errno == EIO) {
492             syslog(LOG_WARNING, "write: warning: %m");
493         } else {
494             syslog(LOG_ERR, "write: %m");
495             die(1);
496         }
497     }
498 }
499
500
501 /*
502  * wait_input - wait until there is data available on fd,
503  * for the length of time specified by *timo (indefinite
504  * if timo is NULL).
505  */
506 void
507 wait_input(timo)
508     struct timeval *timo;
509 {
510     fd_set ready;
511     int n;
512
513     FD_ZERO(&ready);
514     FD_SET(fd, &ready);
515     n = select(fd+1, &ready, NULL, &ready, timo);
516     if (n < 0 && errno != EINTR) {
517         syslog(LOG_ERR, "select: %m");
518         die(1);
519     }
520 }
521
522
523 /*
524  * read_packet - get a PPP packet from the serial device.
525  */
526 int
527 read_packet(buf)
528     u_char *buf;
529 {
530     int len;
531
532     if ((len = read(fd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
533         if (errno == EWOULDBLOCK || errno == EINTR) {
534             MAINDEBUG((LOG_DEBUG, "read(fd): %m"));
535             return -1;
536         }
537         syslog(LOG_ERR, "read(fd): %m");
538         die(1);
539     }
540     return len;
541 }
542
543
544 /*
545  * ppp_send_config - configure the transmit characteristics of
546  * the ppp interface.
547  */
548 void
549 ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
550     int unit, mtu;
551     u_int32_t asyncmap;
552     int pcomp, accomp;
553 {
554     u_int x;
555     struct ifreq ifr;
556
557     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
558     ifr.ifr_mtu = mtu;
559     if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
560         syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
561         quit();
562     }
563
564     if (ioctl(fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) {
565         syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m");
566         quit();
567     }
568
569     if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
570         syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
571         quit();
572     }
573     x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
574     x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
575     if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
576         syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
577         quit();
578     }
579 }
580
581
582 /*
583  * ppp_set_xaccm - set the extended transmit ACCM for the interface.
584  */
585 void
586 ppp_set_xaccm(unit, accm)
587     int unit;
588     ext_accm accm;
589 {
590     if (ioctl(fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
591         syslog(LOG_WARNING, "ioctl(PPPIOCSXASYNCMAP): %m");
592 }
593
594
595 /*
596  * ppp_recv_config - configure the receive-side characteristics of
597  * the ppp interface.
598  */
599 void
600 ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
601     int unit, mru;
602     u_int32_t asyncmap;
603     int pcomp, accomp;
604 {
605     int x;
606
607     if (ioctl(fd, PPPIOCSMRU, (caddr_t) &mru) < 0) {
608         syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m");
609         quit();
610     }
611     if (ioctl(fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) {
612         syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m");
613         quit();
614     }
615     if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
616         syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
617         quit();
618     }
619     x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
620     if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
621         syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
622         quit();
623     }
624 }
625
626 /*
627  * ccp_test - ask kernel whether a given compression method
628  * is acceptable for use.
629  */
630 int
631 ccp_test(unit, opt_ptr, opt_len, for_transmit)
632     int unit, opt_len, for_transmit;
633     u_char *opt_ptr;
634 {
635     struct ppp_option_data data;
636
637     data.ptr = opt_ptr;
638     data.length = opt_len;
639     data.transmit = for_transmit;
640     if (ioctl(fd, PPPIOCSCOMPRESS, (caddr_t) &data) >= 0)
641         return 1;
642     return (errno == ENOBUFS)? 0: -1;
643 }
644
645 /*
646  * ccp_flags_set - inform kernel about the current state of CCP.
647  */
648 void
649 ccp_flags_set(unit, isopen, isup)
650     int unit, isopen, isup;
651 {
652     int x;
653
654     if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
655         syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
656         return;
657     }
658     x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
659     x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
660     if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
661         syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
662 }
663
664 /*
665  * ccp_fatal_error - returns 1 if decompression was disabled as a
666  * result of an error detected after decompression of a packet,
667  * 0 otherwise.  This is necessary because of patent nonsense.
668  */
669 int
670 ccp_fatal_error(unit)
671     int unit;
672 {
673     int x;
674
675     if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
676         syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
677         return 0;
678     }
679     return x & SC_DC_FERROR;
680 }
681
682 /*
683  * sifvjcomp - config tcp header compression
684  */
685 int
686 sifvjcomp(u, vjcomp, cidcomp, maxcid)
687     int u, vjcomp, cidcomp, maxcid;
688 {
689     u_int x;
690
691     if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
692         syslog(LOG_ERR, "ioctl(PPIOCGFLAGS): %m");
693         return 0;
694     }
695     x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP;
696     x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
697     if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
698         syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
699         return 0;
700     }
701     if (ioctl(fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
702         syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
703         return 0;
704     }
705     return 1;
706 }
707
708 /*
709  * sifup - Config the interface up and enable IP packets to pass.
710  */
711 #ifndef SC_ENABLE_IP
712 #define SC_ENABLE_IP    0x100   /* compat for old versions of kernel code */
713 #endif
714
715 int
716 sifup(u)
717     int u;
718 {
719     struct ifreq ifr;
720     u_int x;
721     struct npioctl npi;
722
723     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
724     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
725         syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
726         return 0;
727     }
728     ifr.ifr_flags |= IFF_UP;
729     if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
730         syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
731         return 0;
732     }
733     if_is_up = 1;
734     npi.protocol = PPP_IP;
735     npi.mode = NPMODE_PASS;
736     if (ioctl(fd, PPPIOCSNPMODE, &npi) < 0) {
737         if (errno != ENOTTY) {
738             syslog(LOG_ERR, "ioctl(PPPIOCSNPMODE): %m");
739             return 0;
740         }
741         /* for backwards compatibility */
742         if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
743             syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
744             return 0;
745         }
746         x |= SC_ENABLE_IP;
747         if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
748             syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
749             return 0;
750         }
751     }
752     return 1;
753 }
754
755 /*
756  * sifdown - Config the interface down and disable IP.
757  */
758 int
759 sifdown(u)
760     int u;
761 {
762     struct ifreq ifr;
763     u_int x;
764     int rv;
765     struct npioctl npi;
766
767     rv = 1;
768     npi.protocol = PPP_IP;
769     npi.mode = NPMODE_ERROR;
770     if (ioctl(fd, PPPIOCSNPMODE, (caddr_t) &npi) < 0) {
771         if (errno != ENOTTY) {
772             syslog(LOG_ERR, "ioctl(PPPIOCSNPMODE): %m");
773             rv = 0;
774         } else {
775             /* backwards compatibility */
776             if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
777                 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
778                 rv = 0;
779             } else {
780                 x &= ~SC_ENABLE_IP;
781                 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
782                     syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
783                     rv = 0;
784                 }
785             }
786         }
787     }
788
789     strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
790     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
791         syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
792         rv = 0;
793     } else {
794         ifr.ifr_flags &= ~IFF_UP;
795         if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
796             syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
797             rv = 0;
798         } else
799             if_is_up = 0;
800     }
801     return rv;
802 }
803
804 /*
805  * SET_SA_FAMILY - set the sa_family field of a struct sockaddr,
806  * if it exists.
807  */
808 #define SET_SA_FAMILY(addr, family)             \
809     BZERO((char *) &(addr), sizeof(addr));      \
810     addr.sa_family = (family); 
811
812 /*
813  * sifaddr - Config the interface IP addresses and netmask.
814  */
815 int
816 sifaddr(u, o, h, m)
817     int u;
818     u_int32_t o, h, m;
819 {
820     int ret;
821     struct ifreq ifr;
822
823     ret = 1;
824     strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
825     SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
826     ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
827     if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
828         syslog(LOG_ERR, "ioctl(SIOCAIFADDR): %m");
829         ret = 0;
830     }
831     ((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h;
832     if (ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
833         syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
834         ret = 0;
835     }
836     if (m != 0) {
837         ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
838         syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
839         if (ioctl(sockfd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
840             syslog(LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
841             ret = 0;
842         }
843     }
844     return ret;
845 }
846
847 /*
848  * cifaddr - Clear the interface IP addresses, and delete routes
849  * through the interface if possible.
850  *
851  * N.B.: under NextStep, you can't *delete* an address on an interface,
852  * so we change it to 0.0.0.0...  A real hack.  But it simplifies
853  * reconnection on the server side.
854  */
855 int
856 cifaddr(u, o, h)
857     int u;
858     u_int32_t o, h;
859 {
860     struct rtentry rt;
861
862 #if 1
863     h = o = 0L;
864     (void) sifaddr(u, o, h, 0L);
865 #endif
866     SET_SA_FAMILY(rt.rt_dst, AF_INET);
867     ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = h;
868     SET_SA_FAMILY(rt.rt_gateway, AF_INET);
869     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o;
870     rt.rt_flags = RTF_HOST;
871     if (ioctl(sockfd, SIOCDELRT, (caddr_t) &rt) < 0) {
872         syslog(LOG_ERR, "ioctl(SIOCDELRT): %m");
873         return 0;
874     }
875     return 1;
876 }
877
878 /*
879  * sifdefaultroute - assign a default route through the address given.
880  */
881 int
882 sifdefaultroute(u, g)
883     int u;
884     u_int32_t g;
885 {
886     return dodefaultroute(g, 's');
887 }
888
889 /*
890  * cifdefaultroute - delete a default route through the address given.
891  */
892 int
893 cifdefaultroute(u, g)
894     int u;
895     u_int32_t g;
896 {
897     return dodefaultroute(g, 'c');
898 }
899
900 /*
901  * dodefaultroute - talk to a routing socket to add/delete a default route.
902  */
903 int
904 dodefaultroute(g, cmd)
905     u_int32_t g;
906     int cmd;
907 {
908     struct rtentry rt;
909
910     SET_SA_FAMILY(rt.rt_dst, AF_INET);
911     ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = 0L;
912     SET_SA_FAMILY(rt.rt_gateway, AF_INET);
913     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
914     rt.rt_flags = RTF_GATEWAY;
915     if (ioctl(sockfd, (cmd == 's') ? SIOCADDRT : SIOCDELRT, &rt) < 0) {
916         syslog(LOG_ERR, "%cifdefaultroute: ioctl(%s): %m", cmd,
917                (cmd == 's') ? "SIOCADDRT" : "SIOCDELRT");
918         return 0;
919     }
920     default_route_gateway = (cmd == 's')? g: 0;
921     return 1;
922 }
923
924 /*
925  * sifproxyarp - Make a proxy ARP entry for the peer.
926  */
927 int
928 sifproxyarp(unit, hisaddr)
929     int unit;
930     u_int32_t hisaddr;
931 {
932     struct arpreq arpreq;
933
934     BZERO(&arpreq, sizeof(arpreq));
935
936     /*
937      * Get the hardware address of an interface on the same subnet
938      * as our local address.
939      */
940     if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
941         syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
942         return 0;
943     }
944
945     SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
946     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
947     arpreq.arp_flags = ATF_PERM | ATF_PUBL;
948     if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
949         syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
950         return 0;
951     }
952
953     proxy_arp_addr = hisaddr;
954     return 1;
955 }
956
957 /*
958  * cifproxyarp - Delete the proxy ARP entry for the peer.
959  */
960 int
961 cifproxyarp(unit, hisaddr)
962     int unit;
963     u_int32_t hisaddr;
964 {
965     struct arpreq arpreq;
966
967     BZERO(&arpreq, sizeof(arpreq));
968     SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
969     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
970     if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
971         syslog(LOG_WARNING, "ioctl(SIOCDARP): %m");
972         return 0;
973     }
974     proxy_arp_addr = 0;
975     return 1;
976 }
977
978 /*
979  * get_ether_addr - get the hardware address of an interface on the
980  * the same subnet as ipaddr.
981  */
982 #define MAX_IFS         32
983
984 int
985 get_ether_addr(ipaddr, hwaddr)
986     u_int32_t ipaddr;
987     struct sockaddr *hwaddr;
988 {
989     struct ifreq *ifr, *ifend, *ifp;
990     u_int32_t ina, mask;
991     struct ether_addr dla;
992     struct ifreq ifreq;
993     struct ifconf ifc;
994     struct ifreq ifs[MAX_IFS];
995     struct hostent *hostent;
996
997     ifc.ifc_len = sizeof(ifs);
998     ifc.ifc_req = ifs;
999     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
1000         syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
1001         return 0;
1002     }
1003
1004     /*
1005      * Scan through looking for an interface with an Internet
1006      * address on the same subnet as `ipaddr'.
1007      */
1008     ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
1009     for (ifr = ifc.ifc_req; ifr < ifend; ifr = (struct ifreq *)
1010                 ((char *)&ifr->ifr_addr + sizeof(struct sockaddr))) {
1011         if (ifr->ifr_addr.sa_family == AF_INET) {
1012             ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
1013             strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
1014             /*
1015              * Check that the interface is up, and not point-to-point
1016              * or loopback.
1017              */
1018             if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
1019                 continue;
1020             if ((ifreq.ifr_flags &
1021                  (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK|IFF_NOARP))
1022                  != (IFF_UP|IFF_BROADCAST))
1023                 continue;
1024             /*
1025              * Get its netmask and check that it's on the right subnet.
1026              */
1027             if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
1028                 continue;
1029             mask = ((struct sockaddr_in*)&ifreq.ifr_addr)->sin_addr.s_addr;
1030             if ((ipaddr & mask) != (ina & mask))
1031                 continue;
1032
1033             break;
1034         }
1035     }
1036
1037     if (ifr >= ifend)
1038         return 0;
1039     syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
1040
1041     /*
1042      * Get the hostname and look for an entry using the ethers database.
1043      * Under NeXTStep this is the best we can do for now.
1044      */
1045     if ((hostent = gethostbyaddr((char*)&ina, sizeof(ina), AF_INET)) == NULL)
1046         return 0;
1047
1048     if (ether_by_host(hostent->h_name, &dla)) {
1049         syslog(LOG_INFO, "Add entry for %s in /etc/ethers", hostent->h_name);
1050         return 0;       /* it's not there */
1051     }
1052     hwaddr->sa_family = AF_UNSPEC;
1053     BCOPY(&dla, hwaddr->sa_data, sizeof(dla));
1054     return 1;
1055 }
1056
1057 static int
1058 ether_by_host(hostname, etherptr)
1059     char *hostname;
1060     struct ether_addr *etherptr;
1061 {
1062     struct ether_addr *thisptr;
1063     void *conn;
1064     ni_id root;
1065     ni_namelist val;
1066     char path[256];
1067
1068     if (!ether_hostton(hostname, etherptr))
1069         return 0;
1070     /*
1071      * We shall now try and
1072      * find the address in the
1073      * top domain of netinfo.
1074      */
1075     strcat(strcpy(path, "/machines/"), hostname);
1076
1077     if (ni_open((void *)0, "/", &conn)
1078      || ni_root(conn, &root)
1079      || ni_pathsearch(conn, &root, path)
1080      || ni_lookupprop(conn, &root, "en_address", &val))
1081         return 1;
1082
1083     /*
1084      * Now we can convert the returned string into an ethernet address.
1085      */
1086     strcpy(path, val.ni_namelist_val[0]);
1087     ni_free(conn);
1088     if ((thisptr = (struct ether_addr*)ether_aton(path)) == NULL)
1089         return 1;
1090     BCOPY(thisptr, etherptr, sizeof(struct ether_addr));
1091     return 0;
1092 }
1093
1094
1095
1096 /*
1097  * Return user specified netmask, modified by any mask we might determine
1098  * for address `addr' (in network byte order).
1099  * Here we scan through the system's list of interfaces, looking for
1100  * any non-point-to-point interfaces which might appear to be on the same
1101  * network as `addr'.  If we find any, we OR in their netmask to the
1102  * user-specified netmask.
1103  */
1104 u_int32_t
1105 GetMask(addr)
1106     u_int32_t addr;
1107 {
1108     u_int32_t mask, nmask, ina;
1109     struct ifreq *ifr, *ifend, ifreq;
1110     struct ifconf ifc;
1111     struct ifreq ifs[MAX_IFS];
1112
1113     addr = ntohl(addr);
1114     if (IN_CLASSA(addr))        /* determine network mask for address class */
1115         nmask = IN_CLASSA_NET;
1116     else if (IN_CLASSB(addr))
1117         nmask = IN_CLASSB_NET;
1118     else
1119         nmask = IN_CLASSC_NET;
1120     /* class D nets are disallowed by bad_ip_adrs */
1121     mask = netmask | htonl(nmask);
1122
1123     /*
1124      * Scan through the system's network interfaces.
1125      */
1126     ifc.ifc_len = sizeof(ifs);
1127     ifc.ifc_req = ifs;
1128     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
1129         syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
1130         return mask;
1131     }
1132     ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
1133     for (ifr = ifc.ifc_req; ifr < ifend; ifr = (struct ifreq *)
1134                 ((char *)&ifr->ifr_addr + sizeof(struct sockaddr))) {
1135         /*
1136          * Check the interface's internet address.
1137          */
1138         if (ifr->ifr_addr.sa_family != AF_INET)
1139             continue;
1140         ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
1141         if ((ntohl(ina) & nmask) != (addr & nmask))
1142             continue;
1143         /*
1144          * Check that the interface is up, and not point-to-point or loopback.
1145          */
1146         strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
1147         if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
1148             continue;
1149         if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))
1150             != IFF_UP)
1151             continue;
1152         /*
1153          * Get its netmask and OR it into our mask.
1154          */
1155         if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
1156             continue;
1157         mask |= ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr;
1158     }
1159
1160     return mask;
1161 }
1162
1163
1164
1165 /*
1166  * daemon - Detach us from the terminal session.
1167  */
1168 int
1169 daemon(nochdir, noclose)
1170     int nochdir, noclose;
1171 {
1172     int pid;
1173
1174     if ((pid = fork()) < 0)
1175         return -1;
1176     if (pid != 0)
1177         exit(0);                /* parent dies */
1178     (void)setsid();
1179     if (!nochdir)
1180         chdir("/");
1181     if (!noclose) {
1182         fclose(stdin);          /* don't need stdin, stdout, stderr */
1183         fclose(stdout);
1184         fclose(stderr);
1185     }
1186     return 0;
1187 }
1188
1189
1190 char *
1191 strdup(s)
1192     const char *s;
1193 {
1194     char *d = malloc(strlen(s) + 1);
1195
1196     if (d) strcpy(d, s);
1197     return d;
1198 }
1199
1200 /*
1201  * This logwtmp() implementation is subject to the following copyright:
1202  *
1203  * Copyright (c) 1988 The Regents of the University of California.
1204  * All rights reserved.
1205  *
1206  * Redistribution and use in source and binary forms are permitted
1207  * provided that the above copyright notice and this paragraph are
1208  * duplicated in all such forms and that any documentation,
1209  * advertising materials, and other materials related to such
1210  * distribution and use acknowledge that the software was developed
1211  * by the University of California, Berkeley.  The name of the
1212  * University may not be used to endorse or promote products derived
1213  * from this software without specific prior written permission.
1214  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1215  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1216  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1217  */
1218
1219 #define WTMPFILE        "/usr/adm/wtmp"
1220
1221 int
1222 logwtmp(line, name, host)
1223     char *line, *name, *host;
1224 {
1225     int fd;
1226     struct stat buf;
1227     struct utmp ut;
1228
1229     if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
1230         return;
1231     if (!fstat(fd, &buf)) {
1232         (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
1233         (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
1234         (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
1235         (void)time(&ut.ut_time);
1236         if (write(fd, (char *)&ut, sizeof(struct utmp)) != sizeof(struct utmp))
1237             (void)ftruncate(fd, buf.st_size);
1238     }
1239     close(fd);
1240 }
1241
1242 /*
1243  * Routines for locking and unlocking the serial device, moved here
1244  * from chat.c.
1245  */
1246
1247 #define LOCK_PREFIX     "/usr/spool/uucp/LCK/LCK.."
1248
1249 /*
1250  * lock - create a lock file for the named device
1251  */
1252 int
1253 lock(dev)
1254     char *dev;
1255 {
1256     int fd, pid, n;
1257     char *p;
1258
1259     if ((p = strrchr(dev, '/')) != NULL)
1260         dev = p + 1;
1261     lock_file = malloc(strlen(LOCK_PREFIX) + strlen(dev) + 1);
1262     if (lock_file == NULL)
1263         novm("lock file name");
1264     strcat(strcpy(lock_file, LOCK_PREFIX), dev);
1265
1266     while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) {
1267         if (errno == EEXIST
1268             && (fd = open(lock_file, O_RDONLY, 0)) >= 0) {
1269             /* Read the lock file to find out who has the device locked */
1270             n = read(fd, &pid, sizeof(pid));
1271             if (n <= 0) {
1272                 syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
1273                 close(fd);
1274             } else {
1275                 if (kill(pid, 0) == -1 && errno == ESRCH) {
1276                     /* pid no longer exists - remove the lock file */
1277                     if (unlink(lock_file) == 0) {
1278                         close(fd);
1279                         syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
1280                                dev, pid);
1281                         continue;
1282                     } else
1283                         syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
1284                                dev);
1285                 } else
1286                     syslog(LOG_NOTICE, "Device %s is locked by pid %d",
1287                            dev, pid);
1288             }
1289             close(fd);
1290         } else
1291             syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
1292         free(lock_file);
1293         lock_file = NULL;
1294         return -1;
1295     }
1296
1297     pid = getpid();
1298     write(fd, &pid, sizeof pid);
1299
1300     close(fd);
1301     return 0;
1302 }
1303
1304 /*
1305  * unlock - remove our lockfile
1306  */
1307 void
1308 unlock()
1309 {
1310     if (lock_file) {
1311         unlink(lock_file);
1312         free(lock_file);
1313         lock_file = NULL;
1314     }
1315 }
1316
1317 #if defined(i386) && defined(HAS_BROKEN_IOCTL)
1318 int
1319 ioctl(fd, cmd, c)
1320     int fd, cmd;
1321     caddr_t c;
1322 {
1323 #undef  ioctl
1324     int ret;
1325
1326 #ifdef DEBUGIOCTL
1327     int serrno;
1328     u_char let, code, size;
1329
1330     size = (cmd >> 16) & IOCPARM_MASK;
1331     let = (cmd >> 8);
1332     code = cmd;
1333
1334     if (let == 't' && (75 <= code && code <= 90))
1335     syslog(LOG_INFO, "ioctl(%d, 0x%x ('%c', %d, %d), 0x%x)\n", fd, cmd,
1336            let, code, size, c);
1337 #endif
1338
1339     ret = ioctl(fd, cmd, c);
1340
1341 #ifdef DEBUGIOCTL
1342     serrno = errno;
1343     if (ret == -1)
1344         syslog(LOG_INFO, "ioctl('%c', %d, %d) errno = %d (%m)\n",
1345                 let, code, size, errno);
1346     if (let == 't' && (75 <= code && code <= 90) && (cmd & IOC_OUT)) {
1347         int i, len = ((cmd >> 16) & IOCPARM_MASK);
1348         for (i = 0; i < len / 4; ++i)
1349                 syslog(LOG_INFO, "word[%d] @ 0x%06x = 0x%x\n",
1350                        i, &((int *) c)[i],((int *)c)[i]);
1351     }
1352     errno = serrno;
1353 #endif
1354
1355     if (ret == -1 && errno == EPERM)
1356         errno = ret = 0;
1357     return ret;
1358 }
1359 #endif  /* HAS_BROKEN_IOCTL */
1360
1361
1362 #if defined(FIXSIGS) && (defined (hppa) || defined(sparc))
1363
1364 /*
1365  * These redefinitions of Posix functions are necessary
1366  * because HPPA systems have an OS bug that causes 
1367  * sigaction to core dump:
1368  *
1369  * AlainF 9-Nov-1994    HACK FOR HP-PA/NEXTSTEP
1370  *                      sigaction(3) seems broken in the HP-PA NeXTSTEP 3.2
1371  *                      Posix lib. This causes pppd to SIGBUS at the expiration
1372  *                      of the first timeout (_sigtramp seems to invoke
1373  *                      the SIGALRM handler at an unreasonably low address).
1374  *                      All calls so sigaction(3) have been changed to calls
1375  *                      to sigvec(2) and sigprocmask(SIG_BLOCK,...) to
1376  *                      sigblock(2).
1377  *                      This is kind of a hack, especially since there are
1378  *                      other routines of the Posix lib still used, but
1379  *                      it worked for me.
1380  *
1381  * Dave Hess <David-Hess@net.tamu.edu> noted that 3.3 Sparc seems to
1382  * have the same bug.  Thus this fix has been enabled for SPARC also.
1383  *
1384  *
1385  */
1386
1387 int sigemptyset(sigset_t *mask)
1388 {
1389   *mask = 0;
1390 }
1391
1392 sigaddset(sigset_t *mask, int which_sig)
1393 {
1394   *mask |= sigmask(which_sig);
1395 }
1396
1397
1398 int sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
1399 {
1400    struct sigvec sv;
1401    static int in = 0;
1402
1403    sv.sv_handler = act->sa_handler;
1404    sv.sv_mask = act->sa_mask;
1405    sv.sv_flags = 0;
1406
1407    if (!in)
1408      {
1409        in = 1;
1410        syslog(LOG_WARNING, "PPPD: Inside modified HP and SPARC sigaction\n");
1411      }
1412
1413    return sigvec(sig, &sv, NULL);
1414 }
1415
1416 #endif