2 * System-dependent procedures for pppd under Solaris 2.
4 * Copyright (c) 1994 The Australian National University.
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation is hereby granted, provided that the above copyright
9 * notice appears in all copies. This software is provided without any
10 * warranty, express or implied. The Australian National University
11 * makes no representations about the suitability of this software for
14 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
15 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
17 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
20 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
21 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
24 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
29 static char rcsid[] = "$Id: sys-svr4.c,v 1.3 1995/06/23 01:54:11 paulus Exp $";
40 #include <sys/types.h>
41 #include <sys/ioccom.h>
42 #include <sys/stream.h>
43 #include <sys/stropts.h>
44 #include <sys/socket.h>
45 #include <sys/sockio.h>
46 #include <sys/syslog.h>
47 #include <sys/systeminfo.h>
51 #include <net/if_arp.h>
52 #include <net/route.h>
53 #include <net/ppp_defs.h>
54 #include <net/pppio.h>
55 #include <netinet/in.h>
60 static int fdmuxid = -1;
62 static int ipmuxid = -1;
64 static int restore_term;
65 static struct termios inittermios;
67 static int link_mtu, link_mru;
70 static int tty_nmodules;
71 static char tty_modules[NMODULES][FMNAMESZ+1];
74 * sys_init - System-dependent initialization.
79 openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP);
80 setlogmask(LOG_UPTO(LOG_INFO));
82 setlogmask(LOG_UPTO(LOG_DEBUG));
84 ipfd = open("/dev/ip", O_RDWR, 0);
86 syslog(LOG_ERR, "Couldn't open IP device: %m");
92 * daemon - Detach us from controlling terminal session.
95 daemon(nochdir, noclose)
100 if ((pid = fork()) < 0)
103 exit(0); /* parent dies */
108 fclose(stdin); /* don't need stdin, stdout, stderr */
116 * note_debug_level - note a change in the debug level.
122 syslog(LOG_INFO, "Debug turned ON, Level %d", debug);
123 setlogmask(LOG_UPTO(LOG_DEBUG));
125 setlogmask(LOG_UPTO(LOG_WARNING));
130 * ppp_available - check whether the system has any ppp interfaces
137 return stat("/dev/ppp", &buf) >= 0;
141 * establish_ppp - Turn the serial port into a ppp interface.
148 pppfd = open("/dev/ppp", O_RDWR | O_NONBLOCK, 0);
150 syslog(LOG_ERR, "Can't open /dev/ppp: %m");
154 /* Assign a new PPA and get its unit number. */
155 if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0) {
156 syslog(LOG_ERR, "Can't create new PPP interface: %m");
161 * Open the ppp device again and link it under the ip multiplexor.
162 * IP will assign a unit number which hopefully is the same as ifunit.
163 * I don't know any way to be certain they will be the same. :-(
165 ifd = open("/dev/ppp", O_RDWR, 0);
167 syslog(LOG_ERR, "Can't open /dev/ppp (2): %m");
170 if (ioctl(ifd, I_PUSH, "ip") < 0) {
171 syslog(LOG_ERR, "Can't push IP module: %m");
175 ipmuxid = ioctl(ipfd, I_LINK, ifd);
178 syslog(LOG_ERR, "Can't link PPP device to IP: %m");
182 /* Pop any existing modules off the tty stream. */
184 if (ioctl(fd, I_LOOK, tty_modules[i]) < 0
185 || ioctl(fd, I_POP, 0) < 0)
189 /* Push the async hdlc module and the compressor module. */
190 if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0) {
191 syslog(LOG_ERR, "Couldn't push PPP Async HDLC module: %m");
194 if (ioctl(fd, I_PUSH, "ppp_comp") < 0) {
195 syslog(LOG_ERR, "Couldn't push PPP compression module: %m");
199 /* Link the serial port under the PPP multiplexor. */
200 if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) {
201 syslog(LOG_ERR, "Can't link tty to PPP mux: %m");
207 * disestablish_ppp - Restore the serial port to normal operation.
208 * This shouldn't call die() because it's called from die().
216 if (ioctl(pppfd, I_UNLINK, fdmuxid) < 0) {
218 syslog(LOG_ERR, "Can't unlink tty from PPP mux: %m");
223 while (ioctl(fd, I_POP, 0) >= 0)
225 for (i = tty_nmodules - 1; i >= 0; --i)
226 if (ioctl(fd, I_PUSH, tty_modules[i]) < 0)
227 syslog(LOG_ERR, "Couldn't restore tty module %s: %m",
234 * List of valid speeds.
237 int speed_int, speed_val;
309 * Translate from bits/second to a speed_t.
315 struct speed *speedp;
319 for (speedp = speeds; speedp->speed_int; speedp++)
320 if (bps == speedp->speed_int)
321 return speedp->speed_val;
322 syslog(LOG_WARNING, "speed %d not supported", bps);
327 * Translate from a speed_t to bits/second.
333 struct speed *speedp;
337 for (speedp = speeds; speedp->speed_int; speedp++)
338 if (speed == speedp->speed_val)
339 return speedp->speed_int;
344 * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity,
345 * at the requested speed, etc. If `local' is true, set CLOCAL
346 * regardless of whether the modem option was specified.
348 set_up_tty(fd, local)
354 if (tcgetattr(fd, &tios) < 0) {
355 syslog(LOG_ERR, "tcgetattr: %m");
362 tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
364 tios.c_cflag |= CRTSCTS;
365 else if (crtscts < 0)
366 tios.c_cflag &= ~CRTSCTS;
368 tios.c_cflag |= CS8 | CREAD | HUPCL;
370 tios.c_cflag |= CLOCAL;
371 tios.c_iflag = IGNBRK | IGNPAR;
375 tios.c_cc[VTIME] = 0;
378 tios.c_iflag |= IXOFF;
379 tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
380 tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
383 speed = translate_speed(inspeed);
385 cfsetospeed(&tios, speed);
386 cfsetispeed(&tios, speed);
388 speed = cfgetospeed(&tios);
390 * We can't proceed if the serial port speed is 0,
391 * since that implies that the serial port is disabled.
394 syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
400 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
401 syslog(LOG_ERR, "tcsetattr: %m");
405 baud_rate = inspeed = baud_rate_of(speed);
410 * restore_tty - restore the terminal to the saved settings.
416 if (!default_device) {
418 * Turn off echoing, because otherwise we can get into
419 * a loop with the tty and the modem echoing to each other.
420 * We presume we are the sole user of this tty device, so
421 * when we close it, it will revert to its defaults anyway.
423 inittermios.c_lflag &= ~(ECHO | ECHONL);
425 if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
426 if (!hungup && errno != ENXIO)
427 syslog(LOG_WARNING, "tcsetattr: %m");
433 * setdtr - control the DTR line on the serial port.
434 * This is called from die(), so it shouldn't call die().
439 int modembits = TIOCM_DTR;
441 ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits);
445 * output - Output PPP packet.
456 log_packet(p, len, "sent ");
459 data.buf = (caddr_t) p;
460 if (putmsg(pppfd, NULL, &data, 0) < 0) {
461 if (errno != ENXIO) {
462 syslog(LOG_ERR, "Couldn't send packet: %m");
469 * wait_input - wait until there is data available on fd,
470 * for the length of time specified by *timo (indefinite
474 struct timeval *timo;
479 t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
481 pfd.events = POLLIN | POLLPRI | POLLHUP;
482 if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
483 syslog(LOG_ERR, "poll: %m");
489 * read_packet - get a PPP packet from the serial device.
495 struct strbuf ctrl, data;
497 unsigned char ctrlbuf[sizeof(union DL_primitives) + 64];
500 data.maxlen = PPP_MRU + PPP_HDRLEN;
501 data.buf = (caddr_t) buf;
502 ctrl.maxlen = sizeof(ctrlbuf);
503 ctrl.buf = (caddr_t) ctrlbuf;
505 len = getmsg(pppfd, &ctrl, &data, &flags);
507 if (errno = EAGAIN || errno == EINTR)
509 syslog(LOG_ERR, "Error reading packet: %m");
517 * Got a M_PROTO or M_PCPROTO message. Interpret it
518 * as a DLPI primitive.
521 syslog(LOG_DEBUG, "got dlpi prim 0x%x, len=%d",
522 ((union DL_primitives *)ctrlbuf)->dl_primitive, ctrl.len);
528 * ppp_send_config - configure the transmit characteristics of
532 ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
540 if (strioctl(pppfd, PPPIO_MTU, &mtu, sizeof(mtu), 0) < 0) {
541 if (hungup && errno == ENXIO)
543 syslog(LOG_ERR, "Couldn't set MTU: %m");
545 if (strioctl(pppfd, PPPIO_XACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
546 syslog(LOG_ERR, "Couldn't set transmit ACCM: %m");
548 cf[0] = (pcomp? COMP_PROT: 0) + (accomp? COMP_AC: 0);
549 cf[1] = COMP_PROT | COMP_AC;
550 if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
551 syslog(LOG_ERR, "Couldn't set prot/AC compression: %m");
556 * ppp_set_xaccm - set the extended transmit ACCM for the interface.
559 ppp_set_xaccm(unit, accm)
563 if (strioctl(pppfd, PPPIO_XACCM, accm, sizeof(ext_accm), 0) < 0) {
564 if (!hungup || errno != ENXIO)
565 syslog(LOG_WARNING, "Couldn't set extended ACCM: %m");
570 * ppp_recv_config - configure the receive-side characteristics of
574 ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
582 if (strioctl(pppfd, PPPIO_MRU, &mru, sizeof(mru), 0) < 0) {
583 if (hungup && errno == ENXIO)
585 syslog(LOG_ERR, "Couldn't set MRU: %m");
587 if (strioctl(pppfd, PPPIO_RACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
588 syslog(LOG_ERR, "Couldn't set receive ACCM: %m");
590 cf[0] = (pcomp? DECOMP_PROT: 0) + (accomp? DECOMP_AC: 0);
591 cf[1] = DECOMP_PROT | DECOMP_AC;
592 if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
593 syslog(LOG_ERR, "Couldn't set prot/AC decompression: %m");
598 * ccp_test - ask kernel whether a given compression method
599 * is acceptable for use.
601 ccp_test(unit, opt_ptr, opt_len, for_transmit)
602 int unit, opt_len, for_transmit;
605 return strioctl(pppfd, (for_transmit? PPPIO_XCOMP: PPPIO_RCOMP),
606 opt_ptr, opt_len, 0) >= 0;
610 * ccp_flags_set - inform kernel about the current state of CCP.
613 ccp_flags_set(unit, isopen, isup)
614 int unit, isopen, isup;
618 cf[0] = (isopen? CCP_ISOPEN: 0) + (isup? CCP_ISUP: 0);
619 cf[1] = CCP_ISOPEN | CCP_ISUP | CCP_ERROR | CCP_FATALERROR;
620 if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
621 if (!hungup || errno != ENXIO)
622 syslog(LOG_ERR, "Couldn't set kernel CCP state: %m");
627 * ccp_fatal_error - returns 1 if decompression was disabled as a
628 * result of an error detected after decompression of a packet,
629 * 0 otherwise. This is necessary because of patent nonsense.
632 ccp_fatal_error(unit)
638 if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
639 if (errno != ENXIO && errno != EINVAL)
640 syslog(LOG_ERR, "Couldn't get compression flags: %m");
643 return cf[0] & CCP_FATALERROR;
647 * sifvjcomp - config tcp header compression
650 sifvjcomp(u, vjcomp, xcidcomp, xmaxcid)
651 int u, vjcomp, xcidcomp, xmaxcid;
657 maxcid[0] = xcidcomp;
658 maxcid[1] = 15; /* XXX should be rmaxcid */
659 if (strioctl(pppfd, PPPIO_VJINIT, maxcid, sizeof(maxcid), 0) < 0) {
660 syslog(LOG_ERR, "Couldn't initialize VJ compression: %m");
664 cf[0] = (vjcomp? COMP_VJC + DECOMP_VJC: 0) /* XXX this is wrong */
665 + (xcidcomp? COMP_VJCCID + DECOMP_VJCCID: 0);
666 cf[1] = COMP_VJC + DECOMP_VJC + COMP_VJCCID + DECOMP_VJCCID;
667 if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
669 syslog(LOG_ERR, "Couldn't enable VJ compression: %m");
676 * sifup - Config the interface up and enable IP packets to pass.
684 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
685 if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) {
686 syslog(LOG_ERR, "Couldn't mark interface up (get): %m");
689 ifr.ifr_flags |= IFF_UP;
690 if (ioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
691 syslog(LOG_ERR, "Couldn't mark interface up (set): %m");
698 * sifdown - Config the interface down and disable IP.
708 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
709 if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) {
710 syslog(LOG_ERR, "Couldn't mark interface down (get): %m");
713 ifr.ifr_flags &= ~IFF_UP;
714 if (ioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
715 syslog(LOG_ERR, "Couldn't mark interface down (set): %m");
721 #define INET_ADDR(x) (((struct sockaddr_in *) &(x))->sin_addr.s_addr)
724 * sifaddr - Config the interface IP addresses and netmask.
733 memset(&ifr, 0, sizeof(ifr));
734 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
735 ifr.ifr_addr.sa_family = AF_INET;
736 INET_ADDR(ifr.ifr_addr) = o;
737 if (ioctl(ipfd, SIOCSIFADDR, &ifr) < 0) {
738 syslog(LOG_ERR, "Couldn't set local IP address: %m");
740 ifr.ifr_dstaddr.sa_family = AF_INET;
741 INET_ADDR(ifr.ifr_dstaddr) = h;
742 if (ioctl(ipfd, SIOCSIFDSTADDR, &ifr) < 0) {
743 syslog(LOG_ERR, "Couldn't set remote IP address: %m");
745 ifr.ifr_addr.sa_family = AF_INET;
746 INET_ADDR(ifr.ifr_addr) = m;
747 if (ioctl(ipfd, SIOCSIFNETMASK, &ifr) < 0) {
748 syslog(LOG_ERR, "Couldn't set IP netmask: %m");
750 ifr.ifr_metric = link_mtu;
751 if (ioctl(ipfd, SIOCSIFMTU, &ifr) < 0) {
752 syslog(LOG_ERR, "Couldn't set IP MTU: %m");
759 * cifaddr - Clear the interface IP addresses, and delete routes
760 * through the interface if possible.
769 if (ioctl(ipfd, I_UNLINK, ipmuxid) < 0) {
770 syslog(LOG_ERR, "Can't remove ppp interface unit: %m");
780 * sifdefaultroute - assign a default route through the address given.
783 sifdefaultroute(u, g)
789 rt.rt_dst.sa_family = AF_INET;
790 INET_ADDR(rt.rt_dst) = 0;
791 rt.rt_gateway.sa_family = AF_INET;
792 INET_ADDR(rt.rt_gateway) = g;
793 rt.rt_flags = RTF_GATEWAY;
795 if (ioctl(ipfd, SIOCADDRT, &rt) < 0) {
796 syslog(LOG_ERR, "Can't add default route: %m");
804 * cifdefaultroute - delete a default route through the address given.
807 cifdefaultroute(u, g)
813 rt.rt_dst.sa_family = AF_INET;
814 INET_ADDR(rt.rt_dst) = 0;
815 rt.rt_gateway.sa_family = AF_INET;
816 INET_ADDR(rt.rt_gateway) = g;
817 rt.rt_flags = RTF_GATEWAY;
819 if (ioctl(ipfd, SIOCDELRT, &rt) < 0) {
820 syslog(LOG_ERR, "Can't delete default route: %m");
828 * sifproxyarp - Make a proxy ARP entry for the peer.
831 sifproxyarp(unit, hisaddr)
835 struct arpreq arpreq;
837 memset(&arpreq, 0, sizeof(arpreq));
838 if (!get_ether_addr(hisaddr, &arpreq.arp_ha))
841 arpreq.arp_pa.sa_family = AF_INET;
842 INET_ADDR(arpreq.arp_pa) = hisaddr;
843 arpreq.arp_flags = ATF_PERM | ATF_PUBL;
844 if (ioctl(ipfd, SIOCSARP, (caddr_t) &arpreq) < 0) {
845 syslog(LOG_ERR, "Couldn't set proxy ARP entry: %m");
853 * cifproxyarp - Delete the proxy ARP entry for the peer.
856 cifproxyarp(unit, hisaddr)
860 struct arpreq arpreq;
862 memset(&arpreq, 0, sizeof(arpreq));
863 arpreq.arp_pa.sa_family = AF_INET;
864 INET_ADDR(arpreq.arp_pa) = hisaddr;
865 if (ioctl(ipfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
866 syslog(LOG_ERR, "Couldn't delete proxy ARP entry: %m");
874 * get_ether_addr - get the hardware address of an interface on the
875 * the same subnet as ipaddr.
880 get_ether_addr(ipaddr, hwaddr)
882 struct sockaddr *hwaddr;
884 struct ifreq *ifr, *ifend, ifreq;
890 * Scan through the system's network interfaces.
892 if (ioctl(ipfd, SIOCGIFNUM, &nif) < 0)
894 ifc.ifc_len = nif * sizeof(struct ifreq);
895 ifc.ifc_req = alloca(ifc.ifc_len);
896 if (ifc.ifc_req == 0)
898 if (ioctl(ipfd, SIOCGIFCONF, &ifc) < 0) {
899 syslog(LOG_WARNING, "Couldn't get system interface list: %m");
902 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
903 for (ifr = ifc.ifc_req; ifr < ifend; ++ifr) {
904 if (ifr->ifr_addr.sa_family != AF_INET)
907 * Check that the interface is up, and not point-to-point or loopback.
909 strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
910 if (ioctl(ipfd, SIOCGIFFLAGS, &ifreq) < 0)
912 if ((ifreq.ifr_flags &
913 (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK|IFF_NOARP))
914 != (IFF_UP|IFF_BROADCAST))
917 * Get its netmask and check that it's on the right subnet.
919 if (ioctl(ipfd, SIOCGIFNETMASK, &ifreq) < 0)
921 ina = INET_ADDR(ifr->ifr_addr);
922 mask = INET_ADDR(ifreq.ifr_addr);
923 if ((ipaddr & mask) == (ina & mask))
928 syslog(LOG_WARNING, "No suitable interface found for proxy ARP");
932 syslog(LOG_INFO, "found interface %s for proxy ARP", ifr->ifr_name);
933 if (!get_hw_addr(ifr->ifr_name, hwaddr)) {
934 syslog(LOG_ERR, "Couldn't get hardware address for %s", ifr->ifr_name);
942 * get_hw_addr - obtain the hardware address for a named interface.
945 get_hw_addr(name, hwaddr)
947 struct sockaddr *hwaddr;
950 int unit, iffd, adrlen;
954 union DL_primitives prim;
959 * We have to open the device and ask it for its hardware address.
960 * First split apart the device name and unit.
962 strcpy(ifdev, "/dev/");
963 q = ifdev + 5; /* strlen("/dev/") */
964 while (*name != 0 && !isdigit(*name))
970 * Open the device and do a DLPI attach and phys_addr_req.
972 iffd = open(ifdev, O_RDWR);
974 syslog(LOG_ERR, "Can't open %s: %m", ifdev);
977 if (dlpi_attach(iffd, unit) < 0
978 || dlpi_get_reply(iffd, &reply.prim, DL_OK_ACK, sizeof(reply)) < 0
979 || dlpi_phys_addr_req(iffd) < 0
980 || dlpi_get_reply(iffd, &reply.prim, DL_PHYS_ADDR_ACK,
981 sizeof(reply)) < 0) {
986 hwaddr->sa_family = AF_UNSPEC;
987 adrlen = reply.prim.physaddr_ack.dl_addr_length;
988 adrp = (unsigned char *)&reply + reply.prim.physaddr_ack.dl_addr_offset;
989 memcpy(hwaddr->sa_data, adrp, adrlen);
1001 req.dl_primitive = DL_ATTACH_REQ;
1003 buf.len = sizeof(req);
1004 buf.buf = (void *) &req;
1005 return putmsg(fd, &buf, NULL, RS_HIPRI);
1009 dlpi_phys_addr_req(fd)
1012 dl_phys_addr_req_t req;
1015 req.dl_primitive = DL_PHYS_ADDR_REQ;
1016 req.dl_addr_type = DL_CURR_PHYS_ADDR;
1017 buf.len = sizeof(req);
1018 buf.buf = (void *) &req;
1019 return putmsg(fd, &buf, NULL, RS_HIPRI);
1023 dlpi_get_reply(fd, reply, expected_prim, maxlen)
1024 union DL_primitives *reply;
1025 int fd, expected_prim, maxlen;
1032 * Use poll to wait for a message with a timeout.
1035 pfd.events = POLLIN | POLLPRI;
1037 n = poll(&pfd, 1, 1000);
1038 } while (n == -1 && errno == EINTR);
1045 buf.maxlen = maxlen;
1046 buf.buf = (void *) reply;
1048 if (getmsg(fd, &buf, NULL, &flags) < 0)
1051 if (buf.len < sizeof(ulong)) {
1053 syslog(LOG_DEBUG, "dlpi response short (len=%d)\n", buf.len);
1057 if (reply->dl_primitive == expected_prim)
1061 if (reply->dl_primitive == DL_ERROR_ACK) {
1062 syslog(LOG_DEBUG, "dlpi error %d (unix errno %d) for prim %x\n",
1063 reply->error_ack.dl_errno, reply->error_ack.dl_unix_errno,
1064 reply->error_ack.dl_error_primitive);
1066 syslog(LOG_DEBUG, "dlpi unexpected response prim %x\n",
1067 reply->dl_primitive);
1075 * Return user specified netmask, modified by any mask we might determine
1076 * for address `addr' (in network byte order).
1077 * Here we scan through the system's list of interfaces, looking for
1078 * any non-point-to-point interfaces which might appear to be on the same
1079 * network as `addr'. If we find any, we OR in their netmask to the
1080 * user-specified netmask.
1086 u_int32_t mask, nmask, ina;
1087 struct ifreq *ifr, *ifend, ifreq;
1092 if (IN_CLASSA(addr)) /* determine network mask for address class */
1093 nmask = IN_CLASSA_NET;
1094 else if (IN_CLASSB(addr))
1095 nmask = IN_CLASSB_NET;
1097 nmask = IN_CLASSC_NET;
1098 /* class D nets are disallowed by bad_ip_adrs */
1099 mask = netmask | htonl(nmask);
1102 * Scan through the system's network interfaces.
1104 if (ioctl(ipfd, SIOCGIFNUM, &nif) < 0)
1106 ifc.ifc_len = nif * sizeof(struct ifreq);
1107 ifc.ifc_req = alloca(ifc.ifc_len);
1108 if (ifc.ifc_req == 0)
1110 if (ioctl(ipfd, SIOCGIFCONF, &ifc) < 0) {
1111 syslog(LOG_WARNING, "Couldn't get system interface list: %m");
1114 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
1115 for (ifr = ifc.ifc_req; ifr < ifend; ++ifr) {
1117 * Check the interface's internet address.
1119 if (ifr->ifr_addr.sa_family != AF_INET)
1121 ina = INET_ADDR(ifr->ifr_addr);
1122 if ((ntohl(ina) & nmask) != (addr & nmask))
1125 * Check that the interface is up, and not point-to-point or loopback.
1127 strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
1128 if (ioctl(ipfd, SIOCGIFFLAGS, &ifreq) < 0)
1130 if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))
1134 * Get its netmask and OR it into our mask.
1136 if (ioctl(ipfd, SIOCGIFNETMASK, &ifreq) < 0)
1138 mask |= INET_ADDR(ifreq.ifr_addr);
1145 * logwtmp - write an accounting record to the /var/adm/wtmp file.
1148 logwtmp(line, name, host)
1149 char *line, *name, *host;
1154 * gethostid - return the serial number of this machine.
1161 if (sysinfo(SI_HW_SERIAL, buf, sizeof(buf)) < 0) {
1162 syslog(LOG_ERR, "sysinfo: %m");
1165 return strtol(buf, NULL, 16);
1169 strioctl(fd, cmd, ptr, ilen, olen)
1170 int fd, cmd, ilen, olen;
1173 struct strioctl str;
1179 if (ioctl(fd, I_STR, &str) == -1)
1181 if (str.ic_len != olen)
1182 syslog(LOG_DEBUG, "strioctl: expected %d bytes, got %d for cmd %x\n",
1183 olen, str.ic_len, cmd);