-int sifdown (int u)
- {
- struct ifreq 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;
-
- 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
- */
- 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, 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
- */
-
-FILE *route_fd = (FILE *) 0;
-static char route_buffer [100];
-
-static char *path_to_route (void);
-static int open_route_table (void);
-static void close_route_table (void);
-static int read_route_table (struct rtentry *rt);
-static int defaultroute_exists (void);
-
-/*
- * path_to_route - find the path to the route tables in the proc file system
- */
-
-static char *path_to_route (void)
- {
- struct mntent *mntent;
- FILE *fp;
-
- fp = fopen (MOUNTED, "r");
- if (fp != 0)
- {
- mntent = getmntent (fp);
- while (mntent != (struct mntent *) 0)
- {
- if (strcmp (mntent->mnt_type, MNTTYPE_IGNORE) != 0)
- {
- if (strcmp (mntent->mnt_type, "proc") == 0)
- {
- strncpy (route_buffer, mntent->mnt_dir,
- sizeof (route_buffer)-10);
- route_buffer [sizeof (route_buffer)-10] = '\0';
- strcat (route_buffer, "/net/route");
-
- fclose (fp);
- return (route_buffer);
- }
- }
- mntent = getmntent (fp);
- }
- fclose (fp);
- }
-
- syslog (LOG_ERR, "proc file system not mounted");
- return 0;
- }