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