/// <summary> /// Calculates the length for the chunk parameter. /// </summary> /// <param name="padded">If true the length field will be padded to a 4 byte boundary.</param> /// <returns>The length of the chunk. This method gets overridden by specialised SCTP parameters /// that each have their own fields that determine the length.</returns> public virtual ushort GetParameterLength(bool padded) { ushort len = (ushort)(SCTP_PARAMETER_HEADER_LENGTH + (ParameterValue == null ? 0 : ParameterValue.Length)); return((padded) ? SctpPadding.PadTo4ByteBoundary(len) : len); }
/// <summary> /// Calculates the length for the chunk. Chunks are required /// to be padded out to 4 byte boundaries. This method gets overridden /// by specialised SCTP chunks that have their own fields that determine the length. /// </summary> /// <param name="padded">If true the length field will be padded to a 4 byte boundary.</param> /// <returns>The length of the chunk.</returns> public virtual ushort GetChunkLength(bool padded) { var len = (ushort)(SCTP_CHUNK_HEADER_LENGTH + (ChunkValue == null ? 0 : ChunkValue.Length)); return((padded) ? SctpPadding.PadTo4ByteBoundary(len) : len); }
/// <summary> /// Calculates the length for DATA chunk. /// </summary> /// <param name="padded">If true the length field will be padded to a 4 byte boundary.</param> /// <returns>The length of the chunk.</returns> public override ushort GetChunkLength(bool padded) { ushort len = SCTP_CHUNK_HEADER_LENGTH + FIXED_PARAMETERS_LENGTH; len += (ushort)(UserData != null ? UserData.Length : 0); return((padded) ? SctpPadding.PadTo4ByteBoundary(len) : len); }
/// <summary> /// Calculates the length for INIT and INIT ACK chunks. /// </summary> /// <param name="padded">If true the length field will be padded to a 4 byte boundary.</param> /// <returns>The length of the chunk.</returns> public override ushort GetChunkLength(bool padded) { var len = (ushort)(SCTP_CHUNK_HEADER_LENGTH + FIXED_PARAMETERS_LENGTH + GetVariableParametersLength(false)); return((padded) ? SctpPadding.PadTo4ByteBoundary(len) : len); }
/// <summary> /// Calculates the length for the chunk. /// </summary> /// <param name="padded">If true the length field will be padded to a 4 byte boundary.</param> /// <returns>The padded length of the chunk.</returns> public override ushort GetChunkLength(bool padded) { ushort len = SCTP_CHUNK_HEADER_LENGTH; if (ErrorCauses != null && ErrorCauses.Count > 0) { foreach (var cause in ErrorCauses) { len += cause.GetErrorCauseLength(padded); } } return((padded) ? SctpPadding.PadTo4ByteBoundary(len) : len); }
/// <summary> /// Gets the length of the optional and variable length parameters for this /// INIT or INIT ACK chunk. /// </summary> /// <param name="padded">If true the length field will be padded to a 4 byte boundary.</param> /// <returns>The length of the optional and variable length parameters.</returns> private ushort GetVariableParametersLength(bool padded) { int len = 0; len += Addresses.Count(x => x.AddressFamily == AddressFamily.InterNetwork) * (SctpTlvChunkParameter.SCTP_PARAMETER_HEADER_LENGTH + PARAMVAL_LENGTH_IPV4); len += Addresses.Count(x => x.AddressFamily == AddressFamily.InterNetworkV6) * (SctpTlvChunkParameter.SCTP_PARAMETER_HEADER_LENGTH + PARAMVAL_LENGTH_IPV6); if (CookiePreservative > 0) { len += SctpTlvChunkParameter.SCTP_PARAMETER_HEADER_LENGTH + PARAMVAL_LENGTH_COOKIE_PRESERVATIVE; } if (!string.IsNullOrEmpty(HostnameAddress)) { len += SctpTlvChunkParameter.SCTP_PARAMETER_HEADER_LENGTH + SctpPadding.PadTo4ByteBoundary(Encoding.UTF8.GetByteCount(HostnameAddress)); } if (SupportedAddressTypes.Count > 0) { len += SctpTlvChunkParameter.SCTP_PARAMETER_HEADER_LENGTH + SctpPadding.PadTo4ByteBoundary(SupportedAddressTypes.Count * 2); } if (StateCookie != null) { len += SctpTlvChunkParameter.SCTP_PARAMETER_HEADER_LENGTH + SctpPadding.PadTo4ByteBoundary(StateCookie.Length); } foreach (var unrecognised in UnrecognizedPeerParameters) { len += SctpTlvChunkParameter.SCTP_PARAMETER_HEADER_LENGTH + unrecognised.GetParameterLength(true); } return((padded) ? SctpPadding.PadTo4ByteBoundary(len) : (ushort)len); }
public ushort GetErrorCauseLength(bool padded) { ushort len = (ushort)(4 + ((!string.IsNullOrEmpty(AdditionalInformation)) ? Encoding.UTF8.GetByteCount(AdditionalInformation) : 0)); return(padded ? SctpPadding.PadTo4ByteBoundary(len) : len); }
public ushort GetErrorCauseLength(bool padded) { ushort len = (ushort)(4 + ((NewAddressTLVs != null) ? NewAddressTLVs.Length : 0)); return(padded ? SctpPadding.PadTo4ByteBoundary(len) : len); }
public ushort GetErrorCauseLength(bool padded) { ushort len = (ushort)(4 + ((UnrecognizedParameters != null) ? UnrecognizedParameters.Length : 0)); return(padded ? SctpPadding.PadTo4ByteBoundary(len) : len); }
public ushort GetErrorCauseLength(bool padded) { ushort len = (ushort)(4 + ((MissingParameters != null) ? MissingParameters.Count * 2 : 0)); return(padded ? SctpPadding.PadTo4ByteBoundary(len) : len); }
/// <summary> /// Extracts the padded length field from a serialised chunk buffer. /// </summary> /// <param name="buffer">The buffer holding the serialised chunk.</param> /// <param name="posn">The start position of the serialised chunk.</param> /// <param name="padded">If true the length field will be padded to a 4 byte boundary.</param> /// <returns>The padded length of the serialised chunk.</returns> public static uint GetChunkLengthFromHeader(byte[] buffer, int posn, bool padded) { ushort len = NetConvert.ParseUInt16(buffer, posn + 2); return((padded) ? SctpPadding.PadTo4ByteBoundary(len) : len); }