public void SetInterfaceState(String ifName, uint addr, uint mask, uint gway)
        {
            IAdapter intf = FindAdapter(ifName);

            if (intf == null)
            {
                throw new Exception("SetInterfaceState");
            }
            else
            {
                HostConfiguration h = IP.GetHostConfiguration();

                // Remove existing interface binding, if any
                h.Bindings.Flush(intf);

                InterfaceIPConfiguration ipconf =
                    new InterfaceIPConfiguration(new IPv4(addr),
                                                 new IPv4(mask),
                                                 new IPv4(gway));

                if (h.Bindings.Add(intf, ipconf) == false)
                {
                    throw new Exception("SetInterfaceState");
                }
            }
        }
Example #2
0
 public bool Add(IAdapter !adapter, InterfaceIPConfiguration !ipConfig)
 {
     if (ipBindings[ipConfig.Address] != null)
     {
         return(false);
     }
     ipBindings[ipConfig.Address] = new IPBinding(adapter, ipConfig);
     AddInterfaceRoutes(ipConfig);
     return(true);
 }
Example #3
0
        private void AddInterfaceRoutes(InterfaceIPConfiguration !ipConfig)
        {
            //
            // Add subnet route
            //
            IPv4Network subnet = new IPv4Network(ipConfig.Address,
                                                 ipConfig.NetMask);

            routingTable.AddRoute(
                new RouteEntry(subnet,
                               ipConfig.Address,
                               ipConfig.Address,
                               RouteEntry.DirectlyConnectedMetric,
                               RouteEntry.InterfaceRouteTag)
                );

            //
            // Add route to gateway
            //
            routingTable.AddRoute(
                new RouteEntry(ipConfig.Gateway,
                               ipConfig.Address,
                               ipConfig.Address,
                               RouteEntry.DirectlyConnectedMetric,
                               RouteEntry.InterfaceRouteTag)
                );

            //
            // Add default route if none exists
            //
            if (routingTable.Lookup(IPv4Network.Default) == null)
            {
                routingTable.AddRoute(
                    new RouteEntry(IPv4Network.Default,
                                   ipConfig.Gateway,
                                   ipConfig.Address,
                                   RouteEntry.DefaultRouteMetric,
                                   RouteEntry.InterfaceRouteTag)
                    );
            }
        }
Example #4
0
 private void Flush(InterfaceIPConfiguration !ipConfig)
 {
     DeleteInterfaceRoutes(ipConfig);
     ipBindings.Remove(ipConfig.Address);
 }
Example #5
0
 private void DeleteInterfaceRoutes(InterfaceIPConfiguration !ipConfig)
 {
     routingTable.DeleteInterfaceRoutes(ipConfig.Address);
 }