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.2 1995/06/01 01:31:28 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");
160 /* Pop any existing modules off the tty stream. */
162 if (ioctl(fd, I_LOOK, tty_modules[i]) < 0
163 || ioctl(fd, I_POP, 0) < 0)
167 /* Push the async hdlc module and the compressor module. */
168 if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0) {
169 syslog(LOG_ERR, "Couldn't push PPP Async HDLC module: %m");
172 if (ioctl(fd, I_PUSH, "ppp_comp") < 0) {
173 syslog(LOG_ERR, "Couldn't push PPP compression module: %m");
177 /* Link the serial port under the PPP multiplexor. */
178 if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) {
179 syslog(LOG_ERR, "Can't link tty to PPP mux: %m");
185 * disestablish_ppp - Restore the serial port to normal operation.
186 * This shouldn't call die() because it's called from die().
194 if (ioctl(pppfd, I_UNLINK, fdmuxid) < 0) {
196 syslog(LOG_ERR, "Can't unlink tty from PPP mux: %m");
201 while (ioctl(fd, I_POP, 0) >= 0)
203 for (i = tty_nmodules - 1; i >= 0; --i)
204 if (ioctl(fd, I_PUSH, tty_modules[i]) < 0)
205 syslog(LOG_ERR, "Couldn't restore tty module %s: %m",
212 * List of valid speeds.
215 int speed_int, speed_val;
287 * Translate from bits/second to a speed_t.
293 struct speed *speedp;
297 for (speedp = speeds; speedp->speed_int; speedp++)
298 if (bps == speedp->speed_int)
299 return speedp->speed_val;
300 syslog(LOG_WARNING, "speed %d not supported", bps);
305 * Translate from a speed_t to bits/second.
311 struct speed *speedp;
315 for (speedp = speeds; speedp->speed_int; speedp++)
316 if (speed == speedp->speed_val)
317 return speedp->speed_int;
322 * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity,
323 * at the requested speed, etc. If `local' is true, set CLOCAL
324 * regardless of whether the modem option was specified.
326 set_up_tty(fd, local)
332 if (tcgetattr(fd, &tios) < 0) {
333 syslog(LOG_ERR, "tcgetattr: %m");
340 tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
342 tios.c_cflag |= CRTSCTS;
343 else if (crtscts < 0)
344 tios.c_cflag &= ~CRTSCTS;
346 tios.c_cflag |= CS8 | CREAD | HUPCL;
348 tios.c_cflag |= CLOCAL;
349 tios.c_iflag = IGNBRK | IGNPAR;
353 tios.c_cc[VTIME] = 0;
356 tios.c_iflag |= IXOFF;
357 tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
358 tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
361 speed = translate_speed(inspeed);
363 cfsetospeed(&tios, speed);
364 cfsetispeed(&tios, speed);
366 speed = cfgetospeed(&tios);
368 * We can't proceed if the serial port speed is 0,
369 * since that implies that the serial port is disabled.
372 syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
378 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
379 syslog(LOG_ERR, "tcsetattr: %m");
383 baud_rate = inspeed = baud_rate_of(speed);
388 * restore_tty - restore the terminal to the saved settings.
394 if (!default_device) {
396 * Turn off echoing, because otherwise we can get into
397 * a loop with the tty and the modem echoing to each other.
398 * We presume we are the sole user of this tty device, so
399 * when we close it, it will revert to its defaults anyway.
401 inittermios.c_lflag &= ~(ECHO | ECHONL);
403 if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
404 if (!hungup && errno != ENXIO)
405 syslog(LOG_WARNING, "tcsetattr: %m");
411 * setdtr - control the DTR line on the serial port.
412 * This is called from die(), so it shouldn't call die().
417 int modembits = TIOCM_DTR;
419 ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits);
423 * output - Output PPP packet.
434 log_packet(p, len, "sent ");
437 data.buf = (caddr_t) p;
438 if (putmsg(pppfd, NULL, &data, 0) < 0) {
439 if (errno != ENXIO) {
440 syslog(LOG_ERR, "Couldn't send packet: %m");
447 * wait_input - wait until there is data available on fd,
448 * for the length of time specified by *timo (indefinite
452 struct timeval *timo;
457 t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
459 pfd.events = POLLIN | POLLPRI | POLLHUP;
460 if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
461 syslog(LOG_ERR, "poll: %m");
467 * read_packet - get a PPP packet from the serial device.
473 struct strbuf ctrl, data;
475 unsigned char ctrlbuf[sizeof(union DL_primitives) + 64];
478 data.maxlen = PPP_MRU + PPP_HDRLEN;
479 data.buf = (caddr_t) buf;
480 ctrl.maxlen = sizeof(ctrlbuf);
481 ctrl.buf = (caddr_t) ctrlbuf;
483 len = getmsg(pppfd, &ctrl, &data, &flags);
485 if (errno = EAGAIN || errno == EINTR)
487 syslog(LOG_ERR, "Error reading packet: %m");
495 * Got a M_PROTO or M_PCPROTO message. Interpret it
496 * as a DLPI primitive.
499 syslog(LOG_DEBUG, "got dlpi prim 0x%x, len=%d",
500 ((union DL_primitives *)ctrlbuf)->dl_primitive, ctrl.len);
506 * ppp_send_config - configure the transmit characteristics of
510 ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
518 if (strioctl(pppfd, PPPIO_MTU, &mtu, sizeof(mtu), 0) < 0) {
519 if (hungup && errno == ENXIO)
521 syslog(LOG_ERR, "Couldn't set MTU: %m");
523 if (strioctl(pppfd, PPPIO_XACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
524 syslog(LOG_ERR, "Couldn't set transmit ACCM: %m");
526 cf[0] = (pcomp? COMP_PROT: 0) + (accomp? COMP_AC: 0);
527 cf[1] = COMP_PROT | COMP_AC;
528 if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
529 syslog(LOG_ERR, "Couldn't set prot/AC compression: %m");
534 * ppp_set_xaccm - set the extended transmit ACCM for the interface.
537 ppp_set_xaccm(unit, accm)
541 if (strioctl(pppfd, PPPIO_XACCM, accm, sizeof(ext_accm), 0) < 0) {
542 if (!hungup || errno != ENXIO)
543 syslog(LOG_WARNING, "Couldn't set extended ACCM: %m");
548 * ppp_recv_config - configure the receive-side characteristics of
552 ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
560 if (strioctl(pppfd, PPPIO_MRU, &mru, sizeof(mru), 0) < 0) {
561 if (hungup && errno == ENXIO)
563 syslog(LOG_ERR, "Couldn't set MRU: %m");
565 if (strioctl(pppfd, PPPIO_RACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
566 syslog(LOG_ERR, "Couldn't set receive ACCM: %m");
568 cf[0] = (pcomp? DECOMP_PROT: 0) + (accomp? DECOMP_AC: 0);
569 cf[1] = DECOMP_PROT | DECOMP_AC;
570 if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
571 syslog(LOG_ERR, "Couldn't set prot/AC decompression: %m");
576 * ccp_test - ask kernel whether a given compression method
577 * is acceptable for use.
579 ccp_test(unit, opt_ptr, opt_len, for_transmit)
580 int unit, opt_len, for_transmit;
583 return strioctl(pppfd, (for_transmit? PPPIO_XCOMP: PPPIO_RCOMP),
584 opt_ptr, opt_len, 0) >= 0;
588 * ccp_flags_set - inform kernel about the current state of CCP.
591 ccp_flags_set(unit, isopen, isup)
592 int unit, isopen, isup;
596 cf[0] = (isopen? CCP_ISOPEN: 0) + (isup? CCP_ISUP: 0);
597 cf[1] = CCP_ISOPEN | CCP_ISUP | CCP_ERROR | CCP_FATALERROR;
598 if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
599 if (!hungup || errno != ENXIO)
600 syslog(LOG_ERR, "Couldn't set kernel CCP state: %m");
605 * ccp_fatal_error - returns 1 if decompression was disabled as a
606 * result of an error detected after decompression of a packet,
607 * 0 otherwise. This is necessary because of patent nonsense.
610 ccp_fatal_error(unit)
616 if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
617 if (errno != ENXIO && errno != EINVAL)
618 syslog(LOG_ERR, "Couldn't get compression flags: %m");
621 return cf[0] & CCP_FATALERROR;
625 * sifvjcomp - config tcp header compression
628 sifvjcomp(u, vjcomp, xcidcomp, xmaxcid)
629 int u, vjcomp, xcidcomp, xmaxcid;
635 maxcid[0] = xcidcomp;
636 maxcid[1] = 15; /* XXX should be rmaxcid */
637 if (strioctl(pppfd, PPPIO_VJINIT, maxcid, sizeof(maxcid), 0) < 0) {
638 syslog(LOG_ERR, "Couldn't initialize VJ compression: %m");
642 cf[0] = (vjcomp? COMP_VJC + DECOMP_VJC: 0) /* XXX this is wrong */
643 + (xcidcomp? COMP_VJCCID + DECOMP_VJCCID: 0);
644 cf[1] = COMP_VJC + DECOMP_VJC + COMP_VJCCID + DECOMP_VJCCID;
645 if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
647 syslog(LOG_ERR, "Couldn't enable VJ compression: %m");
654 * sifup - Config the interface up and enable IP packets to pass.
663 syslog(LOG_DEBUG, "sifup: not plumbed!");
666 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
667 if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) {
668 syslog(LOG_ERR, "Couldn't mark interface up (get): %m");
671 ifr.ifr_flags |= IFF_UP;
672 if (ioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
673 syslog(LOG_ERR, "Couldn't mark interface up (set): %m");
680 * sifdown - Config the interface down and disable IP.
690 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
691 if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) {
692 syslog(LOG_ERR, "Couldn't mark interface down (get): %m");
695 ifr.ifr_flags &= ~IFF_UP;
696 if (ioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
697 syslog(LOG_ERR, "Couldn't mark interface down (set): %m");
703 #define INET_ADDR(x) (((struct sockaddr_in *) &(x))->sin_addr.s_addr)
706 * sifaddr - Config the interface IP addresses and netmask.
716 fd = open("/dev/ppp", O_RDWR, 0);
718 syslog(LOG_ERR, "Can't open /dev/ppp (2): %m");
721 if (ioctl(fd, I_PUSH, "ip") < 0) {
722 syslog(LOG_ERR, "Can't push IP module: %m");
726 ipmuxid = ioctl(ipfd, I_LINK, fd);
729 syslog(LOG_ERR, "Can't link PPP device to IP: %m");
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.
768 if (ioctl(ipfd, I_UNLINK, ipmuxid) < 0) {
769 syslog(LOG_ERR, "Can't remove ppp interface unit: %m");
778 * sifdefaultroute - assign a default route through the address given.
781 sifdefaultroute(u, g)
787 rt.rt_dst.sa_family = AF_INET;
788 INET_ADDR(rt.rt_dst) = 0;
789 rt.rt_gateway.sa_family = AF_INET;
790 INET_ADDR(rt.rt_gateway) = g;
791 rt.rt_flags = RTF_GATEWAY;
793 if (ioctl(ipfd, SIOCADDRT, &rt) < 0) {
794 syslog(LOG_ERR, "Can't add default route: %m");
802 * cifdefaultroute - delete a default route through the address given.
805 cifdefaultroute(u, g)
811 rt.rt_dst.sa_family = AF_INET;
812 INET_ADDR(rt.rt_dst) = 0;
813 rt.rt_gateway.sa_family = AF_INET;
814 INET_ADDR(rt.rt_gateway) = g;
815 rt.rt_flags = RTF_GATEWAY;
817 if (ioctl(ipfd, SIOCDELRT, &rt) < 0) {
818 syslog(LOG_ERR, "Can't delete default route: %m");
826 * sifproxyarp - Make a proxy ARP entry for the peer.
829 sifproxyarp(unit, hisaddr)
833 struct arpreq arpreq;
835 memset(&arpreq, 0, sizeof(arpreq));
836 if (!get_ether_addr(hisaddr, &arpreq.arp_ha))
839 arpreq.arp_pa.sa_family = AF_INET;
840 INET_ADDR(arpreq.arp_pa) = hisaddr;
841 arpreq.arp_flags = ATF_PERM | ATF_PUBL;
842 if (ioctl(ipfd, SIOCSARP, (caddr_t) &arpreq) < 0) {
843 syslog(LOG_ERR, "Couldn't set proxy ARP entry: %m");
851 * cifproxyarp - Delete the proxy ARP entry for the peer.
854 cifproxyarp(unit, hisaddr)
858 struct arpreq arpreq;
860 memset(&arpreq, 0, sizeof(arpreq));
861 arpreq.arp_pa.sa_family = AF_INET;
862 INET_ADDR(arpreq.arp_pa) = hisaddr;
863 if (ioctl(ipfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
864 syslog(LOG_ERR, "Couldn't delete proxy ARP entry: %m");
872 * get_ether_addr - get the hardware address of an interface on the
873 * the same subnet as ipaddr.
878 get_ether_addr(ipaddr, hwaddr)
880 struct sockaddr *hwaddr;
882 struct ifreq *ifr, *ifend, ifreq;
888 * Scan through the system's network interfaces.
890 if (ioctl(ipfd, SIOCGIFNUM, &nif) < 0)
892 ifc.ifc_len = nif * sizeof(struct ifreq);
893 ifc.ifc_req = alloca(ifc.ifc_len);
894 if (ifc.ifc_req == 0)
896 if (ioctl(ipfd, SIOCGIFCONF, &ifc) < 0) {
897 syslog(LOG_WARNING, "Couldn't get system interface list: %m");
900 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
901 for (ifr = ifc.ifc_req; ifr < ifend; ++ifr) {
902 if (ifr->ifr_addr.sa_family != AF_INET)
905 * Check that the interface is up, and not point-to-point or loopback.
907 strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
908 if (ioctl(ipfd, SIOCGIFFLAGS, &ifreq) < 0)
910 if ((ifreq.ifr_flags &
911 (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK|IFF_NOARP))
912 != (IFF_UP|IFF_BROADCAST))
915 * Get its netmask and check that it's on the right subnet.
917 if (ioctl(ipfd, SIOCGIFNETMASK, &ifreq) < 0)
919 ina = INET_ADDR(ifr->ifr_addr);
920 mask = INET_ADDR(ifreq.ifr_addr);
921 if ((ipaddr & mask) == (ina & mask))
926 syslog(LOG_WARNING, "No suitable interface found for proxy ARP");
930 syslog(LOG_INFO, "found interface %s for proxy ARP", ifr->ifr_name);
931 if (!get_hw_addr(ifr->ifr_name, hwaddr)) {
932 syslog(LOG_ERR, "Couldn't get hardware address for %s", ifr->ifr_name);
940 * get_hw_addr - obtain the hardware address for a named interface.
943 get_hw_addr(name, hwaddr)
945 struct sockaddr *hwaddr;
948 int unit, iffd, adrlen;
952 union DL_primitives prim;
957 * We have to open the device and ask it for its hardware address.
958 * First split apart the device name and unit.
960 strcpy(ifdev, "/dev/");
961 q = ifdev + 5; /* strlen("/dev/") */
962 while (*name != 0 && !isdigit(*name))
968 * Open the device and do a DLPI attach and phys_addr_req.
970 iffd = open(ifdev, O_RDWR);
972 syslog(LOG_ERR, "Can't open %s: %m", ifdev);
975 if (dlpi_attach(iffd, unit) < 0
976 || dlpi_get_reply(iffd, &reply.prim, DL_OK_ACK, sizeof(reply)) < 0
977 || dlpi_phys_addr_req(iffd) < 0
978 || dlpi_get_reply(iffd, &reply.prim, DL_PHYS_ADDR_ACK,
979 sizeof(reply)) < 0) {
984 hwaddr->sa_family = AF_UNSPEC;
985 adrlen = reply.prim.physaddr_ack.dl_addr_length;
986 adrp = (unsigned char *)&reply + reply.prim.physaddr_ack.dl_addr_offset;
987 memcpy(hwaddr->sa_data, adrp, adrlen);
999 req.dl_primitive = DL_ATTACH_REQ;
1001 buf.len = sizeof(req);
1002 buf.buf = (void *) &req;
1003 return putmsg(fd, &buf, NULL, RS_HIPRI);
1007 dlpi_phys_addr_req(fd)
1010 dl_phys_addr_req_t req;
1013 req.dl_primitive = DL_PHYS_ADDR_REQ;
1014 req.dl_addr_type = DL_CURR_PHYS_ADDR;
1015 buf.len = sizeof(req);
1016 buf.buf = (void *) &req;
1017 return putmsg(fd, &buf, NULL, RS_HIPRI);
1021 dlpi_get_reply(fd, reply, expected_prim, maxlen)
1022 union DL_primitives *reply;
1023 int fd, expected_prim, maxlen;
1030 * Use poll to wait for a message with a timeout.
1033 pfd.events = POLLIN | POLLPRI;
1035 n = poll(&pfd, 1, 1000);
1036 } while (n == -1 && errno == EINTR);
1043 buf.maxlen = maxlen;
1044 buf.buf = (void *) reply;
1046 if (getmsg(fd, &buf, NULL, &flags) < 0)
1049 if (buf.len < sizeof(ulong)) {
1051 syslog(LOG_DEBUG, "dlpi response short (len=%d)\n", buf.len);
1055 if (reply->dl_primitive == expected_prim)
1059 if (reply->dl_primitive == DL_ERROR_ACK) {
1060 syslog(LOG_DEBUG, "dlpi error %d (unix errno %d) for prim %x\n",
1061 reply->error_ack.dl_errno, reply->error_ack.dl_unix_errno,
1062 reply->error_ack.dl_error_primitive);
1064 syslog(LOG_DEBUG, "dlpi unexpected response prim %x\n",
1065 reply->dl_primitive);
1073 * Return user specified netmask, modified by any mask we might determine
1074 * for address `addr' (in network byte order).
1075 * Here we scan through the system's list of interfaces, looking for
1076 * any non-point-to-point interfaces which might appear to be on the same
1077 * network as `addr'. If we find any, we OR in their netmask to the
1078 * user-specified netmask.
1084 u_int32_t mask, nmask, ina;
1085 struct ifreq *ifr, *ifend, ifreq;
1090 if (IN_CLASSA(addr)) /* determine network mask for address class */
1091 nmask = IN_CLASSA_NET;
1092 else if (IN_CLASSB(addr))
1093 nmask = IN_CLASSB_NET;
1095 nmask = IN_CLASSC_NET;
1096 /* class D nets are disallowed by bad_ip_adrs */
1097 mask = netmask | htonl(nmask);
1100 * Scan through the system's network interfaces.
1102 if (ioctl(ipfd, SIOCGIFNUM, &nif) < 0)
1104 ifc.ifc_len = nif * sizeof(struct ifreq);
1105 ifc.ifc_req = alloca(ifc.ifc_len);
1106 if (ifc.ifc_req == 0)
1108 if (ioctl(ipfd, SIOCGIFCONF, &ifc) < 0) {
1109 syslog(LOG_WARNING, "Couldn't get system interface list: %m");
1112 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
1113 for (ifr = ifc.ifc_req; ifr < ifend; ++ifr) {
1115 * Check the interface's internet address.
1117 if (ifr->ifr_addr.sa_family != AF_INET)
1119 ina = INET_ADDR(ifr->ifr_addr);
1120 if ((ntohl(ina) & nmask) != (addr & nmask))
1123 * Check that the interface is up, and not point-to-point or loopback.
1125 strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
1126 if (ioctl(ipfd, SIOCGIFFLAGS, &ifreq) < 0)
1128 if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))
1132 * Get its netmask and OR it into our mask.
1134 if (ioctl(ipfd, SIOCGIFNETMASK, &ifreq) < 0)
1136 mask |= INET_ADDR(ifreq.ifr_addr);
1143 * logwtmp - write an accounting record to the /var/adm/wtmp file.
1146 logwtmp(line, name, host)
1147 char *line, *name, *host;
1152 * gethostid - return the serial number of this machine.
1159 if (sysinfo(SI_HW_SERIAL, buf, sizeof(buf)) < 0) {
1160 syslog(LOG_ERR, "sysinfo: %m");
1163 return strtol(buf, NULL, 16);
1167 strioctl(fd, cmd, ptr, ilen, olen)
1168 int fd, cmd, ilen, olen;
1171 struct strioctl str;
1177 if (ioctl(fd, I_STR, &str) == -1)
1179 if (str.ic_len != olen)
1180 syslog(LOG_DEBUG, "strioctl: expected %d bytes, got %d for cmd %x\n",
1181 olen, str.ic_len, cmd);