Example #1
0
        public override byte[] ConvertToByte(bool reverseByteOrder, Action <Exception> ActionOnException)
        {
            List <byte> ret = new List <byte>();

            if (Comment != null)
            {
                byte[] comentValue = UTF8Encoding.UTF8.GetBytes(Comment);
                if (comentValue.Length <= UInt16.MaxValue)
                {
                    ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.CommentCode, comentValue, reverseByteOrder, ActionOnException));
                }
            }

            if (Name != null)
            {
                byte[] nameValue = UTF8Encoding.UTF8.GetBytes(Name);
                if (nameValue.Length <= UInt16.MaxValue)
                {
                    ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.NameCode, nameValue, reverseByteOrder, ActionOnException));
                }
            }

            if (Description != null)
            {
                byte[] descValue = UTF8Encoding.UTF8.GetBytes(Description);
                if (descValue.Length <= UInt16.MaxValue)
                {
                    ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.DescriptionCode, descValue, reverseByteOrder, ActionOnException));
                }
            }

            if (IPv4Address != null)
            {
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.IPv4AddressCode, IPv4Address.ConvertToByte(), reverseByteOrder, ActionOnException));
            }

            if (IPv6Address != null)
            {
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.IPv6AddressCode, IPv6Address.ConvertToByte(), reverseByteOrder, ActionOnException));
            }

            if (MacAddress != null)
            {
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.MacAddressCode, MacAddress.GetAddressBytes(), reverseByteOrder, ActionOnException));
            }

            if (EuiAddress != null)
            {
                if (EuiAddress.Length <= UInt16.MaxValue)
                {
                    ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.EuiAddressCode, EuiAddress, reverseByteOrder, ActionOnException));
                }
            }

            if (Speed.HasValue)
            {
                byte[] speedValue = BitConverter.GetBytes(Speed.Value.ReverseByteOrder(reverseByteOrder));
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.SpeedCode, speedValue, reverseByteOrder, ActionOnException));
            }

            if (TimestampResolution.HasValue)
            {
                byte[] timestampValue = { TimestampResolution.Value };
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.TimestampResolutionCode, timestampValue, reverseByteOrder, ActionOnException));
            }

            if (TimeZone.HasValue)
            {
                byte[] timeZoneValue = BitConverter.GetBytes(TimeZone.Value.ReverseByteOrder(reverseByteOrder));
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.TimeZoneCode, timeZoneValue, reverseByteOrder, ActionOnException));
            }

            if (Filter != null)
            {
                if (Filter.Length <= UInt16.MaxValue)
                {
                    ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.FilterCode, Filter, reverseByteOrder, ActionOnException));
                }
            }

            if (OperatingSystem != null)
            {
                byte[] systemValue = UTF8Encoding.UTF8.GetBytes(OperatingSystem);
                if (systemValue.Length <= UInt16.MaxValue)
                {
                    ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.OperatingSystemCode, systemValue, reverseByteOrder, ActionOnException));
                }
            }

            if (FrameCheckSequence.HasValue)
            {
                byte[] fcValue = { FrameCheckSequence.Value };
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.FrameCheckSequenceCode, fcValue, reverseByteOrder, ActionOnException));
            }

            if (TimeOffsetSeconds.HasValue)
            {
                byte[] timeOffsetValue = BitConverter.GetBytes(TimeOffsetSeconds.Value.ReverseByteOrder(reverseByteOrder));
                ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.TimeOffsetSecondsCode, timeOffsetValue, reverseByteOrder, ActionOnException));
            }

            ret.AddRange(ConvertOptionFieldToByte((ushort)InterfaceDescriptionOptionCode.EndOfOptionsCode, new byte[0], reverseByteOrder, ActionOnException));
            return(ret.ToArray());
        }