public override string ToString() { string response = "CID: " + this.ClientId.ToString() + " | SESID: " + this.SessionId.ToHexString("0x") + " | IP: " + this.Address.ToString() + " | OWNER: " + this.Owner.ToString() + " | NAME: " + ByteUtility.GetSafeString(_hostName) + " | EXPN: " + this.Expiration.ToLocalTime().ToString() + " | STATE: " + LeaseStateString.GetName(_state); return(response); }
/// <summary> /// Converts dhcp message into string object. /// </summary> public override String ToString() { StringBuilder sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine(" DHCP PACKET"); sb.AppendLine(String.Concat(" Message Timestamp : ", this.Timestamp.ToLocalTime().ToString())); sb.AppendLine(String.Concat(" Message Type (op) : ", OperationString.GetName(this.Operation))); sb.AppendLine(String.Concat(" Hardware Type (htype) : ", HardwareString.GetName(this.Hardware))); sb.AppendLine(String.Concat(" Hops (hops) : ", ByteUtility.PrintByte(this.Hops))); sb.AppendLine(String.Concat(" Transaction Id (Xid) : ", this.SessionId.ToHexString("0x"))); sb.AppendLine(String.Concat(" Seconds Elapsed (secs) : ", this.SecondsElapsed.ToString())); sb.AppendLine(String.Concat(" Flags (flags) : 0x", ByteUtility.PrintBytes(this._flags))); sb.AppendLine(String.Concat(" Is Broadcast (flags) : ", this.IsBroadcast.ToString())); sb.AppendLine(String.Concat(" Client Address (ciaddr) : ", this.ClientAddress.ToString())); sb.AppendLine(String.Concat(" Assigned Address (yiaddr) : ", this.AssignedAddress.ToString())); sb.AppendLine(String.Concat(" Next Server Address (siaddr) : ", this.NextServerAddress.ToString())); sb.AppendLine(String.Concat(" Relay Agent Address (giaddr) : ", this.RelayAgentAddress.ToString())); sb.AppendLine(String.Concat(" Hardware Address (chaddr) : ", this.ClientHardwareAddress.ToString())); sb.AppendLine(String.Concat(" Server Host Name (sname) : ", ByteUtility.GetSafeString(this.ServerName))); sb.AppendLine(String.Concat(" Boot File Name (file) : ", ByteUtility.GetSafeString(this.BootFileName))); sb.AppendLine(String.Concat(" Option (Message Type) : ", MessageTypeString.GetName((MessageType)this.GetOptionData(DhcpOption.DhcpMessageType)[0]))); sb.AppendLine(String.Concat(" Option (Client Id) : ", ByteUtility.PrintSafeBytes(this.GetOptionData(DhcpOption.ClientId)))); sb.AppendLine(String.Concat(" Option (Host Name) : ", ByteUtility.GetSafeString(this.GetOptionData(DhcpOption.Hostname)))); sb.AppendLine(String.Concat(" Option (Address Request) : ", new InternetAddress(this.GetOptionData(DhcpOption.AddressRequest)).ToString())); sb.AppendLine(String.Concat(" Option (Server Identifier) : ", new InternetAddress(this.GetOptionData(DhcpOption.ServerIdentifier)).ToString())); sb.AppendLine(String.Concat(" Option (Dhcp Message) : ", ByteUtility.GetSafeString(this.GetOptionData(DhcpOption.DhcpMessage)))); foreach (DhcpOption option in _options.Keys) { byte optionId = (Byte)option; byte[] optionValue = (byte[])_options[option]; sb.AppendLine(String.Concat(" Option (Binary) : ", ByteUtility.PrintByte(optionId) + " => " + ByteUtility.PrintBytes(optionValue, false))); } sb.AppendLine(); return(sb.ToString()); }
/// <summary> /// Gets the DHCP option string. /// </summary> /// <param name="dhcpOption">The DHCP option.</param> /// <param name="dhcpOptionValue">The DHCP option value.</param> /// <param name="dhcpRequestListFormat">The DHCP request list format.</param> /// <param name="logger">The logger.</param> /// <returns>System.String.</returns> /// <autogeneratedoc /> public static string GetDhcpOptionString( DhcpOption dhcpOption, byte[] dhcpOptionValue, DhcpRequestListFormat dhcpRequestListFormat = DhcpRequestListFormat.StringNewlineIndentedSeparated, IPureLogger logger = null ) { try { if (dhcpOptionValue == null) { return("Null"); } if (dhcpOption == DhcpOption.ParamReqList) { return(GetDhcpRequestListString(dhcpOptionValue, dhcpRequestListFormat, logger)); } switch (DhcpOptionTypes[dhcpOption]) { case DhcpOptionType.IPAddress: return(new IPAddress(dhcpOptionValue).ToString()); case DhcpOptionType.PhysicalAddressSkip1DashString: return(new PhysicalAddress(dhcpOptionValue.Skip(1).ToArray()).ToDashString()); case DhcpOptionType.PhysicalAddressSkip1ColonString: return(new PhysicalAddress(dhcpOptionValue.Skip(1).ToArray()).ToColonString()); case DhcpOptionType.PhysicalAddressDashString: return(new PhysicalAddress(dhcpOptionValue).ToDashString()); case DhcpOptionType.PhysicalAddressColonString: return(new PhysicalAddress(dhcpOptionValue).ToColonString()); case DhcpOptionType.MessageTypeString: return(MessageTypeString.GetName((MessageType)dhcpOptionValue[0])); case DhcpOptionType.SafeString: return(ByteUtility.GetSafeString(dhcpOptionValue)); case DhcpOptionType.SafeBytes: return(ByteUtility.PrintSafeBytes(dhcpOptionValue)); case DhcpOptionType.UInt16: return(BitConverter.ToUInt16(dhcpOptionValue, 0).ToString()); case DhcpOptionType.UInt32: return(BitConverter.ToUInt32(dhcpOptionValue, 0).ToString()); case DhcpOptionType.UInt16Network: return(IPAddress.NetworkToHostOrder(BitConverter.ToUInt16(dhcpOptionValue, 0)).ToString()); case DhcpOptionType.UInt32Network: return(IPAddress.NetworkToHostOrder(BitConverter.ToUInt32(dhcpOptionValue, 0)).ToString()); } } catch (Exception ex) { logger?.LogError(ex, "Invalid DhcpOption: {dhcpOption}", dhcpOption); } return(string.Empty); }
/// <summary> /// Send NAK message back to remote client. /// </summary> private void SendNak(DhcpMessageEventArgs args) { // Set options args.ResponseMessage.AddOption(DhcpOption.DhcpMessageType, (Byte)MessageType.Nak); Logger.WriteInfo(this, "NAK (Negative Acknowledge) for message id " + args.RequestMessage.SessionId.ToHexString("0x") + " sent on thread(#" + Thread.CurrentThread.ManagedThreadId + ")" + " with option message: " + ByteUtility.GetSafeString(args.ResponseMessage.GetOptionData(DhcpOption.DhcpMessage))); this.SendReply(args); }