private DhcpRequestType GetDhcpRequestType(ClientInfomation clientInfo, IPEndPoint endPoint) { DhcpRequestType res; if (clientInfo.ServerAddress != null && clientInfo.RequestAddress != null && clientInfo.ClientAddress.Equals(IPAddress.Any)) { res = DhcpRequestType.Selecting; } else { switch (clientInfo.ServerAddress) { case null when clientInfo.RequestAddress != null && clientInfo.ClientAddress.Equals(IPAddress.Any): res = DhcpRequestType.InitReboot; break; case null when clientInfo.RequestAddress == null && endPoint.Address.Equals(_settings.ServerIp): res = DhcpRequestType.ReNewing; break; case null when clientInfo.RequestAddress == null && endPoint.Address.Equals(IPAddress.Broadcast): res = DhcpRequestType.ReBinding; break; default: res = DhcpRequestType.Unknown; break; } } return(res); }
public ClientInfomation GetClientInfo() { // TODO if (IsBuiltTobeSent) { throw new Exception(); } var client = new ClientInfomation { MacAddress = packet.chaddr.ToString(packet.hlen), ClientAddress = new IPAddress(packet.ciaddr), YourAddress = new IPAddress(packet.yiaddr), TransactionID = BitConverter.ToUInt32(packet.xid, 0), RelayAgentAddress = new IPAddress(packet.giaddr), CastType = (BroadCastType)packet.flags[0] }; if (packet.options.GetOptionData(DhcpOptionType.ClientIdentifier) != null) { client.ClientIdentifier = Encoding.Default.GetString(packet.options.GetOptionData(DhcpOptionType.ClientIdentifier)); } if (packet.options.GetOptionData(DhcpOptionType.RequestedIPAddress) != null) { client.RequestAddress = new IPAddress(packet.options.GetOptionData(DhcpOptionType.RequestedIPAddress)); } if (packet.options.GetOptionData(DhcpOptionType.ServerIdentifier) != null) { client.ServerAddress = new IPAddress(packet.options.GetOptionData(DhcpOptionType.ServerIdentifier)); } return(client); }