2 * sys-linux.c - System-dependent procedures for setting up
3 * PPP interfaces on Linux systems
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.
21 #include <sys/ioctl.h>
22 #include <sys/types.h>
23 #include <sys/socket.h>
25 #include <sys/errno.h>
28 #include <sys/utsname.h>
29 #include <sys/sysmacros.h>
46 /* This is in netdevice.h. However, this compile will fail miserably if
47 you attempt to include netdevice.h because it has so many references
48 to __memcpy functions which it should not attempt to do. So, since I
49 really don't use it, but it must be defined, define it now. */
52 #define MAX_ADDR_LEN 7
56 #include <asm/types.h> /* glibc 2 conflicts with linux/types.h */
58 #include <net/if_arp.h>
59 #include <net/route.h>
60 #include <netinet/if_ether.h>
62 #include <linux/types.h>
64 #include <linux/if_arp.h>
65 #include <linux/route.h>
66 #include <linux/if_ether.h>
68 #include <netinet/in.h>
69 #include <arpa/inet.h>
71 #include <linux/ppp_defs.h>
72 #include <linux/if_ppp.h>
78 /* We can get an EIO error on an ioctl if the modem has hung up */
79 #define ok_error(num) ((num)==EIO)
81 static int tty_disc = N_TTY; /* The TTY discipline */
82 static int initfdflags = -1; /* Initial file descriptor flags for fd */
83 static int ppp_fd = -1; /* fd which is set to PPP discipline */
84 static int sock_fd = -1; /* socket for doing interface ioctls */
85 static int slave_fd = -1;
86 static int master_fd = -1;
87 static int ppp_dev_fd = -1; /* fd for /dev/ppp (new style driver) */
88 static int chindex; /* channel index (new style driver) */
90 static fd_set in_fds; /* set of fds that wait_input waits for */
91 static int max_in_fd; /* highest fd set in in_fds */
93 static int driver_version = 0;
94 static int driver_modification = 0;
95 static int driver_patch = 0;
97 static int if_is_up; /* Interface has been marked up */
98 static u_int32_t our_old_addr; /* for detecting address changes */
99 static int dynaddr_set; /* 1 if ip_dynaddr set */
100 static const int looped = 0; /* 1 if using loop */
102 static int kernel_version;
103 #define KVERSION(j,n,p) ((j)*1000000 + (n)*1000 + (p))
107 #define FLAGS_GOOD (IFF_UP | IFF_BROADCAST)
108 #define FLAGS_MASK (IFF_UP | IFF_BROADCAST | \
109 IFF_POINTOPOINT | IFF_LOOPBACK | IFF_NOARP)
111 #define SIN_ADDR(x) (((struct sockaddr_in *) (&(x)))->sin_addr.s_addr)
113 /* Prototypes for procedures local to this file. */
114 static int get_flags (int fd);
115 static void set_flags (int fd, int flags);
116 static int make_ppp_unit(void);
118 extern u_char inpacket_buf[]; /* borrowed from main.c */
121 * SET_SA_FAMILY - set the sa_family field of a struct sockaddr,
125 #define SET_SA_FAMILY(addr, family) \
126 memset ((char *) &(addr), '\0', sizeof(addr)); \
127 addr.sa_family = (family);
130 * Determine if the PPP connection should still be present.
135 /* new_fd is the fd of a tty */
136 static void set_ppp_fd (int new_fd)
138 SYSDEBUG ((LOG_DEBUG, "setting ppp_fd to %d\n", new_fd));
140 if (!new_style_driver)
144 static int still_ppp(void)
146 if (new_style_driver)
147 return !hungup && ppp_fd >= 0;
148 if (!hungup || ppp_fd == slave_fd)
151 set_ppp_fd(slave_fd);
157 /********************************************************************
159 * Functions to read and set the flags value in the device driver
162 static int get_flags (int fd)
166 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &flags) < 0) {
167 if ( ok_error (errno) )
170 fatal("ioctl(PPPIOCGFLAGS): %m");
173 SYSDEBUG ((LOG_DEBUG, "get flags = %x\n", flags));
177 /********************************************************************/
179 static void set_flags (int fd, int flags)
181 SYSDEBUG ((LOG_DEBUG, "set flags = %x\n", flags));
183 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &flags) < 0) {
184 if (! ok_error (errno) )
185 fatal("ioctl(PPPIOCSFLAGS, %x): %m", flags, errno);
189 /********************************************************************
191 * sys_init - System-dependent initialization.
198 if (new_style_driver) {
199 ppp_dev_fd = open("/dev/ppp", O_RDWR);
201 fatal("Couldn't open /dev/ppp: %m");
202 flags = fcntl(ppp_dev_fd, F_GETFL);
204 || fcntl(ppp_dev_fd, F_SETFL, flags | O_NONBLOCK) == -1)
205 warn("Couldn't set /dev/ppp to nonblock: %m");
208 /* Get an internet socket for doing socket ioctls. */
209 sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
211 fatal("Couldn't create IP socket: %m(%d)", errno);
217 /********************************************************************
219 * sys_cleanup - restore any system state we modified before exiting:
220 * mark the interface down, delete default route and/or proxy arp entry.
221 * This shouldn't call die() because it's called from die().
224 void sys_cleanup(void)
227 * Take down the device
235 /********************************************************************
237 * sys_close - Clean up in a child process before execing.
252 /********************************************************************
254 * set_kdebugflag - Define the debugging level for the kernel
257 static int set_kdebugflag (int requested_level)
259 if (new_style_driver && ifunit < 0)
261 if (ioctl(ppp_dev_fd, PPPIOCSDEBUG, &requested_level) < 0) {
262 if ( ! ok_error (errno) )
263 error("ioctl(PPPIOCSDEBUG): %m");
266 SYSDEBUG ((LOG_INFO, "set kernel debugging level to %d",
272 /********************************************************************
274 * generic_establish_ppp - Turn the fd into a ppp interface.
276 int generic_establish_ppp (int fd)
280 * Demand mode - prime the old ppp device to relinquish the unit.
282 if (!new_style_driver && looped
283 && ioctl(slave_fd, PPPIOCXFERUNIT, 0) < 0) {
284 error("ioctl(transfer ppp unit): %m");
289 if (new_style_driver) {
290 /* Open another instance of /dev/ppp and connect the channel to it */
293 if (ioctl(fd, PPPIOCGCHAN, &chindex) == -1) {
294 error("Couldn't get channel number: %m");
297 dbglog("using channel %d", chindex);
298 fd = open("/dev/ppp", O_RDWR);
300 error("Couldn't reopen /dev/ppp: %m");
303 if (ioctl(fd, PPPIOCATTCHAN, &chindex) < 0) {
304 error("Couldn't attach to channel %d: %m", chindex);
307 flags = fcntl(fd, F_GETFL);
308 if (flags == -1 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
309 warn("Couldn't set /dev/ppp (channel) to nonblock: %m");
314 if (!looped && !multilink) {
316 * Create a new PPP unit.
318 if (make_ppp_unit() < 0)
323 set_flags(ppp_dev_fd, get_flags(ppp_dev_fd) & ~SC_LOOP_TRAFFIC);
327 if (ioctl(fd, PPPIOCCONNECT, &ifunit) < 0) {
328 error("Couldn't attach to PPP unit %d: %m", ifunit);
336 * Old-style driver: find out which interface we were given.
339 if (ioctl(fd, PPPIOCGUNIT, &x) < 0) {
340 if (ok_error (errno))
342 fatal("ioctl(PPPIOCGUNIT): %m(%d)", errno);
344 /* Check that we got the same unit again. */
345 if (looped && x != ifunit)
346 fatal("transfer_ppp failed: wanted unit %d, got %d", ifunit, x);
350 * Fetch the initial file flags and reset blocking mode on the file.
352 initfdflags = fcntl(fd, F_GETFL);
353 if (initfdflags == -1 ||
354 fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
355 if ( ! ok_error (errno))
356 warn("Couldn't set device to non-blocking mode: %m");
362 * Enable debug in the driver if requested.
365 set_kdebugflag (kdebugflag);
367 SYSDEBUG ((LOG_NOTICE, "Using version %d.%d.%d of PPP driver",
368 driver_version, driver_modification, driver_patch));
375 if (ioctl(fd, TIOCSETD, &tty_disc) < 0 && !ok_error(errno))
376 warn("Couldn't reset tty to normal line discipline: %m");
380 /********************************************************************
382 * generic_disestablish_ppp - Restore device components to normal
383 * operation, and reconnect the ppp unit to the loopback if in demand
384 * mode. This shouldn't call die() because it's called from die().
386 void generic_disestablish_ppp(int dev_fd){
387 /* Finally detach the device */
390 if (new_style_driver) {
393 if (!looped && ifunit >= 0 && ioctl(ppp_dev_fd, PPPIOCDETACH) < 0)
394 error("Couldn't release PPP unit: %m");
396 remove_fd(ppp_dev_fd);
401 * make_ppp_unit - make a new ppp unit for ppp_dev_fd.
402 * Assumes new_style_driver.
404 static int make_ppp_unit()
409 x = ioctl(ppp_dev_fd, PPPIOCNEWUNIT, &ifunit);
410 if (x < 0 && req_unit >= 0 && errno == EEXIST) {
411 warn("Couldn't allocate PPP unit %d as it is already in use");
413 x = ioctl(ppp_dev_fd, PPPIOCNEWUNIT, &ifunit);
416 error("Couldn't create new ppp unit: %m");
420 /********************************************************************
422 * clean_check - Fetch the flags for the device and generate
423 * appropriate error messages.
425 void clean_check(void)
431 if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) == 0) {
433 switch (~x & (SC_RCV_B7_0|SC_RCV_B7_1|SC_RCV_EVNP|SC_RCV_ODDP)) {
435 s = "all had bit 7 set to 1";
439 s = "all had bit 7 set to 0";
443 s = "all had odd parity";
447 s = "all had even parity";
452 warn("Receive serial link is not 8-bit clean:");
453 warn("Problem: %s", s);
459 /********************************************************************
461 * output - Output PPP packet.
464 void output (int unit, unsigned char *p, int len)
470 dbglog("sent %P", p, len);
472 if (len < PPP_HDRLEN)
474 if (new_style_driver) {
477 proto = (p[0] << 8) + p[1];
478 if (ifunit >= 0 && !(proto >= 0xc000 || proto == PPP_CCPFRAG))
481 if (write(fd, p, len) < 0) {
482 if (errno == EWOULDBLOCK || errno == ENOBUFS
483 || errno == ENXIO || errno == EIO || errno == EINTR)
484 warn("write: warning: %m (%d)", errno);
486 error("write: %m (%d)", errno);
490 /********************************************************************
492 * wait_input - wait until there is data available,
493 * for the length of time specified by *timo (indefinite
497 void wait_input(struct timeval *timo)
504 n = select(max_in_fd + 1, &ready, NULL, &exc, timo);
505 if (n < 0 && errno != EINTR)
506 fatal("select: %m(%d)", errno);
510 * add_fd - add an fd to the set that wait_input waits for.
520 * remove_fd - remove an fd from the set that wait_input waits for.
522 void remove_fd(int fd)
528 /********************************************************************
530 * read_packet - get a PPP packet from the serial device.
533 int read_packet (unsigned char *buf)
537 len = PPP_MRU + PPP_HDRLEN;
538 if (new_style_driver) {
539 *buf++ = PPP_ALLSTATIONS;
545 nr = read(ppp_fd, buf, len);
546 if (nr < 0 && errno != EWOULDBLOCK && errno != EIO && errno != EINTR)
548 if (nr < 0 && errno == ENXIO)
551 if (nr < 0 && new_style_driver && ifunit >= 0) {
552 /* N.B. we read ppp_fd first since LCP packets come in there. */
553 nr = read(ppp_dev_fd, buf, len);
554 if (nr < 0 && errno != EWOULDBLOCK && errno != EIO && errno != EINTR)
555 error("read /dev/ppp: %m");
556 if (nr < 0 && errno == ENXIO)
559 return (new_style_driver && nr > 0)? nr+2: nr;
563 * netif_set_mtu - set the MTU on the PPP network interface.
566 netif_set_mtu(int unit, int mtu)
570 SYSDEBUG ((LOG_DEBUG, "netif_set_mtu: mtu = %d\n", mtu));
572 memset (&ifr, '\0', sizeof (ifr));
573 strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
576 if (ifunit >= 0 && ioctl(sock_fd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
577 fatal("ioctl(SIOCSIFMTU): %m");
580 /********************************************************************
582 * ccp_test - ask kernel whether a given compression method
583 * is acceptable for use.
586 int ccp_test (int unit, u_char *opt_ptr, int opt_len, int for_transmit)
588 struct ppp_option_data data;
590 memset (&data, '\0', sizeof (data));
592 data.length = opt_len;
593 data.transmit = for_transmit;
595 if (ioctl(ppp_dev_fd, PPPIOCSCOMPRESS, (caddr_t) &data) >= 0)
598 return (errno == ENOBUFS)? 0: -1;
601 /********************************************************************
603 * ccp_flags_set - inform kernel about the current state of CCP.
606 void ccp_flags_set (int unit, int isopen, int isup)
609 int x = get_flags(ppp_dev_fd);
610 x = isopen? x | SC_CCP_OPEN : x &~ SC_CCP_OPEN;
611 x = isup? x | SC_CCP_UP : x &~ SC_CCP_UP;
612 set_flags (ppp_dev_fd, x);
616 /********************************************************************
618 * get_idle_time - return how long the link has been idle.
625 return ioctl(ppp_dev_fd, PPPIOCGIDLE, ip) >= 0;
628 /********************************************************************
630 * get_ppp_stats - return statistics for the link.
633 get_ppp_stats(u, stats)
635 struct pppd_stats *stats;
637 struct ifpppstatsreq req;
639 memset (&req, 0, sizeof (req));
641 req.stats_ptr = (caddr_t) &req.stats;
642 strlcpy(req.ifr__name, ifname, sizeof(req.ifr__name));
643 if (ioctl(sock_fd, SIOCGPPPSTATS, &req) < 0) {
644 error("Couldn't get PPP statistics: %m");
647 stats->bytes_in = req.stats.p.ppp_ibytes;
648 stats->bytes_out = req.stats.p.ppp_obytes;
652 /********************************************************************
654 * ccp_fatal_error - returns 1 if decompression was disabled as a
655 * result of an error detected after decompression of a packet,
656 * 0 otherwise. This is necessary because of patent nonsense.
659 int ccp_fatal_error (int unit)
661 int x = get_flags(ppp_dev_fd);
663 return x & SC_DC_FERROR;
666 /********************************************************************
668 * Return user specified netmask, modified by any mask we might determine
669 * for address `addr' (in network byte order).
670 * Here we scan through the system's list of interfaces, looking for
671 * any non-point-to-point interfaces which might appear to be on the same
672 * network as `addr'. If we find any, we OR in their netmask to the
673 * user-specified netmask.
676 u_int32_t GetMask (u_int32_t addr)
678 u_int32_t mask, nmask, ina;
679 struct ifreq *ifr, *ifend, ifreq;
681 struct ifreq ifs[MAX_IFS];
685 if (IN_CLASSA(addr)) /* determine network mask for address class */
686 nmask = IN_CLASSA_NET;
687 else if (IN_CLASSB(addr))
688 nmask = IN_CLASSB_NET;
690 nmask = IN_CLASSC_NET;
692 /* class D nets are disallowed by bad_ip_adrs */
693 mask = netmask | htonl(nmask);
695 * Scan through the system's network interfaces.
697 ifc.ifc_len = sizeof(ifs);
699 if (ioctl(sock_fd, SIOCGIFCONF, &ifc) < 0) {
700 if ( ! ok_error ( errno ))
701 warn("ioctl(SIOCGIFCONF): %m(%d)", errno);
705 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
706 for (ifr = ifc.ifc_req; ifr < ifend; ifr++) {
708 * Check the interface's internet address.
710 if (ifr->ifr_addr.sa_family != AF_INET)
712 ina = SIN_ADDR(ifr->ifr_addr);
713 if (((ntohl(ina) ^ addr) & nmask) != 0)
716 * Check that the interface is up, and not point-to-point nor loopback.
718 strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
719 if (ioctl(sock_fd, SIOCGIFFLAGS, &ifreq) < 0)
722 if (((ifreq.ifr_flags ^ FLAGS_GOOD) & FLAGS_MASK) != 0)
725 * Get its netmask and OR it into our mask.
727 if (ioctl(sock_fd, SIOCGIFNETMASK, &ifreq) < 0)
729 mask |= SIN_ADDR(ifreq.ifr_addr);
735 /********************************************************************
737 * ppp_available - check whether the system has any ppp interfaces
738 * (in fact we check whether we can do an ioctl on ppp0).
741 int ppp_available(void)
743 struct utsname utsname; /* for the kernel version */
744 int osmaj, osmin, ospatch;
746 /* get the kernel version now, since we are called before sys_init */
748 osmaj = osmin = ospatch = 0;
749 sscanf(utsname.release, "%d.%d.%d", &osmaj, &osmin, &ospatch);
750 kernel_version = KVERSION(osmaj, osmin, ospatch);
752 /* XXX should get from driver */
754 driver_modification = 4;
760 /********************************************************************
762 * sifvjcomp - config tcp header compression
765 int sifvjcomp (int u, int vjcomp, int cidcomp, int maxcid)
767 u_int x = get_flags(ppp_dev_fd);
770 if (ioctl (ppp_dev_fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
771 if (! ok_error (errno))
772 error("ioctl(PPPIOCSMAXCID): %m(%d)", errno);
777 x = vjcomp ? x | SC_COMP_TCP : x &~ SC_COMP_TCP;
778 x = cidcomp ? x & ~SC_NO_TCP_CCID : x | SC_NO_TCP_CCID;
779 set_flags (ppp_dev_fd, x);
784 /********************************************************************
786 * sifup - Config the interface up and enable IP packets to pass.
793 memset (&ifr, '\0', sizeof (ifr));
794 strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
795 if (ioctl(sock_fd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
796 if (! ok_error (errno))
797 error("ioctl (SIOCGIFFLAGS): %m(%d)", errno);
801 ifr.ifr_flags |= (IFF_UP | IFF_POINTOPOINT);
802 if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
803 if (! ok_error (errno))
804 error("ioctl(SIOCSIFFLAGS): %m(%d)", errno);
812 /********************************************************************
814 * sifdown - Disable the indicated protocol and config the interface
815 * down if there are no remaining protocols.
822 if (if_is_up && --if_is_up > 0)
825 memset (&ifr, '\0', sizeof (ifr));
826 strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
827 if (ioctl(sock_fd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
828 if (! ok_error (errno))
829 error("ioctl (SIOCGIFFLAGS): %m(%d)", errno);
833 ifr.ifr_flags &= ~IFF_UP;
834 ifr.ifr_flags |= IFF_POINTOPOINT;
835 if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
836 if (! ok_error (errno))
837 error("ioctl(SIOCSIFFLAGS): %m(%d)", errno);
843 /********************************************************************
845 * sifaddr - Config the interface IP addresses and netmask.
848 int sifaddr (int unit, u_int32_t our_adr, u_int32_t his_adr,
854 memset (&ifr, '\0', sizeof (ifr));
855 memset (&rt, '\0', sizeof (rt));
857 SET_SA_FAMILY (ifr.ifr_addr, AF_INET);
858 SET_SA_FAMILY (ifr.ifr_dstaddr, AF_INET);
859 SET_SA_FAMILY (ifr.ifr_netmask, AF_INET);
861 strlcpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
865 SIN_ADDR(ifr.ifr_addr) = our_adr;
866 if (ioctl(sock_fd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
867 if (errno != EEXIST) {
868 if (! ok_error (errno))
869 error("ioctl(SIOCSIFADDR): %m(%d)", errno);
872 warn("ioctl(SIOCSIFADDR): Address already exists");
877 * Set the gateway address
879 SIN_ADDR(ifr.ifr_dstaddr) = his_adr;
881 if (ioctl(sock_fd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
882 if (! ok_error (errno))
883 error("ioctl(SIOCSIFDSTADDR): %m(%d)", errno);
888 * For recent kernels, force the netmask to 255.255.255.255.
890 if (kernel_version >= KVERSION(2,1,16))
893 SIN_ADDR(ifr.ifr_netmask) = net_mask;
894 if (ioctl(sock_fd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
895 if (! ok_error (errno))
896 error("ioctl(SIOCSIFNETMASK): %m(%d)", errno);
901 * Add the device route
903 if (kernel_version < KVERSION(2,1,16)) {
904 SET_SA_FAMILY (rt.rt_dst, AF_INET);
905 SET_SA_FAMILY (rt.rt_gateway, AF_INET);
908 SIN_ADDR(rt.rt_gateway) = 0L;
909 SIN_ADDR(rt.rt_dst) = his_adr;
910 rt.rt_flags = RTF_UP | RTF_HOST;
912 if (kernel_version > KVERSION(2,1,0)) {
913 SET_SA_FAMILY (rt.rt_genmask, AF_INET);
914 SIN_ADDR(rt.rt_genmask) = -1L;
917 if (ioctl(sock_fd, SIOCADDRT, &rt) < 0) {
918 if (! ok_error (errno))
919 error("ioctl(SIOCADDRT) device route: %m(%d)", errno);
924 /* set ip_dynaddr in demand mode if address changes */
925 if (demand && tune_kernel && !dynaddr_set
926 && our_old_addr && our_old_addr != our_adr) {
927 /* set ip_dynaddr if possible */
931 path = "/proc/sys/net/ipv4/ip_dynaddr";
932 if (path != 0 && (fd = open(path, O_WRONLY)) >= 0) {
933 if (write(fd, "1", 1) != 1)
934 error("Couldn't enable dynamic IP addressing: %m");
937 dynaddr_set = 1; /* only 1 attempt */
944 /********************************************************************
946 * cifaddr - Clear the interface IP addresses, and delete routes
947 * through the interface if possible.
950 int cifaddr (int unit, u_int32_t our_adr, u_int32_t his_adr)
954 create_msg(BCM_PPPOE_CLIENT_STATE_DOWN);
955 syslog(LOG_CRIT,"Clear IP addresses. PPP connection DOWN.\n");
957 if (kernel_version < KVERSION(2,1,16)) {
959 * Delete the route through the device
962 memset (&rt, '\0', sizeof (rt));
964 SET_SA_FAMILY (rt.rt_dst, AF_INET);
965 SET_SA_FAMILY (rt.rt_gateway, AF_INET);
968 SIN_ADDR(rt.rt_gateway) = 0;
969 SIN_ADDR(rt.rt_dst) = his_adr;
970 rt.rt_flags = RTF_UP | RTF_HOST;
972 if (kernel_version > KVERSION(2,1,0)) {
973 SET_SA_FAMILY (rt.rt_genmask, AF_INET);
974 SIN_ADDR(rt.rt_genmask) = -1L;
977 if (ioctl(sock_fd, SIOCDELRT, &rt) < 0 && errno != ESRCH) {
978 if (still_ppp() && ! ok_error (errno))
979 error("ioctl(SIOCDELRT) device route: %m(%d)", errno);
984 /* This way it is possible to have an IPX-only or IPv6-only interface */
985 memset(&ifr, 0, sizeof(ifr));
986 SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
987 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
989 if (ioctl(sock_fd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
990 if (! ok_error (errno)) {
991 error("ioctl(SIOCSIFADDR): %m(%d)", errno);
996 our_old_addr = our_adr;
1001 /********************************************************************
1003 * sifnpmode - Set the mode for handling packets for a given NP.
1007 sifnpmode(u, proto, mode)
1014 npi.protocol = proto;
1016 if (ioctl(ppp_dev_fd, PPPIOCSNPMODE, (caddr_t) &npi) < 0) {
1017 if (! ok_error (errno))
1018 error("ioctl(PPPIOCSNPMODE, %d, %d): %m (%d)",
1019 proto, mode, errno);
1026 * Use the hostname as part of the random number seed.
1035 for (p = hostname; *p != 0; ++p)