/// <summary> /// Serlialize this routing option into something which /// can be passed to an IpV4Packet class. /// </summary> /// <param name="optionType"> /// There are 3 types of routing option: loose source, strict source and record. /// </param> /// <returns> /// An IpV4Option class which can be passed to an IpV4Packet. /// </returns> /// <exception cref="ArgumentException"> /// The option type is not a routing option. /// </exception> public IpV4Option Serialize(IpV4OptionNumber optionType) { IpV4Option newOption = new IpV4Option(); if (optionType != IpV4OptionNumber.LooseSourceRouting && optionType != IpV4OptionNumber.StrictSourceRouting && optionType != IpV4OptionNumber.RecordRoute) { throw new ArgumentException("The option type must be a routing option (strict source routing, loose source routing or record route", "option"); } // fill in basic fields newOption.Class = IpV4OptionClass.Control; newOption.OptionType = optionType; newOption.IsCopied = true; newOption.Length = (m_routeData.Length * 4) + 3; newOption.Data = new byte[(m_routeData.Length * 4) + 1]; // fill in the pointer newOption.Data [0] = (byte)m_pointer; // fill in the route data for (int i = 0; i < m_routeData.Length; i++) { Array.Copy(m_routeData[i].GetAddressBytes(), 0, newOption.Data, (i * 4) + 1, 4); } return(newOption); }
/// <summary> /// Serlialize this routing option into something which /// can be passed to an IpV4Packet class. /// </summary> /// <param name="optionType"> /// There are 3 types of routing option: loose source, strict source and record. /// </param> /// <returns> /// An IpV4Option class which can be passed to an IpV4Packet. /// </returns> /// <exception cref="ArgumentException"> /// The option type is not a routing option. /// </exception> public IpV4Option Serialize (IpV4OptionNumber optionType) { IpV4Option newOption = new IpV4Option (); if (optionType != IpV4OptionNumber.LooseSourceRouting && optionType != IpV4OptionNumber.StrictSourceRouting && optionType != IpV4OptionNumber.RecordRoute) { throw new ArgumentException ("The option type must be a routing option (strict source routing, loose source routing or record route", "option"); } // fill in basic fields newOption.Class = IpV4OptionClass.Control; newOption.OptionType = optionType; newOption.IsCopied = true; newOption.Length = (m_routeData.Length * 4) + 3; newOption.Data = new byte[(m_routeData.Length * 4) + 1]; // fill in the pointer newOption.Data [0] = (byte)m_pointer; // fill in the route data for (int i = 0; i < m_routeData.Length; i++) { Array.Copy (m_routeData[i].GetAddressBytes (), 0, newOption.Data, (i * 4) + 1, 4); } return newOption; }