示例#1
0
        /// <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());
        }