// This service creates a full featured Dhcp server public static void Main() { // Initialize logging Logger.Initialize(new DebugLogger(), LoggerLevel.Debug); // Create the Dhcp server DhcpService DhcpServer = new DhcpService(); // set the device server name and Dhcp suffix offered to client DhcpServer.ServerName = "example"; DhcpServer.DnsSuffix = "iot.local"; // Set a Dhcp pool for the clients to use DhcpServer.PoolRange("172.16.10.100", "172.16.10.250"); DhcpServer.GatewayAddress = "172.16.10.1"; DhcpServer.SubnetMask = "255.255.255.0"; // Set a Dhcp reservation that assigns as specific ip address to a client MAC address DhcpServer.PoolReservation("172.16.10.15", "000C29027338"); // Add a NTP server option for time-a.nist.gov as client time source DhcpServer.AddOption(DhcpOption.NTPServer, IPAddress.Parse("129.6.15.28").GetAddressBytes()); // Sets interface ip address DhcpServer.InterfaceAddress = IPAddress.GetDefaultLocalAddress(); // Starts Dhcp service DhcpServer.Start(); }
/// <summary> /// Triggered when the application host is performing a graceful shutdown. /// </summary> /// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param> /// <returns>Task.</returns> /// <autogeneratedoc /> public override Task StopAsync(CancellationToken cancellationToken) { var tasks = new List <Task> { NetworkMap.StopAsync(cancellationToken), CommonNetworkServices.StopAsync(cancellationToken), DhcpService.StopAsync(cancellationToken) }; return(tasks.WaitForTasks(cancellationToken, (t) => { if (t.IsCompleted) { ServiceHostStatus = ServiceHostStatus.Stopped; } }, Logger)); }
/// <summary> /// Triggered when the application host is ready to start the service. /// </summary> /// <param name="cancellationToken">Indicates that the start process has been aborted.</param> /// <returns>Task.</returns> /// <autogeneratedoc /> public override Task StartAsync(CancellationToken cancellationToken) { ServiceHostStatus = ServiceHostStatus.StartPending; var tasks = new List <Task> { CommonNetworkServices.StartAsync(cancellationToken), DhcpService.StartAsync(cancellationToken), NetworkMap.StartAsync(cancellationToken) }; return(tasks.WaitForTasks(cancellationToken, (t) => { if (t.IsCompleted && t.Status == TaskStatus.RanToCompletion) { ServiceHostStatus = ServiceHostStatus.Running; } }, Logger)); }