internal static bool ParseMessageDataToFields(DataSegment messageData, out ushort sequenceNumber, out bool acknowledge, out bool homeRegistration, out bool linkLocalAddressCompatibility, out bool keyManagementMobilityCapability, out ushort lifetime, out IpV6MobilityOptions options) { if (messageData.Length < MinimumMessageDataLength) { sequenceNumber = 0; acknowledge = false; homeRegistration = false; linkLocalAddressCompatibility = false; keyManagementMobilityCapability = false; lifetime = 0; options = null; return(false); } sequenceNumber = messageData.ReadUShort(MessageDataOffset.SequenceNumber, Endianity.Big); acknowledge = messageData.ReadBool(MessageDataOffset.Acknowledge, MessageDataMask.Acknowledge); homeRegistration = messageData.ReadBool(MessageDataOffset.HomeRegistration, MessageDataMask.HomeRegistration); linkLocalAddressCompatibility = messageData.ReadBool(MessageDataOffset.LinkLocalAddressCompatibility, MessageDataMask.LinkLocalAddressCompatibility); keyManagementMobilityCapability = messageData.ReadBool(MessageDataOffset.KeyManagementMobilityCapability, MessageDataMask.KeyManagementMobilityCapability); lifetime = messageData.ReadUShort(MessageDataOffset.Lifetime, Endianity.Big); options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options)); return(true); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) return null; bool isIpV4 = data.ReadBool(Offset.IsIpV4, Mask.IsIpV4); bool isIpV6 = data.ReadBool(Offset.IsIpV6, Mask.IsIpV6); if (isIpV4 && !isIpV6) { if (data.Length != OptionDataMinimumLength + IpV4Address.SizeOf) return null; IpV4Address localMobilityAddress = data.ReadIpV4Address(Offset.LocalMobilityAddress, Endianity.Big); return new IpV6MobilityOptionRedirect(localMobilityAddress); } if (isIpV6 && !isIpV4) { if (data.Length != OptionDataMinimumLength + IpV6Address.SizeOf) return null; IpV6Address localMobilityAddress = data.ReadIpV6Address(Offset.LocalMobilityAddress, Endianity.Big); return new IpV6MobilityOptionRedirect(localMobilityAddress); } return null; }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) { return(null); } bool isIpV4 = data.ReadBool(Offset.IsIpV4, Mask.IsIpV4); bool isIpV6 = data.ReadBool(Offset.IsIpV6, Mask.IsIpV6); if (isIpV4 && !isIpV6) { if (data.Length != OptionDataMinimumLength + IpV4Address.SizeOf) { return(null); } IpV4Address localMobilityAddress = data.ReadIpV4Address(Offset.LocalMobilityAddress, Endianity.Big); return(new IpV6MobilityOptionRedirect(localMobilityAddress)); } if (isIpV6 && !isIpV4) { if (data.Length != OptionDataMinimumLength + IpV6Address.SizeOf) { return(null); } IpV6Address localMobilityAddress = data.ReadIpV6Address(Offset.LocalMobilityAddress, Endianity.Big); return(new IpV6MobilityOptionRedirect(localMobilityAddress)); } return(null); }
internal static IpV6ExtensionHeaderMobilityHeartbeatMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { if (messageData.Length < MinimumMessageDataLength) { return(null); } bool isUnsolicitedHeartbeatResponse = messageData.ReadBool(MessageDataOffset.IsUnsolicitedHeartbeatResponse, MessageDataMask.IsUnsolicitedHeartbeatResponse); bool isResponse = messageData.ReadBool(MessageDataOffset.IsResponse, MessageDataMask.IsResponse); uint sequenceNumber = messageData.ReadUInt(MessageDataOffset.SequenceNumber, Endianity.Big); IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.MobilityOptions, messageData.Length - MessageDataOffset.MobilityOptions)); return(new IpV6ExtensionHeaderMobilityHeartbeatMessage(nextHeader, checksum, isUnsolicitedHeartbeatResponse, isResponse, sequenceNumber, options)); }
internal override IpV6AccessNetworkIdentifierSubOption CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) { return(null); } bool isNetworkNameUtf8 = data.ReadBool(Offset.IsNetworkNameUtf8, Mask.IsNetworkNameUtf8); byte networkNameLength = data[Offset.NetworkNameLength]; if (data.Length < OptionDataMinimumLength + networkNameLength) { return(null); } DataSegment networkName = data.Subsegment(Offset.NetworkName, networkNameLength); int accessPointNameLengthOffset = Offset.NetworkName + networkNameLength; byte accessPointNameLength = data[accessPointNameLengthOffset]; if (data.Length != OptionDataMinimumLength + networkNameLength + accessPointNameLength) { return(null); } int accessPointNameOffset = accessPointNameLengthOffset + sizeof(byte); DataSegment accessPointName = data.Subsegment(accessPointNameOffset, accessPointNameLength); return(new IpV6AccessNetworkIdentifierSubOptionNetworkIdentifier(isNetworkNameUtf8, networkName, accessPointName)); }
internal override IpV6Option CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) { return(null); } bool down = data.ReadBool(Offset.Down, Mask.Down); bool rankError = data.ReadBool(Offset.RankError, Mask.RankError); bool forwardingError = data.ReadBool(Offset.ForwardingError, Mask.ForwardingError); byte rplInstanceId = data[Offset.RplInstanceId]; ushort senderRank = data.ReadUShort(Offset.SenderRank, Endianity.Big); DataSegment subTlvs = data.Subsegment(Offset.SubTlvs, data.Length - Offset.SubTlvs); return(new IpV6OptionRoutingProtocolLowPowerAndLossyNetworks(down, rankError, forwardingError, rplInstanceId, senderRank, subTlvs)); }
internal override DnsResourceData CreateInstance(DataSegment data) { if (data.Length < ConstantPartLength) { return(null); } bool zoneKey = data.ReadBool(Offset.ZoneKey, Mask.ZoneKey); bool revoke = data.ReadBool(Offset.Revoke, Mask.Revoke); bool secureEntryPoint = data.ReadBool(Offset.SecureEntryPoint, Mask.SecureEntryPoint); byte protocol = data[Offset.Protocol]; DnsAlgorithm algorithm = (DnsAlgorithm)data[Offset.Algorithm]; DataSegment publicKey = data.Subsegment(Offset.PublicKey, data.Length - ConstantPartLength); return(new DnsResourceDataDnsKey(zoneKey, revoke, secureEntryPoint, protocol, algorithm, publicKey)); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) { return(null); } ushort bindingId = data.ReadUShort(Offset.BindingId, Endianity.Big); IpV6BindingAcknowledgementStatus status = (IpV6BindingAcknowledgementStatus)data[Offset.Status]; bool simultaneousHomeAndForeignBinding = data.ReadBool(Offset.SimultaneousHomeAndForeignBinding, Mask.SimultaneousHomeAndForeignBinding); byte priority = (byte)(data[Offset.Priority] & Mask.Priority); if (data.Length == OptionDataMinimumLength) { return(new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority)); } if (data.Length == OptionDataMinimumLength + IpV4Address.SizeOf) { IpV4Address careOfAddress = data.ReadIpV4Address(Offset.CareOfAddress, Endianity.Big); return(new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority, careOfAddress)); } if (data.Length == OptionDataMinimumLength + IpV6Address.SizeOf) { IpV6Address careOfAddress = data.ReadIpV6Address(Offset.CareOfAddress, Endianity.Big); return(new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority, careOfAddress)); } return(null); }
internal static IpV6ExtensionHeaderMobilityHandoverInitiateMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { if (messageData.Length < MinimumMessageDataLength) { return(null); } ushort sequenceNumber = messageData.ReadUShort(MessageDataOffset.SequenceNumber, Endianity.Big); bool assignedAddressConfiguration = messageData.ReadBool(MessageDataOffset.AssignedAddressConfiguration, MessageDataMask.AssignedAddressConfiguration); bool buffer = messageData.ReadBool(MessageDataOffset.Buffer, MessageDataMask.Buffer); IpV6HandoverInitiateMessageCode code = (IpV6HandoverInitiateMessageCode)messageData[MessageDataOffset.Code]; IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options)); return(new IpV6ExtensionHeaderMobilityHandoverInitiateMessage(nextHeader, checksum, sequenceNumber, assignedAddressConfiguration, buffer, code, options)); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length != OptionDataLength) return null; bool isServer = data.ReadBool(Offset.IsServer, Mask.IsServer); return new IpV6MobilityOptionIpV4DhcpSupportMode(isServer); }
internal override DnsResourceData CreateInstance(DataSegment data) { if (data.Length < 4) { return((DnsResourceData)null); } return((DnsResourceData) new DnsResourceDataDnsKey(data.ReadBool(0, (byte)1), data.ReadBool(1, (byte)sbyte.MinValue), data.ReadBool(1, (byte)1), data[2], (DnsAlgorithm)data[3], data.Subsegment(4, data.Length - 4))); }
internal override DnsResourceData CreateInstance(DataSegment data) { if (data.Length < ConstantPartLength) { return(null); } bool authenticationProhibited = data.ReadBool(Offset.AuthenticationProhibited, Mask.AuthenticationProhibited); bool confidentialityProhibited = data.ReadBool(Offset.ConfidentialityProhibited, Mask.ConfidentialityProhibited); bool experimental = data.ReadBool(Offset.Experimental, Mask.Experimental); bool isFlagsExtension = data.ReadBool(Offset.IsFlagsExtension, Mask.IsFlagsExtension); bool userAssociated = data.ReadBool(Offset.UserAssociated, Mask.UserAssociated); bool ipSec = data.ReadBool(Offset.IpSec, Mask.IpSec); bool email = data.ReadBool(Offset.Email, Mask.Email); DnsKeyNameType nameType = (DnsKeyNameType)(data[Offset.NameType] & Mask.NameType); DnsKeySignatoryAttributes signatory = (DnsKeySignatoryAttributes)(data[Offset.Signatory] & Mask.Signatory); DnsKeyProtocol protocol = (DnsKeyProtocol)data[Offset.Protocol]; DnsAlgorithm algorithm = (DnsAlgorithm)data[Offset.Algorithm]; ushort? flagsExtension = (isFlagsExtension ? ((ushort?)data.ReadUShort(Offset.FlagsExtension, Endianity.Big)) : null); int publicKeyOffset = Offset.FlagsExtension + (isFlagsExtension ? sizeof(ushort) : 0); DataSegment publicKey = data.Subsegment(publicKeyOffset, data.Length - publicKeyOffset); return(new DnsResourceDataKey(authenticationProhibited, confidentialityProhibited, experimental, userAssociated, ipSec, email, nameType, signatory, protocol, algorithm, flagsExtension, publicKey)); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length != OptionDataLength) return null; bool latePathSwitch = data.ReadBool(Offset.LatePathSwitch, Mask.LatePathSwitch); byte lifetime = data[Offset.Lifetime]; return new IpV6MobilityOptionTransientBinding(latePathSwitch, lifetime); }
internal static IpV6Option CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) return null; bool hashIndicator = data.ReadBool(Offset.HashIndicator, Mask.HashIndicator); if (hashIndicator) return new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionSequenceHashAssistValue(data); return IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionSequenceBased.CreateSpecificInstance(data); }
internal override IpV6Option CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) return null; bool hashIndicator = data.ReadBool(Offset.HashIndicator, Mask.HashIndicator); if (hashIndicator) return new IpV6OptionSmfDpdSequenceHashAssistValue(data); return IpV6OptionSmfDpdSequenceBased.CreateSpecificInstance(data); }
/// <summary> /// Parses an option from the given data. /// </summary> /// <param name="data">The data to parse.</param> /// <returns>The option if parsing was successful, null otherwise.</returns> public IpV6Option CreateInstance(DataSegment data) { if (data == null) { throw new ArgumentNullException("data"); } if (data.Length < OptionDataMinimumLength) { return(null); } bool down = data.ReadBool(Offset.Down, Mask.Down); bool rankError = data.ReadBool(Offset.RankError, Mask.RankError); bool forwardingError = data.ReadBool(Offset.ForwardingError, Mask.ForwardingError); byte rplInstanceId = data[Offset.RoutingProtocolLowPowerAndLossyNetworksInstanceId]; ushort senderRank = data.ReadUShort(Offset.SenderRank, Endianity.Big); DataSegment subTlvs = data.Subsegment(Offset.SubTypeLengthValues, data.Length - Offset.SubTypeLengthValues); return(new IpV6OptionRoutingProtocolLowPowerAndLossyNetworks(down, rankError, forwardingError, rplInstanceId, senderRank, subTlvs)); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length != OptionDataLength) { return(null); } bool isServer = data.ReadBool(Offset.IsServer, Mask.IsServer); return(new IpV6MobilityOptionIpV4DhcpSupportMode(isServer)); }
internal static IpV6ExtensionHeaderMobilityBindingAcknowledgement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { IpV6BindingAcknowledgementStatus status; bool keyManagementMobilityCapability; ushort sequenceNumber; ushort lifetime; IpV6MobilityOptions options; if (!ParseMessageDataFields(messageData, out status, out keyManagementMobilityCapability, out sequenceNumber, out lifetime, out options)) { return(null); } bool mobileRouter = messageData.ReadBool(MessageDataOffset.MobileRouter, MessageDataMask.MobileRouter); bool proxyRegistration = messageData.ReadBool(MessageDataOffset.ProxyRegistration, MessageDataMask.ProxyRegistration); bool tlvHeaderFormat = messageData.ReadBool(MessageDataOffset.TlvHeaderFormat, MessageDataMask.TlvHeaderFormat); return(new IpV6ExtensionHeaderMobilityBindingAcknowledgement(nextHeader, checksum, status, keyManagementMobilityCapability, mobileRouter, proxyRegistration, tlvHeaderFormat, sequenceNumber, lifetime, options)); }
internal static IpV6ExtensionHeaderFragmentData ParseData(IpV4Protocol nextHeader, DataSegment data) { if (data.Length != DataLength) return null; ushort fragmentOffset = (ushort)((data.ReadUShort(DataOffset.FragmentOffset, Endianity.Big) & DataMask.FragmentOffset) >> DataShift.FragmentOffset); bool moreFragments = data.ReadBool(DataOffset.MoreFragments, DataMask.MoreFragments); uint identification = data.ReadUInt(DataOffset.Identification, Endianity.Big); return new IpV6ExtensionHeaderFragmentData(nextHeader, fragmentOffset, moreFragments, identification); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length != OptionDataLength) { return(null); } bool latePathSwitch = data.ReadBool(Offset.LatePathSwitch, Mask.LatePathSwitch); byte lifetime = data[Offset.Lifetime]; return(new IpV6MobilityOptionTransientBinding(latePathSwitch, lifetime)); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length != OptionDataLength) { return(null); } bool udpEncapsulationRequired = data.ReadBool(Offset.UdpEncapsulationRequired, Mask.UdpEncapsulationRequired); uint refreshTime = data.ReadUInt(Offset.RefreshTime, Endianity.Big); return(new IpV6MobilityOptionNatDetection(udpEncapsulationRequired, refreshTime)); }
internal static IpV6ExtensionHeaderMobilityBindingUpdate ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { ushort sequenceNumber; bool acknowledge; bool homeRegistration; bool linkLocalAddressCompatibility; bool keyManagementMobilityCapability; ushort lifetime; IpV6MobilityOptions options; if (!ParseMessageDataToFields(messageData, out sequenceNumber, out acknowledge, out homeRegistration, out linkLocalAddressCompatibility, out keyManagementMobilityCapability, out lifetime, out options)) { return(null); } bool mapRegistration = messageData.ReadBool(MessageDataOffset.MapRegistration, MessageDataMask.MapRegistration); bool mobileRouter = messageData.ReadBool(MessageDataOffset.MobileRouter, MessageDataMask.MobileRouter); bool proxyRegistration = messageData.ReadBool(MessageDataOffset.ProxyRegistration, MessageDataMask.ProxyRegistration); bool forcingUdpEncapsulation = messageData.ReadBool(MessageDataOffset.ForcingUdpEncapsulation, MessageDataMask.ForcingUdpEncapsulation); bool tlvHeaderFormat = messageData.ReadBool(MessageDataOffset.TlvHeaderFormat, MessageDataMask.TlvHeaderFormat); bool bulkBindingUpdate = messageData.ReadBool(MessageDataOffset.BulkBindingUpdate, MessageDataMask.BulkBindingUpdate); return(new IpV6ExtensionHeaderMobilityBindingUpdate(nextHeader, checksum, sequenceNumber, acknowledge, homeRegistration, linkLocalAddressCompatibility, keyManagementMobilityCapability, mapRegistration, mobileRouter, proxyRegistration, forcingUdpEncapsulation, tlvHeaderFormat, bulkBindingUpdate, lifetime, options)); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) { return(null); } IpV6DnsUpdateStatus status = (IpV6DnsUpdateStatus)data[Offset.Status]; bool remove = data.ReadBool(Offset.Remove, Mask.Remove); DataSegment mobileNodeIdentity = data.Subsegment(Offset.MobileNodeIdentity, data.Length - Offset.MobileNodeIdentity); return(new IpV6MobilityOptionDnsUpdate(status, remove, mobileNodeIdentity)); }
internal static IpV6ExtensionHeaderFragmentData ParseData(IpV4Protocol nextHeader, DataSegment data) { if (data.Length != ExtensionHeaderDataLength) { return(null); } ushort fragmentOffset = (ushort)((data.ReadUShort(DataOffset.FragmentOffset, Endianity.Big) & DataMask.FragmentOffset) >> DataShift.FragmentOffset); bool moreFragments = data.ReadBool(DataOffset.MoreFragments, DataMask.MoreFragments); uint identification = data.ReadUInt(DataOffset.Identification, Endianity.Big); return(new IpV6ExtensionHeaderFragmentData(nextHeader, fragmentOffset, moreFragments, identification)); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length != OptionDataLength) { return(null); } byte prefixLength = (byte)((data[Offset.PrefixLength] & Mask.PrefixLength) >> Shift.PrefixLength); bool requestPrefix = data.ReadBool(Offset.RequestPrefix, Mask.RequestPrefix); IpV4Address homeAddress = data.ReadIpV4Address(Offset.HomeAddress, Endianity.Big); return(new IpV6MobilityOptionIpV4HomeAddress(prefixLength, requestPrefix, homeAddress)); }
internal override IpV6Option CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) { return(null); } bool hashIndicator = data.ReadBool(Offset.HashIndicator, Mask.HashIndicator); if (hashIndicator) { return(new IpV6OptionSmfDpdSequenceHashAssistValue(data)); } return(IpV6OptionSmfDpdSequenceBased.CreateSpecificInstance(data)); }
internal static IpV6Option CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) { return(null); } bool hashIndicator = data.ReadBool(Offset.HashIndicator, Mask.HashIndicator); if (hashIndicator) { return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionSequenceHashAssistValue(data)); } return(IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionSequenceBased.CreateSpecificInstance(data)); }
internal static IpV6ExtensionHeaderMobilityLocalizedRoutingAcknowledgement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { ushort sequenceNumber; ushort lifetime; IpV6MobilityOptions options; if (!ParseMessageDataToFields(messageData, out sequenceNumber, out lifetime, out options)) { return(null); } bool unsolicited = messageData.ReadBool(MessageDataOffset.Unsolicited, MessageDataMask.Unsolicited); IpV6MobilityLocalizedRoutingAcknowledgementStatus status = (IpV6MobilityLocalizedRoutingAcknowledgementStatus)messageData[MessageDataOffset.Status]; return(new IpV6ExtensionHeaderMobilityLocalizedRoutingAcknowledgement(nextHeader, checksum, sequenceNumber, unsolicited, status, lifetime, options)); }
internal static DnsAddressPrefix Read(DataSegment data) { if (data == null) { throw new ArgumentNullException("data"); } if (data.Length < 4) { return((DnsAddressPrefix)null); } AddressFamily addressFamily = (AddressFamily)data.ReadUShort(0, Endianity.Big); byte prefixLength = data[2]; bool negation = data.ReadBool(3, (byte)sbyte.MinValue); byte num = (byte)((uint)data[3] & (uint)sbyte.MaxValue); if (data.Length < 4 + (int)num) { return((DnsAddressPrefix)null); } DataSegment addressFamilyDependentPart = data.Subsegment(4, (int)num); return(new DnsAddressPrefix(addressFamily, prefixLength, negation, addressFamilyDependentPart)); }
internal static bool ParseMessageDataFields(DataSegment messageData, out IpV6BindingAcknowledgementStatus status, out bool keyManagementMobilityCapability, out ushort sequenceNumber, out ushort lifetime, out IpV6MobilityOptions options) { if (messageData.Length < MinimumMessageDataLength) { status = IpV6BindingAcknowledgementStatus.BindingUpdateAccepted; keyManagementMobilityCapability = false; sequenceNumber = 0; lifetime = 0; options = null; return(false); } status = (IpV6BindingAcknowledgementStatus)messageData[MessageDataOffset.Status]; keyManagementMobilityCapability = messageData.ReadBool(MessageDataOffset.KeyManagementMobilityCapability, MessageDataMask.KeyManagementMobilityCapability); sequenceNumber = messageData.ReadUShort(MessageDataOffset.SequenceNumber, Endianity.Big); lifetime = messageData.ReadUShort(MessageDataOffset.Lifetime, Endianity.Big); options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options)); return(true); }
internal static DnsAddressPrefix Read(DataSegment data) { if (data == null) { throw new ArgumentNullException("data"); } if (data.Length < MinimumLength) { return(null); } AddressFamily addressFamily = (AddressFamily)data.ReadUShort(Offset.AddressFamily, Endianity.Big); byte prefixLength = data[Offset.PrefixLength]; bool negation = data.ReadBool(Offset.Negation, Mask.Negation); byte addressFamilyDependentPartLength = (byte)(data[Offset.AddressFamilyDependentPartLength] & Mask.AddressFamilyDependentPartLength); if (data.Length < MinimumLength + addressFamilyDependentPartLength) { return(null); } DataSegment addressFamilyDependentPart = data.Subsegment(Offset.AddressFamilyDependentPart, addressFamilyDependentPartLength); return(new DnsAddressPrefix(addressFamily, prefixLength, negation, addressFamilyDependentPart)); }
internal override DnsResourceData CreateInstance(DataSegment data) { if (data.Length < 4) { return((DnsResourceData)null); } bool authenticationProhibited = data.ReadBool(0, (byte)sbyte.MinValue); bool confidentialityProhibited = data.ReadBool(0, (byte)64); bool experimental = data.ReadBool(0, (byte)32); bool flag = data.ReadBool(0, (byte)16); bool userAssociated = data.ReadBool(0, (byte)4); bool ipSec = data.ReadBool(1, (byte)sbyte.MinValue); bool email = data.ReadBool(1, (byte)64); DnsKeyNameType nameType = (DnsKeyNameType)((uint)data[0] & 3U); DnsKeySignatoryAttributes signatory = (DnsKeySignatoryAttributes)((uint)data[1] & 15U); DnsKeyProtocol protocol = (DnsKeyProtocol)data[2]; DnsAlgorithm algorithm = (DnsAlgorithm)data[3]; ushort? flagsExtension = flag ? new ushort?(data.ReadUShort(4, Endianity.Big)) : new ushort?(); int offset = 4 + (flag ? 2 : 0); DataSegment publicKey = data.Subsegment(offset, data.Length - offset); return((DnsResourceData) new DnsResourceDataKey(authenticationProhibited, confidentialityProhibited, experimental, userAssociated, ipSec, email, nameType, signatory, protocol, algorithm, flagsExtension, publicKey)); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length != OptionDataLength) return null; byte prefixLength = (byte)((data[Offset.PrefixLength] & Mask.PrefixLength) >> Shift.PrefixLength); bool requestPrefix = data.ReadBool(Offset.RequestPrefix, Mask.RequestPrefix); IpV4Address homeAddress = data.ReadIpV4Address(Offset.HomeAddress, Endianity.Big); return new IpV6MobilityOptionIpV4HomeAddress(prefixLength, requestPrefix, homeAddress); }
internal static IpV6ExtensionHeaderMobilityBindingUpdate ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { if (messageData.Length < MinimumMessageDataLength) return null; ushort sequenceNumber = messageData.ReadUShort(MessageDataOffset.SequenceNumber, Endianity.Big); bool acknowledge = messageData.ReadBool(MessageDataOffset.Acknowledge, MessageDataMask.Acknowledge); bool homeRegistration = messageData.ReadBool(MessageDataOffset.HomeRegistration, MessageDataMask.HomeRegistration); bool linkLocalAddressCompatibility = messageData.ReadBool(MessageDataOffset.LinkLocalAddressCompatibility, MessageDataMask.LinkLocalAddressCompatibility); bool keyManagementMobilityCapability = messageData.ReadBool(MessageDataOffset.KeyManagementMobilityCapability, MessageDataMask.KeyManagementMobilityCapability); ushort lifetime = messageData.ReadUShort(MessageDataOffset.Lifetime, Endianity.Big); IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options)); return new IpV6ExtensionHeaderMobilityBindingUpdate(nextHeader, checksum, sequenceNumber, acknowledge, homeRegistration, linkLocalAddressCompatibility, keyManagementMobilityCapability, lifetime, options); }
internal override IpV6AccessNetworkIdentifierSubOption CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) return null; bool isNetworkNameUtf8 = data.ReadBool(Offset.IsNetworkNameUtf8, Mask.IsNetworkNameUtf8); byte networkNameLength = data[Offset.NetworkNameLength]; if (data.Length < OptionDataMinimumLength + networkNameLength) return null; DataSegment networkName = data.Subsegment(Offset.NetworkName, networkNameLength); int accessPointNameLengthOffset = Offset.NetworkName + networkNameLength; byte accessPointNameLength = data[accessPointNameLengthOffset]; if (data.Length != OptionDataMinimumLength + networkNameLength + accessPointNameLength) return null; int accessPointNameOffset = accessPointNameLengthOffset + sizeof(byte); DataSegment accessPointName = data.Subsegment(accessPointNameOffset, accessPointNameLength); return new IpV6AccessNetworkIdentifierSubOptionNetworkIdentifier(isNetworkNameUtf8, networkName, accessPointName); }
internal static IpV6ExtensionHeaderMobilityBindingRevocationMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { if (messageData.Length < MinimumMessageDataLength) return null; IpV6MobilityBindingRevocationType bindingRevocationType = (IpV6MobilityBindingRevocationType)messageData[MessageDataOffset.BindingRevocationType]; byte revocationTriggerOrStatus = messageData[MessageDataOffset.RevocationTriggerOrStatus]; ushort sequenceNumber = messageData.ReadUShort(MessageDataOffset.SequenceNumber, Endianity.Big); bool proxyBinding = messageData.ReadBool(MessageDataOffset.ProxyBinding, MessageDataMask.ProxyBinding); bool ipV4HomeAddressBindingOnly = messageData.ReadBool(MessageDataOffset.IpV4HomeAddressBindingOnly, MessageDataMask.IpV4HomeAddressBindingOnly); bool global = messageData.ReadBool(MessageDataOffset.Global, MessageDataMask.Global); IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options)); switch (bindingRevocationType) { case IpV6MobilityBindingRevocationType.BindingRevocationIndication: return new IpV6ExtensionHeaderMobilityBindingRevocationIndicationMessage(nextHeader, checksum, (Ipv6MobilityBindingRevocationTrigger)revocationTriggerOrStatus, sequenceNumber, proxyBinding, ipV4HomeAddressBindingOnly, global, options); case IpV6MobilityBindingRevocationType.BindingRevocationAcknowledgement: return new IpV6ExtensionHeaderMobilityBindingRevocationAcknowledgementMessage(nextHeader, checksum, (Ipv6MobilityBindingRevocationStatus)revocationTriggerOrStatus, sequenceNumber, proxyBinding, ipV4HomeAddressBindingOnly, global, options); default: return null; } }
internal static IpV6ExtensionHeaderMobilityLocalizedRoutingAcknowledgement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { ushort sequenceNumber; ushort lifetime; IpV6MobilityOptions options; if (!ParseMessageDataToFields(messageData, out sequenceNumber, out lifetime, out options)) return null; bool unsolicited = messageData.ReadBool(MessageDataOffset.Unsolicited, MessageDataMask.Unsolicited); IpV6MobilityLocalizedRoutingAcknowledgementStatus status = (IpV6MobilityLocalizedRoutingAcknowledgementStatus)messageData[MessageDataOffset.Status]; return new IpV6ExtensionHeaderMobilityLocalizedRoutingAcknowledgement(nextHeader, checksum, sequenceNumber, unsolicited, status, lifetime, options); }
/// <summary> /// Parses an option from the given data. /// </summary> /// <param name="data">The data to parse.</param> /// <returns>The option if parsing was successful, null otherwise.</returns> public IpV6Option CreateInstance(DataSegment data) { if (data == null) throw new ArgumentNullException("data"); if (data.Length < OptionDataMinimumLength) return null; bool down = data.ReadBool(Offset.Down, Mask.Down); bool rankError = data.ReadBool(Offset.RankError, Mask.RankError); bool forwardingError = data.ReadBool(Offset.ForwardingError, Mask.ForwardingError); byte rplInstanceId = data[Offset.RoutingProtocolLowPowerAndLossyNetworksInstanceId]; ushort senderRank = data.ReadUShort(Offset.SenderRank, Endianity.Big); DataSegment subTlvs = data.Subsegment(Offset.SubTypeLengthValues, data.Length - Offset.SubTypeLengthValues); return new IpV6OptionRoutingProtocolLowPowerAndLossyNetworks(down, rankError, forwardingError, rplInstanceId, senderRank, subTlvs); }
internal static bool ParseMessageDataToFields(DataSegment messageData, out ushort sequenceNumber, out bool acknowledge, out bool homeRegistration, out bool linkLocalAddressCompatibility, out bool keyManagementMobilityCapability, out ushort lifetime, out IpV6MobilityOptions options) { if (messageData.Length < MinimumMessageDataLength) { sequenceNumber = 0; acknowledge = false; homeRegistration = false; linkLocalAddressCompatibility = false; keyManagementMobilityCapability = false; lifetime = 0; options = null; return false; } sequenceNumber = messageData.ReadUShort(MessageDataOffset.SequenceNumber, Endianity.Big); acknowledge = messageData.ReadBool(MessageDataOffset.Acknowledge, MessageDataMask.Acknowledge); homeRegistration = messageData.ReadBool(MessageDataOffset.HomeRegistration, MessageDataMask.HomeRegistration); linkLocalAddressCompatibility = messageData.ReadBool(MessageDataOffset.LinkLocalAddressCompatibility, MessageDataMask.LinkLocalAddressCompatibility); keyManagementMobilityCapability = messageData.ReadBool(MessageDataOffset.KeyManagementMobilityCapability, MessageDataMask.KeyManagementMobilityCapability); lifetime = messageData.ReadUShort(MessageDataOffset.Lifetime, Endianity.Big); options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options)); return true; }
internal static IpV6ExtensionHeaderMobilityHeartbeatMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { if (messageData.Length < MinimumMessageDataLength) return null; bool isUnsolicitedHeartbeatResponse = messageData.ReadBool(MessageDataOffset.IsUnsolicitedHeartbeatResponse, MessageDataMask.IsUnsolicitedHeartbeatResponse); bool isResponse = messageData.ReadBool(MessageDataOffset.IsResponse, MessageDataMask.IsResponse); uint sequenceNumber = messageData.ReadUInt(MessageDataOffset.SequenceNumber, Endianity.Big); IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.MobilityOptions, messageData.Length - MessageDataOffset.MobilityOptions)); return new IpV6ExtensionHeaderMobilityHeartbeatMessage(nextHeader, checksum, isUnsolicitedHeartbeatResponse, isResponse, sequenceNumber, options); }
internal static IpV6ExtensionHeaderMobilityBindingAcknowledgement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { if (messageData.Length < MinimumMessageDataLength) return null; IpV6BindingAcknowledgementStatus status = (IpV6BindingAcknowledgementStatus)messageData[MessageDataOffset.Status]; bool keyManagementMobilityCapability = messageData.ReadBool(MessageDataOffset.KeyManagementMobilityCapability, MessageDataMask.KeyManagementMobilityCapability); ushort sequenceNumber = messageData.ReadUShort(MessageDataOffset.SequenceNumber, Endianity.Big); ushort lifetime = messageData.ReadUShort(MessageDataOffset.Lifetime, Endianity.Big); IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options)); return new IpV6ExtensionHeaderMobilityBindingAcknowledgement(nextHeader, checksum, status, keyManagementMobilityCapability, sequenceNumber, lifetime, options); }
internal override IpV6Option CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) return null; bool down = data.ReadBool(Offset.Down, Mask.Down); bool rankError = data.ReadBool(Offset.RankError, Mask.RankError); bool forwardingError = data.ReadBool(Offset.ForwardingError, Mask.ForwardingError); byte rplInstanceId = data[Offset.RplInstanceId]; ushort senderRank = data.ReadUShort(Offset.SenderRank, Endianity.Big); DataSegment subTlvs = data.Subsegment(Offset.SubTlvs, data.Length - Offset.SubTlvs); return new IpV6OptionRoutingProtocolLowPowerAndLossyNetworks(down, rankError, forwardingError, rplInstanceId, senderRank, subTlvs); }
internal static bool ParseMessageDataFields(DataSegment messageData, out IpV6BindingAcknowledgementStatus status, out bool keyManagementMobilityCapability, out ushort sequenceNumber, out ushort lifetime, out IpV6MobilityOptions options) { if (messageData.Length < MinimumMessageDataLength) { status = IpV6BindingAcknowledgementStatus.BindingUpdateAccepted; keyManagementMobilityCapability = false; sequenceNumber = 0; lifetime = 0; options = null; return false; } status = (IpV6BindingAcknowledgementStatus)messageData[MessageDataOffset.Status]; keyManagementMobilityCapability = messageData.ReadBool(MessageDataOffset.KeyManagementMobilityCapability, MessageDataMask.KeyManagementMobilityCapability); sequenceNumber = messageData.ReadUShort(MessageDataOffset.SequenceNumber, Endianity.Big); lifetime = messageData.ReadUShort(MessageDataOffset.Lifetime, Endianity.Big); options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options)); return true; }
internal static IpV6ExtensionHeaderMobilityBindingUpdate ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { ushort sequenceNumber; bool acknowledge; bool homeRegistration; bool linkLocalAddressCompatibility; bool keyManagementMobilityCapability; ushort lifetime; IpV6MobilityOptions options; if (!ParseMessageDataToFields(messageData, out sequenceNumber, out acknowledge, out homeRegistration, out linkLocalAddressCompatibility, out keyManagementMobilityCapability, out lifetime, out options)) { return null; } bool mapRegistration = messageData.ReadBool(MessageDataOffset.MapRegistration, MessageDataMask.MapRegistration); bool mobileRouter = messageData.ReadBool(MessageDataOffset.MobileRouter, MessageDataMask.MobileRouter); bool proxyRegistration = messageData.ReadBool(MessageDataOffset.ProxyRegistration, MessageDataMask.ProxyRegistration); bool forcingUdpEncapsulation = messageData.ReadBool(MessageDataOffset.ForcingUdpEncapsulation, MessageDataMask.ForcingUdpEncapsulation); bool tlvHeaderFormat = messageData.ReadBool(MessageDataOffset.TlvHeaderFormat, MessageDataMask.TlvHeaderFormat); bool bulkBindingUpdate = messageData.ReadBool(MessageDataOffset.BulkBindingUpdate, MessageDataMask.BulkBindingUpdate); return new IpV6ExtensionHeaderMobilityBindingUpdate(nextHeader, checksum, sequenceNumber, acknowledge, homeRegistration, linkLocalAddressCompatibility, keyManagementMobilityCapability, mapRegistration, mobileRouter, proxyRegistration, forcingUdpEncapsulation, tlvHeaderFormat, bulkBindingUpdate, lifetime, options); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length != OptionDataLength) return null; bool udpEncapsulationRequired = data.ReadBool(Offset.UdpEncapsulationRequired, Mask.UdpEncapsulationRequired); uint refreshTime = data.ReadUInt(Offset.RefreshTime, Endianity.Big); return new IpV6MobilityOptionNatDetection(udpEncapsulationRequired, refreshTime); }
internal static IpV6ExtensionHeaderMobilityBindingAcknowledgement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { IpV6BindingAcknowledgementStatus status; bool keyManagementMobilityCapability; ushort sequenceNumber; ushort lifetime; IpV6MobilityOptions options; if (!ParseMessageDataFields(messageData, out status, out keyManagementMobilityCapability, out sequenceNumber, out lifetime, out options)) return null; bool mobileRouter = messageData.ReadBool(MessageDataOffset.MobileRouter, MessageDataMask.MobileRouter); bool proxyRegistration = messageData.ReadBool(MessageDataOffset.ProxyRegistration, MessageDataMask.ProxyRegistration); bool tlvHeaderFormat = messageData.ReadBool(MessageDataOffset.TlvHeaderFormat, MessageDataMask.TlvHeaderFormat); return new IpV6ExtensionHeaderMobilityBindingAcknowledgement(nextHeader, checksum, status, keyManagementMobilityCapability, mobileRouter, proxyRegistration, tlvHeaderFormat, sequenceNumber, lifetime, options); }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) return null; ushort bindingId = data.ReadUShort(Offset.BindingId, Endianity.Big); IpV6BindingAcknowledgementStatus status = (IpV6BindingAcknowledgementStatus)data[Offset.Status]; bool simultaneousHomeAndForeignBinding = data.ReadBool(Offset.SimultaneousHomeAndForeignBinding, Mask.SimultaneousHomeAndForeignBinding); byte priority = (byte)(data[Offset.Priority] & Mask.Priority); if (data.Length == OptionDataMinimumLength) return new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority); if (data.Length == OptionDataMinimumLength + IpV4Address.SizeOf) { IpV4Address careOfAddress = data.ReadIpV4Address(Offset.CareOfAddress, Endianity.Big); return new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority, careOfAddress); } if (data.Length == OptionDataMinimumLength + IpV6Address.SizeOf) { IpV6Address careOfAddress = data.ReadIpV6Address(Offset.CareOfAddress, Endianity.Big); return new IpV6MobilityOptionBindingIdentifier(bindingId, status, simultaneousHomeAndForeignBinding, priority, careOfAddress); } return null; }
internal override IpV6MobilityOption CreateInstance(DataSegment data) { if (data.Length < OptionDataMinimumLength) return null; IpV6DnsUpdateStatus status = (IpV6DnsUpdateStatus)data[Offset.Status]; bool remove = data.ReadBool(Offset.Remove, Mask.Remove); DataSegment mobileNodeIdentity = data.Subsegment(Offset.MobileNodeIdentity, data.Length - Offset.MobileNodeIdentity); return new IpV6MobilityOptionDnsUpdate(status, remove, mobileNodeIdentity); }
internal static IpV6ExtensionHeaderMobilityHandoverInitiateMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData) { if (messageData.Length < MinimumMessageDataLength) return null; ushort sequenceNumber = messageData.ReadUShort(MessageDataOffset.SequenceNumber, Endianity.Big); bool assignedAddressConfiguration = messageData.ReadBool(MessageDataOffset.AssignedAddressConfiguration, MessageDataMask.AssignedAddressConfiguration); bool buffer = messageData.ReadBool(MessageDataOffset.Buffer, MessageDataMask.Buffer); IpV6HandoverInitiateMessageCode code = (IpV6HandoverInitiateMessageCode)messageData[MessageDataOffset.Code]; IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options)); return new IpV6ExtensionHeaderMobilityHandoverInitiateMessage(nextHeader, checksum, sequenceNumber, assignedAddressConfiguration, buffer, code, options); }