Exemplo n.º 1
0
            /// <summary>
            /// Reads COTP TPDU (Transport protocol data unit) from the network stream
            /// See: https://tools.ietf.org/html/rfc905
            /// </summary>
            /// <param name="stream">The socket to read from</param>
            /// <returns>COTP DPDU instance</returns>
            public static TPDU Read(Stream stream)
            {
                var tpkt = TPKT.Read(stream);

                if (tpkt.Length == 0)
                {
                    throw new TPDUInvalidException("No protocol data received");
                }
                return(new TPDU(tpkt));
            }
Exemplo n.º 2
0
            /// <summary>
            /// Reads COTP TPDU (Transport protocol data unit) from the network stream
            /// See: https://tools.ietf.org/html/rfc905
            /// </summary>
            /// <param name="stream">The socket to read from</param>
            /// <returns>COTP DPDU instance</returns>
            public static async Task <TPDU> ReadAsync(Stream stream, CancellationToken cancellationToken)
            {
                var tpkt = await TPKT.ReadAsync(stream, cancellationToken).ConfigureAwait(false);

                if (tpkt.Length == 0)
                {
                    throw new TPDUInvalidException("No protocol data received");
                }
                return(new TPDU(tpkt));
            }
Exemplo n.º 3
0
            public TPDU(TPKT tPKT)
            {
                TPkt = tPKT;

                HeaderLength = tPKT.Data[0]; // Header length excluding this length byte
                if (HeaderLength >= 2)
                {
                    PDUType = (PduType)tPKT.Data[1];
                    if (PDUType == PduType.Data) //DT Data
                    {
                        var flags = tPKT.Data[2];
                        TPDUNumber   = flags & 0x7F;
                        LastDataUnit = (flags & 0x80) > 0;
                        Data         = new byte[tPKT.Data.Length - HeaderLength - 1]; // substract header length byte + header length.
                        Array.Copy(tPKT.Data, HeaderLength + 1, Data, 0, Data.Length);
                        return;
                    }
                    //TODO: Handle other PDUTypes
                }
                Data = new byte[0];
            }