2 * sys-bsd.c - System-dependent procedures for setting up
3 * PPP interfaces on bsd-4.4-ish systems (including 386BSD, NetBSD, etc.)
5 * Copyright (c) 1989 Carnegie Mellon University.
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by Carnegie Mellon University. The name of the
14 * University may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 static char rcsid[] = "$Id: sys-bsd.c,v 1.14 1994/10/22 11:50:36 paulus Exp $";
32 #include <sys/ioctl.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
36 #include <sys/errno.h>
39 #include <net/ppp_defs.h>
40 #include <net/if_ppp.h>
41 #include <net/route.h>
42 #include <net/if_dl.h>
43 #include <netinet/in.h>
46 #include <netinet/if_ether.h>
51 static int initdisc = -1; /* Initial TTY discipline */
54 static int restore_term; /* 1 => we've munged the terminal */
55 static struct termios inittermios; /* Initial TTY termios */
58 * sys_init - System-dependent initialization.
63 openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP);
64 setlogmask(LOG_UPTO(LOG_INFO));
66 setlogmask(LOG_UPTO(LOG_DEBUG));
70 * note_debug_level - note a change in the debug level.
76 syslog(LOG_INFO, "Debug turned ON, Level %d", debug);
77 setlogmask(LOG_UPTO(LOG_DEBUG));
79 setlogmask(LOG_UPTO(LOG_WARNING));
84 * ppp_available - check whether the system has any ppp interfaces
85 * (in fact we check whether we can do an ioctl on ppp0).
93 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
94 return 1; /* can't tell - maybe we're not root */
96 strncpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name));
97 ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0;
104 * establish_ppp - Turn the serial port into a ppp interface.
109 int pppdisc = PPPDISC;
112 if (ioctl(fd, TIOCGETD, &initdisc) < 0) {
113 syslog(LOG_ERR, "ioctl(TIOCGETD): %m");
116 if (ioctl(fd, TIOCSETD, &pppdisc) < 0) {
117 syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
122 * Find out which interface we were given.
124 if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {
125 syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
130 * Enable debug in the driver if requested.
133 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
134 syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): %m");
136 x |= (kdebugflag & 0xFF) * SC_DEBUG;
137 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
138 syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
145 * disestablish_ppp - Restore the serial port to normal operation.
146 * This shouldn't call die() because it's called from die().
156 * Check whether the link seems not to be 8-bit clean.
158 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) == 0) {
160 switch (~x & (SC_RCV_B7_0|SC_RCV_B7_1|SC_RCV_EVNP|SC_RCV_ODDP)) {
162 s = "bit 7 set to 1";
165 s = "bit 7 set to 0";
175 syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
176 syslog(LOG_WARNING, "All received characters had %s", s);
179 if (ioctl(fd, TIOCSETD, &initdisc) < 0)
180 syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
186 * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity,
187 * at the requested speed, etc. If `local' is true, set CLOCAL
188 * regardless of whether the modem option was specified.
190 * For *BSD, we assume that speed_t values numerically equal bits/second.
192 set_up_tty(fd, local)
197 if (tcgetattr(fd, &tios) < 0) {
198 syslog(LOG_ERR, "tcgetattr: %m");
205 tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
207 tios.c_cflag |= CRTSCTS;
208 else if (crtscts < 0)
209 tios.c_cflag &= ~CRTSCTS;
211 tios.c_cflag |= CS8 | CREAD | HUPCL;
213 tios.c_cflag |= CLOCAL;
214 tios.c_iflag = IGNBRK | IGNPAR;
218 tios.c_cc[VTIME] = 0;
221 tios.c_iflag |= IXOFF;
222 tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
223 tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
227 cfsetospeed(&tios, inspeed);
228 cfsetispeed(&tios, inspeed);
230 inspeed = cfgetospeed(&tios);
232 * We can't proceed if the serial port speed is 0,
233 * since that implies that the serial port is disabled.
236 syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
243 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
244 syslog(LOG_ERR, "tcsetattr: %m");
252 * restore_tty - restore the terminal to the saved settings.
258 if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
260 syslog(LOG_WARNING, "tcsetattr: %m");
266 * setdtr - control the DTR line on the serial port.
267 * This is called from die(), so it shouldn't call die().
272 int modembits = TIOCM_DTR;
274 ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits);
279 * output - Output PPP packet.
288 MAINDEBUG((LOG_WARNING, "output: unit != 0!"));
290 log_packet(p, len, "sent ");
292 if (write(fd, p, len) < 0) {
293 syslog(LOG_ERR, "write: %m");
300 * wait_input - wait until there is data available on fd,
301 * for the length of time specified by *timo (indefinite
305 struct timeval *timo;
312 n = select(fd+1, &ready, NULL, &ready, timo);
313 if (n < 0 && errno != EINTR) {
314 syslog(LOG_ERR, "select: %m");
321 * read_packet - get a PPP packet from the serial device.
329 if ((len = read(fd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
330 if (errno == EWOULDBLOCK || errno == EINTR) {
331 MAINDEBUG((LOG_DEBUG, "read(fd): %m"));
334 syslog(LOG_ERR, "read(fd): %m");
342 * ppp_send_config - configure the transmit characteristics of
346 ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
354 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
356 if (ioctl(s, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
357 syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
361 if (ioctl(fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) {
362 syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m");
366 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
367 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
370 x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
371 x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
372 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
373 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
380 * ppp_set_xaccm - set the extended transmit ACCM for the interface.
383 ppp_set_xaccm(unit, accm)
387 if (ioctl(fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
388 syslog(LOG_WARNING, "ioctl(set extended ACCM): %m");
393 * ppp_recv_config - configure the receive-side characteristics of
397 ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
404 if (ioctl(fd, PPPIOCSMRU, (caddr_t) &mru) < 0) {
405 syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m");
408 if (ioctl(fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) {
409 syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m");
412 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
413 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
416 x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
417 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
418 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
424 * ccp_test - ask kernel whether a given compression method
425 * is acceptable for use.
427 ccp_test(unit, opt_ptr, opt_len, for_transmit)
428 int unit, opt_len, for_transmit;
431 struct ppp_option_data data;
434 data.length = opt_len;
435 data.transmit = for_transmit;
436 return ioctl(fd, PPPIOCSCOMPRESS, (caddr_t) &data) >= 0;
440 * ccp_flags_set - inform kernel about the current state of CCP.
443 ccp_flags_set(unit, isopen, isup)
444 int unit, isopen, isup;
448 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
449 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
452 x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
453 x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
454 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
455 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
459 * ccp_fatal_error - returns 1 if decompression was disabled as a
460 * result of an error detected after decompression of a packet,
461 * 0 otherwise. This is necessary because of patent nonsense.
464 ccp_fatal_error(unit)
469 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
470 syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
473 return x & SC_DC_FERROR;
477 * sifvjcomp - config tcp header compression
480 sifvjcomp(u, vjcomp, cidcomp, maxcid)
481 int u, vjcomp, cidcomp, maxcid;
485 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
486 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
489 x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP;
490 x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
491 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
492 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
495 if (ioctl(fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
496 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
503 * sifup - Config the interface up and enable IP packets to pass.
513 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
514 if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
515 syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
518 ifr.ifr_flags |= IFF_UP;
519 if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
520 syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
523 npi.protocol = PPP_IP;
524 npi.mode = NPMODE_PASS;
525 if (ioctl(fd, PPPIOCSNPMODE, &npi) < 0) {
526 if (errno != ENOTTY) {
527 syslog(LOG_ERR, "ioctl(PPPIOCSNPMODE): %m");
530 /* for backwards compatibility */
531 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
532 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
536 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
537 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
545 * sifdown - Config the interface down and disable IP.
557 npi.protocol = PPP_IP;
558 npi.mode = NPMODE_ERROR;
559 if (ioctl(fd, PPPIOCSNPMODE, (caddr_t) &npi) < 0) {
560 if (errno != ENOTTY) {
561 syslog(LOG_ERR, "ioctl(PPPIOCSNPMODE): %m");
564 /* backwards compatibility */
565 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
566 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
570 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
571 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
578 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
579 if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
580 syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
583 ifr.ifr_flags &= ~IFF_UP;
584 if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
585 syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
593 * SET_SA_FAMILY - set the sa_family field of a struct sockaddr,
596 #define SET_SA_FAMILY(addr, family) \
597 BZERO((char *) &(addr), sizeof(addr)); \
598 addr.sa_family = (family); \
599 addr.sa_len = sizeof(addr);
602 * sifaddr - Config the interface IP addresses and netmask.
609 struct ifaliasreq ifra;
611 strncpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name));
612 SET_SA_FAMILY(ifra.ifra_addr, AF_INET);
613 ((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o;
614 SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET);
615 ((struct sockaddr_in *) &ifra.ifra_broadaddr)->sin_addr.s_addr = h;
617 SET_SA_FAMILY(ifra.ifra_mask, AF_INET);
618 ((struct sockaddr_in *) &ifra.ifra_mask)->sin_addr.s_addr = m;
620 BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
621 if (ioctl(s, SIOCAIFADDR, (caddr_t) &ifra) < 0) {
622 if (errno != EEXIST) {
623 syslog(LOG_ERR, "ioctl(SIOCAIFADDR): %m");
626 syslog(LOG_WARNING, "ioctl(SIOCAIFADDR): Address already exists");
632 * cifaddr - Clear the interface IP addresses, and delete routes
633 * through the interface if possible.
640 struct ifaliasreq ifra;
642 strncpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name));
643 SET_SA_FAMILY(ifra.ifra_addr, AF_INET);
644 ((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o;
645 SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET);
646 ((struct sockaddr_in *) &ifra.ifra_broadaddr)->sin_addr.s_addr = h;
647 BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
648 if (ioctl(s, SIOCDIFADDR, (caddr_t) &ifra) < 0) {
649 syslog(LOG_WARNING, "ioctl(SIOCDIFADDR): %m");
656 * sifdefaultroute - assign a default route through the address given.
659 sifdefaultroute(u, g)
663 return dodefaultroute(g, 's');
667 * cifdefaultroute - delete a default route through the address given.
670 cifdefaultroute(u, g)
674 return dodefaultroute(g, 'c');
678 * dodefaultroute - talk to a routing socket to add/delete a default route.
681 dodefaultroute(g, cmd)
687 struct rt_msghdr hdr;
688 struct sockaddr_in dst;
689 struct sockaddr_in gway;
690 struct sockaddr_in mask;
693 if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
694 syslog(LOG_ERR, "%cifdefaultroute: opening routing socket: %m", cmd);
698 memset(&rtmsg, 0, sizeof(rtmsg));
699 rtmsg.hdr.rtm_type = cmd == 's'? RTM_ADD: RTM_DELETE;
700 rtmsg.hdr.rtm_flags = RTF_UP | RTF_GATEWAY;
701 rtmsg.hdr.rtm_version = RTM_VERSION;
702 rtmsg.hdr.rtm_seq = ++rtm_seq;
703 rtmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
704 rtmsg.dst.sin_len = sizeof(rtmsg.dst);
705 rtmsg.dst.sin_family = AF_INET;
706 rtmsg.gway.sin_len = sizeof(rtmsg.gway);
707 rtmsg.gway.sin_family = AF_INET;
708 rtmsg.gway.sin_addr.s_addr = g;
709 rtmsg.mask.sin_len = sizeof(rtmsg.dst);
710 rtmsg.mask.sin_family = AF_INET;
712 rtmsg.hdr.rtm_msglen = sizeof(rtmsg);
713 if (write(routes, &rtmsg, sizeof(rtmsg)) < 0) {
714 syslog(LOG_ERR, "%s default route: %m", cmd=='s'? "add": "delete");
726 * sifproxyarp - Make a proxy ARP entry for the peer.
729 struct rt_msghdr hdr;
730 struct sockaddr_inarp dst;
731 struct sockaddr_dl hwa;
735 static int arpmsg_valid;
738 sifproxyarp(unit, hisaddr)
746 * Get the hardware address of an interface on the same subnet
747 * as our local address.
749 memset(&arpmsg, 0, sizeof(arpmsg));
750 if (!get_ether_addr(hisaddr, &arpmsg.hwa)) {
751 syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
755 if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
756 syslog(LOG_ERR, "sifproxyarp: opening routing socket: %m");
760 arpmsg.hdr.rtm_type = RTM_ADD;
761 arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC;
762 arpmsg.hdr.rtm_version = RTM_VERSION;
763 arpmsg.hdr.rtm_seq = ++rtm_seq;
764 arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
765 arpmsg.hdr.rtm_inits = RTV_EXPIRE;
766 arpmsg.dst.sin_len = sizeof(struct sockaddr_inarp);
767 arpmsg.dst.sin_family = AF_INET;
768 arpmsg.dst.sin_addr.s_addr = hisaddr;
769 arpmsg.dst.sin_other = SIN_PROXY;
771 arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg
772 + arpmsg.hwa.sdl_len;
773 if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
774 syslog(LOG_ERR, "add proxy arp entry: %m");
785 * cifproxyarp - Delete the proxy ARP entry for the peer.
788 cifproxyarp(unit, hisaddr)
798 arpmsg.hdr.rtm_type = RTM_DELETE;
799 arpmsg.hdr.rtm_seq = ++rtm_seq;
801 if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
802 syslog(LOG_ERR, "sifproxyarp: opening routing socket: %m");
806 if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
807 syslog(LOG_ERR, "delete proxy arp entry: %m");
816 #else /* RTM_VERSION */
819 * sifproxyarp - Make a proxy ARP entry for the peer.
822 sifproxyarp(unit, hisaddr)
826 struct arpreq arpreq;
828 struct sockaddr_dl sdl;
832 BZERO(&arpreq, sizeof(arpreq));
835 * Get the hardware address of an interface on the same subnet
836 * as our local address.
838 if (!get_ether_addr(hisaddr, &dls.sdl)) {
839 syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
843 arpreq.arp_ha.sa_len = sizeof(struct sockaddr);
844 arpreq.arp_ha.sa_family = AF_UNSPEC;
845 BCOPY(LLADDR(&dls.sdl), arpreq.arp_ha.sa_data, dls.sdl.sdl_alen);
846 SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
847 ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
848 arpreq.arp_flags = ATF_PERM | ATF_PUBL;
849 if (ioctl(s, SIOCSARP, (caddr_t)&arpreq) < 0) {
850 syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
858 * cifproxyarp - Delete the proxy ARP entry for the peer.
861 cifproxyarp(unit, hisaddr)
865 struct arpreq arpreq;
867 BZERO(&arpreq, sizeof(arpreq));
868 SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
869 ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
870 if (ioctl(s, SIOCDARP, (caddr_t)&arpreq) < 0) {
871 syslog(LOG_WARNING, "ioctl(SIOCDARP): %m");
876 #endif /* RTM_VERSION */
880 * get_ether_addr - get the hardware address of an interface on the
881 * the same subnet as ipaddr.
886 get_ether_addr(ipaddr, hwaddr)
888 struct sockaddr_dl *hwaddr;
890 struct ifreq *ifr, *ifend, *ifp;
892 struct sockaddr_dl *dla;
895 struct ifreq ifs[MAX_IFS];
897 ifc.ifc_len = sizeof(ifs);
899 if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
900 syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
905 * Scan through looking for an interface with an Internet
906 * address on the same subnet as `ipaddr'.
908 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
909 for (ifr = ifc.ifc_req; ifr < ifend; ifr = (struct ifreq *)
910 ((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len) {
911 if (ifr->ifr_addr.sa_family == AF_INET) {
912 ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
913 strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
915 * Check that the interface is up, and not point-to-point
918 if (ioctl(s, SIOCGIFFLAGS, &ifreq) < 0)
920 if ((ifreq.ifr_flags &
921 (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK|IFF_NOARP))
922 != (IFF_UP|IFF_BROADCAST))
925 * Get its netmask and check that it's on the right subnet.
927 if (ioctl(s, SIOCGIFNETMASK, &ifreq) < 0)
929 mask = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
930 if ((ipaddr & mask) != (ina & mask))
939 syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
942 * Now scan through again looking for a link-level address
943 * for this interface.
946 for (ifr = ifc.ifc_req; ifr < ifend; ) {
947 if (strcmp(ifp->ifr_name, ifr->ifr_name) == 0
948 && ifr->ifr_addr.sa_family == AF_LINK) {
950 * Found the link-level address - copy it out
952 dla = (struct sockaddr_dl *) &ifr->ifr_addr;
953 BCOPY(dla, hwaddr, dla->sdl_len);
956 ifr = (struct ifreq *) ((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len);