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