-
-int sifdown (int u)
- {
- struct ifreq ifr;
-
- memset (&ifr, '\0', sizeof (ifr));
- strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
- if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0)
- {
- syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
- return 0;
- }
-
- ifr.ifr_flags &= ~IFF_UP;
- ifr.ifr_flags |= IFF_POINTOPOINT;
- if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0)
- {
- syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
- return 0;
- }
- return 1;
- }
-
-/*
- * sifaddr - Config the interface IP addresses and netmask.
- */
-
-int sifaddr (int unit, int our_adr, int his_adr, int net_mask)
- {
- struct ifreq ifr;
- struct rtentry rt;
-
- memset (&ifr, '\0', sizeof (ifr));
- memset (&rt, '\0', sizeof (rt));
-
- SET_SA_FAMILY (ifr.ifr_addr, AF_INET);
- SET_SA_FAMILY (ifr.ifr_dstaddr, AF_INET);
- SET_SA_FAMILY (ifr.ifr_netmask, AF_INET);
-
- strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
-/*
- * Set our IP address
- */
- ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = our_adr;
- if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0)
- {
- if (errno != EEXIST)
- {
- syslog (LOG_ERR, "ioctl(SIOCAIFADDR): %m");
- }
- else
- {
- syslog (LOG_WARNING, "ioctl(SIOCAIFADDR): Address already exists");
- }
- return (0);
- }
-/*
- * Set the gateway address
- */
- ((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = his_adr;
- if (ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0)
- {
- syslog (LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
- return (0);
- }
-/*
- * Set the netmask
- */
- if (net_mask != 0)
- {
- ((struct sockaddr_in *) &ifr.ifr_netmask)->sin_addr.s_addr = net_mask;
- if (ioctl(sockfd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0)
- {
- syslog (LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
- return (0);
- }
- }
-/*
- * Add the device route
- */
- SET_SA_FAMILY (rt.rt_dst, AF_INET);
- SET_SA_FAMILY (rt.rt_gateway, AF_INET);
- rt.rt_dev = ifname; /* MJC */
-
- ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = 0L;
- ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = his_adr;
- rt.rt_flags = RTF_UP | RTF_HOST;
-
- if (ioctl(sockfd, SIOCADDRT, &rt) < 0)
- {
- syslog (LOG_ERR, "ioctl(SIOCADDRT) device route: %m");
- return (0);
- }
- return 1;
- }
-
-/*
- * cifaddr - Clear the interface IP addresses, and delete routes
- * through the interface if possible.
- */
-
-int cifaddr (int unit, int our_adr, int his_adr)
- {
- struct rtentry rt;
-/*
- * Delete the route through the device
- */
- memset (&rt, '\0', sizeof (rt));
-
- SET_SA_FAMILY (rt.rt_dst, AF_INET);
- SET_SA_FAMILY (rt.rt_gateway, AF_INET);
- rt.rt_dev = ifname; /* MJC */
-
- ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = 0;
- ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = his_adr;
- rt.rt_flags = RTF_UP | RTF_HOST;
-
- if (ioctl(sockfd, SIOCDELRT, &rt) < 0)
- {
- syslog (LOG_ERR, "ioctl(SIOCDELRT) device route: %m");
- return (0);
- }
- return 1;
- }
-
-/*
- * path_to_route - determine the path to the proc file system data
- */
-