static void Main(string[] args) { //Arrange string IPAdd = "10.168.1.1", Mask = "0", DomainName = "cetitec.com";//Operator chooses this too value for his local machine. bool V_DRequest, IpAddFormat; bool V_Offer; DHCP_Client cDhcp; DHCP_Server sDhcp; sDhcp = new DHCP_Server(); cDhcp = new DHCP_Client(); //Act IpAddFormat = cDhcp.CheckIPValidFormat(IPAdd); cDhcp = new DHCP_Client(IpAddFormat, IPAdd); V_DRequest = cDhcp.DhcpClient_Discover_Request(sDhcp, Mask, IpAddFormat, DomainName); V_Offer = sDhcp.DhcpServer_Offer(V_DRequest); //Assert... sDhcp.DHCP_Ack_Message(V_Offer); }
//This Method makes the DHCP client broadcast a message of request of an IP address to the DHCP Server public bool DhcpClient_Discover_Request(DHCP_Server DataServer, string MacId, bool IpValidation, string DomainName) { string str = string.Empty; bool DHCP_Discover; // DHCP_Discover=true ---> DHCP client is looking for DHCP server to lease an IP address // DHCP_Discover= false---> DHCP clien information is not valide to lease an IP address from a Server //This condition verifies that the MAC used is the default value 0, the Ip address format is verified and the domain name: cetitec.com if (MacId.StartsWith(MacMask) == true && IpValidation == true && (DomainName.Equals("cetitec.com") == true)) { DHCP_Discover = true; DataServer.dData.MyIP = NetCard; // This informs the DHCP Server, the IP address of the DHCP client which //broadcasted the message of request str = "IP requested for Mac: " + MacId; } //This condition informs the operator that the MAC is not the correct one else if (MacId.StartsWith(MacMask) == false && IpValidation == true) { DHCP_Discover = false; str = "Mac: " + MacId + " is not part of the mask, you should chooose a subnet mask = 0!"; } //This condition informs the operator that the Domain name is not the correct one which should be cetitec.com. else if ((DomainName.Equals("cetitec.com") == false)) { DHCP_Discover = false; Console.WriteLine("Make sure that the DomainName is: cetitec.com \n"); } //This condition informs the operator that something is wrong with the IP address he entered earlier else { DHCP_Discover = false; Console.WriteLine("Make sure that the IP address has Four values separated by dots '.'\n"); } Console.WriteLine(str); return(DHCP_Discover); }