home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NETKIT-A.06 / NETKIT-A / NetKit-A-0.06 / dip337d-uri / attach.c next >
Encoding:
C/C++ Source or Header  |  1994-07-10  |  2.0 KB  |  74 lines

  1. /*
  2.  * dip        A program for handling dialup IP connecions.
  3.  *        This module handles setting the interface and
  4.  *        its routing table entry.
  5.  *
  6.  * Version:    @(#)attach.c    3.3.4    05/29/94
  7.  *
  8.  * Author:      Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  9.  *        Copyright 1988-1993 MicroWalt Corporation
  10.  *
  11.  * Modified:    Uri Blumenthal, <uri@watson.ibm.com>
  12.  *              (C) 1994
  13.  *
  14.  *        This program is free software; you can redistribute it
  15.  *        and/or  modify it under  the terms of  the GNU General
  16.  *        Public  License as  published  by  the  Free  Software
  17.  *        Foundation;  either  version 2 of the License, or  (at
  18.  *        your option) any later version.
  19.  */
  20. #include "dip.h"
  21.  
  22.  
  23. int
  24. attach(char *name, struct dip *dip)
  25. {
  26.   char buff[1024];
  27.  
  28.   /* Set up for "upping" the desired interface. */
  29.   sprintf(buff, "%s %s %s pointopoint ", _PATH_BIN_IFCONFIG,
  30.     name, inet_ntoa(dip->loc_ip));
  31.   sprintf(&buff[strlen(buff)], "%s mtu %d ",
  32.       inet_ntoa(dip->rmt_ip), dip->mtu);
  33.   if (dip->netmask[0] != '\0') 
  34.      sprintf(&buff[strlen(buff)], " netmask %s",
  35.              dip->netmask);
  36.   if (opt_v)
  37.     syslog(LOG_INFO, ">>> ATTACH \"%s\"\n", buff);
  38.   if (system(buff) != 0) return(-1);
  39.  
  40.   sprintf(buff, "%s add %s %s", _PATH_BIN_ROUTE, 
  41.       inet_ntoa(dip->rmt_ip), name);
  42.   if (opt_v)
  43.     syslog(LOG_INFO, ">>> ATTACH \"%s\"\n", buff);
  44.   if (system(buff) != 0) return(-1);
  45.  
  46.   if (dip->rtdefault == 1) {
  47.      sprintf(buff, "%s add -net default gw %s metric %1d %s", 
  48.          _PATH_BIN_ROUTE, inet_ntoa(dip->rmt_ip), 1, name);
  49.      if (opt_v)
  50.        syslog(LOG_INFO, ">>> ATTACH \"%s\"\n", buff);
  51.      if (system(buff) != 0) return(-1);
  52.   } else {
  53.     sprintf(buff, "%s add -host %s %s", _PATH_BIN_ROUTE, 
  54.         inet_ntoa(dip->loc_ip), name);
  55.     if (opt_v)
  56.       syslog(LOG_INFO, ">>> ATTACH \"%s\"\n", buff);
  57.     if (system(buff) != 0) return(-1);    
  58.   }
  59.   
  60.   return(0);
  61. }
  62.  
  63.  
  64. void
  65. detach(char *name)
  66. {
  67.   char buff[1024];
  68.  
  69.   /* Set up for "downing" the desired interface. */
  70.   sprintf(buff, "%s %s down", _PATH_BIN_IFCONFIG, name);
  71.   syslog(LOG_INFO, ">>> DETACH \"%s\"\n", buff);
  72.   (void) system(buff);
  73. }
  74.