/[pengfork]/pengfork/src/iptunnel/init.c
ViewVC logotype

Diff of /pengfork/src/iptunnel/init.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by chupa, Thu Sep 12 12:45:35 2002 UTC revision 1.6 by chupa, Sat Oct 19 12:11:59 2002 UTC
# Line 21  Line 21 
21   */   */
22    
23  #include <sys/types.h>  #include <sys/types.h>
24    #include <sys/socket.h>
25    #include <netinet/in.h>
26    #include <arpa/inet.h>
27  #include <stdlib.h>  #include <stdlib.h>
28  #include <string.h>  #include <string.h>
29    
# Line 34  Line 37 
37  #include "protocol.h"  #include "protocol.h"
38    
39  #include "iptunnel/init.h"  #include "iptunnel/init.h"
40    #include "iptunnel/dns.h"
41  #include "iptunnel/vjcompress.h"  #include "iptunnel/vjcompress.h"
42  #include "iptunnel/aol2cli.h"  #include "iptunnel/aol2cli.h"
43  #include "iptunnel/cli2aol.h"  #include "iptunnel/cli2aol.h"
# Line 41  Line 45 
45  buffer_t *acout, *ifout;  buffer_t *acout, *ifout;
46    
47  int ipnum = 0;  int ipnum = 0;
48  int mtu = 1450;  int ip_recv = 0;
49    
50  struct vjcompress vj_comp;  struct vjcompress vj_comp;
51  #define MAX_VJHEADER 16         /* Maximum size of compressed header */  #define MAX_VJHEADER 16         /* Maximum size of compressed header */
# Line 53  const struct engine_functions ip_tunnel_ Line 57  const struct engine_functions ip_tunnel_
57    get_ip_client,    get_ip_client,
58    NULL,    NULL,
59    NULL,    NULL,
60    NULL    destroy_iface
61  };  };
62    
63    
# Line 82  ip_tunnel_config (token, data, data_size Line 86  ip_tunnel_config (token, data, data_size
86       char *data;       char *data;
87       size_t data_size;       size_t data_size;
88  {  {
89    struct ip_config_reply1 *config1;    struct ip_config_header *cfg_hdr;
90    struct ip_config_reply2 *config2;    void *cfg_data;
91    u_int8_t *flags;    struct in_addr address;
92    in_addr_t *address;    struct in_addr dns;
93    in_addr_t *dns_address;    struct in_addr net;
94      int mask;
95      int mtu;
96    char hostname[255];    char hostname[255];
97      char *domain;
98    int len;    int len;
99      int nparsed = 0;
100    
101    flags = (u_int8_t *) data;    while(nparsed<data_size)
   config1 = (struct ip_config_reply1 *) (data + sizeof(*flags));  
   config2 = (struct ip_config_reply2 *) (data + sizeof(*flags));  
   if(*flags == 7)  
102      {      {
103        address = &config2->address;        cfg_hdr = (struct ip_config_header *) (data + nparsed);
104        dns_address = &config2->dns_address;        cfg_data = data + nparsed + sizeof(struct ip_config_header);
105          switch(cfg_hdr->type)
106            {
107            case TYPE_IP_ADDR:
108            address.s_addr = *((in_addr_t *)cfg_data);
109            log (LOG_INFO, "IP address: %s\n", inet_ntoa(address));
110            break;
111            case TYPE_DNS_ADDR:
112            dns.s_addr = *((in_addr_t *)cfg_data);
113            log (LOG_INFO, "DNS server: %s\n", inet_ntoa(dns));
114            break;
115            case TYPE_MTU:
116            mtu= ntohs(*((u_int16_t *)cfg_data));
117            log (LOG_INFO, "MTU: %d\n", mtu);
118            break;
119            case TYPE_HOSTNAME:
120            len = cfg_hdr->length;
121            if (len > sizeof(hostname))
122              len = sizeof(hostname);
123            strncpy (hostname, cfg_data, len);
124            hostname[len] = '\0';
125            domain = strchr(hostname,'.');
126            if(domain) domain++;
127    
128            log (LOG_INFO, "Hostname: %s\n", hostname);
129            if(domain)
130              log (LOG_INFO, "Domain: %s\n", domain);
131            break;
132            case TYPE_SUBNET:
133            mask = *((u_int8_t *)cfg_data);
134            net.s_addr = 0;
135            memcpy(&net.s_addr, cfg_data+1, cfg_hdr->length-1);
136            /* Need 2 instructions because inet_ntoa use a static buffer */
137            log (LOG_INFO, "Subnet: %s/", inet_ntoa(net));
138            log (LOG_INFO, "%s\n", inet_ntoa(netmask(mask)));
139            break;
140            }
141          nparsed += sizeof(struct ip_config_header) + cfg_hdr->length;
142      }      }
   else  
     {  
       address = &config1->address;  
       dns_address = &config1->dns_address;  
     }  
   *address = ntohl (*address);  
   *dns_address = ntohl (*dns_address);  
143    
144    len = config1->hostname_len;    set_dns(domain, dns);
145    if (len > sizeof(hostname))    launch_ip_up (PARAM_INTERFACE_NAME, address, dns, domain, mtu);
     len = sizeof(hostname);  
   strncpy (hostname, &config1->hostname, len);  
   hostname[len] = '\0';  
   log (LOG_INFO, "IP address: %d.%d.%d.%d\n",  
        *address >> 24 & 0xff,  
        *address >> 16 & 0xff,  
        *address >> 8 & 0xff, *address & 0xff);  
   log (LOG_INFO, "DNS address: %d.%d.%d.%d\n",  
        *dns_address >> 24 & 0xff,  
        *dns_address >> 16 & 0xff,  
        *dns_address >> 8 & 0xff, *dns_address & 0xff);  
   log (LOG_INFO, "Hostname: %s\n", hostname);  
   
   launch_ip_up (PARAM_INTERFACE_NAME,  
                 *address, 0xffffffff,  
                 *address & 0xffff0000,  
                 *address | 0x0000ffff, *address);  
146    
147    vj_compress_init (&vj_comp, -1);    vj_compress_init (&vj_comp, -1);
148    
# Line 133  ip_tunnel_config (token, data, data_size Line 151  ip_tunnel_config (token, data, data_size
151    fdo_register ( TOKEN ("yc"), get_ip_aol);    fdo_register ( TOKEN ("yc"), get_ip_aol);
152  }  }
153    
154    struct in_addr
155    netmask(bits)
156         int bits;
157    {
158      unsigned long ret=0;
159      
160      ret = ~( ( 1 << (32 - bits) ) - 1 );
161    
162      return (struct in_addr) { htonl(ret) };
163    }
164    
165  void  void
166  init_iface (in, out)  init_iface (in, out)
167       buffer_t *in;       buffer_t *in;
168       buffer_t *out;       buffer_t *out;
169  {  {
170    ifout = out;    ifout = out;
171    create_buffer(in,2*mtu);    create_buffer(in,2*1500);
172    create_buffer(out,2*mtu);    create_buffer(out,2*1500);
173  }  }
174    
175    int
176    destroy_iface (in, out)
177         buffer_t *in;
178         buffer_t *out;
179    {
180      launch_ip_down (PARAM_INTERFACE_NAME);
181      unset_dns();
182      destroy_buffer(in);
183      destroy_buffer(out);
184      return 1;
185    }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26