/// <summary> /// Parses an SCTP packet from a serialised buffer. /// </summary> /// <param name="buffer">The buffer holding the serialised packet.</param> /// <param name="offset">The position in the buffer of the packet.</param> /// <param name="length">The length of the serialised packet in the buffer.</param> public static SctpPacket Parse(byte[] buffer, int offset, int length) { var pkt = new SctpPacket(); pkt.Header = SctpHeader.Parse(buffer, offset); (pkt.Chunks, pkt.UnrecognisedChunks) = ParseChunks(buffer, offset, length); return(pkt); }
/// <summary> /// Creates a new SCTP packet instance. /// </summary> /// <param name="sourcePort">The source port value to place in the packet header.</param> /// <param name="destinationPort">The destination port value to place in the packet header.</param> /// <param name="verificationTag">The verification tag value to place in the packet header.</param> public SctpPacket( ushort sourcePort, ushort destinationPort, uint verificationTag) { Header = new SctpHeader { SourcePort = sourcePort, DestinationPort = destinationPort, VerificationTag = verificationTag }; Chunks = new List <SctpChunk>(); UnrecognisedChunks = new List <byte[]>(); }
/// <summary> /// Parses the an SCTP header from a buffer. /// </summary> /// <param name="buffer">The buffer to parse the SCTP header from.</param> /// <param name="posn">The position in the buffer to start parsing the header from.</param> /// <returns>A new SCTPHeaer instance.</returns> public static SctpHeader Parse(byte[] buffer, int posn) { if (buffer.Length < SCTP_HEADER_LENGTH) { throw new ApplicationException("The buffer did not contain the minimum number of bytes for an SCTP header."); } SctpHeader header = new SctpHeader(); header.SourcePort = NetConvert.ParseUInt16(buffer, posn); header.DestinationPort = NetConvert.ParseUInt16(buffer, posn + 2); header.VerificationTag = NetConvert.ParseUInt32(buffer, posn + 4); header.Checksum = NetConvert.ParseUInt32(buffer, posn + 8); return(header); }