public byte[] encode()
        {
            int option_size = 0;

            if (this.options_and_padding != null)
            {
                option_size = this.options_and_padding.Length;
            }
            int data_size = 0;

            if (this.data != null)
            {
                data_size = this.data.Length;
            }
            if (this.b_comput_internet_header_length)
            {
                this.internet_header_length = (byte)(5 + option_size / 4);
            }
            ushort real_total_length = (UInt16)(20 + option_size + data_size);

            if (this.b_comput_total_length)
            {
                this.total_length = real_total_length;
            }
            byte[] ret = new byte[this.total_length];

            ret[0] = (byte)((this.version << 4) + this.internet_header_length);
            ret[1] = this.type_of_service;
            System.Array.Copy(System.BitConverter.GetBytes(this.total_length), 0, ret, 2, 2);
            System.Array.Copy(System.BitConverter.GetBytes(this.identification), 0, ret, 4, 2);
            ret[6] = (byte)((this.flags << 5) + ((this.fragment_offset >> 8) & 0x1f));
            ret[7] = (byte)(this.fragment_offset & 0xff);
            ret[8] = this.time_to_live;
            ret[9] = this.protocol;
            if (this.b_comput_header_checksum)
            {
                this.header_checksum = 0;
            }
            System.Array.Copy(System.BitConverter.GetBytes(this.header_checksum), 0, ret, 10, 2);
            System.Array.Copy(System.BitConverter.GetBytes(this.source_address), 0, ret, 12, 4);
            System.Array.Copy(System.BitConverter.GetBytes(this.destination_address), 0, ret, 16, 4);

            // adding options
            if (option_size > 0)
            {
                System.Array.Copy(this.options_and_padding, 0, ret, 20, option_size);
            }
            if (this.b_comput_header_checksum)
            {
                // comput checksum
                this.header_checksum = Cchecksum.checksum(ret, true);
                System.Array.Copy(System.BitConverter.GetBytes(this.header_checksum), 0, ret, 10, 2);
            }
            // adding data
            if (data_size > 0)
            {
                System.Array.Copy(this.data, 0, ret, 20 + option_size, data_size);
            }
            return(ret);
        }
        public override byte[] encode()
        {
            byte[] ret = new byte[20];
            ret[0] = this.type;
            ret[1] = this.code;
            if (!this.b_comput_checksum)
            {
                System.Array.Copy(System.BitConverter.GetBytes(this.checksum), 0, ret, 2, 2);
            }
            else
            {
                // checksum to 0
                ret[2] = 0;
                ret[3] = 0;
            }


            System.Array.Copy(System.BitConverter.GetBytes(this.identifier), 0, ret, 4, 2);
            System.Array.Copy(System.BitConverter.GetBytes(this.sequence_number), 0, ret, 6, 2);
            System.Array.Copy(System.BitConverter.GetBytes(this.originate_timestamp), 0, ret, 8, 4);
            System.Array.Copy(System.BitConverter.GetBytes(this.receive_timestamp), 0, ret, 12, 4);
            System.Array.Copy(System.BitConverter.GetBytes(this.transmit_timestamp), 0, ret, 16, 4);

            if (this.b_comput_checksum)
            {
                // comput checksum
                this.checksum = Cchecksum.checksum(ret, true);
                System.Array.Copy(System.BitConverter.GetBytes(this.checksum), 0, ret, 2, 2);
            }
            return(ret);
        }
        public override byte[] encode()
        {
            byte[] ret = new byte[8];

            ret[0] = this.type;
            ret[1] = this.code;
            if (!this.b_comput_checksum)
            {
                System.Array.Copy(System.BitConverter.GetBytes(this.checksum), 0, ret, 2, 2);
            }
            else
            {
                // checksum to 0
                ret[2] = 0;
                ret[3] = 0;
            }

            System.Array.Copy(System.BitConverter.GetBytes(this.identifier), 0, ret, 4, 2);
            System.Array.Copy(System.BitConverter.GetBytes(this.sequence_number), 0, ret, 6, 2);

            if (this.b_comput_checksum)
            {
                // comput checksum
                this.checksum = Cchecksum.checksum(ret, true);
                System.Array.Copy(System.BitConverter.GetBytes(this.checksum), 0, ret, 2, 2);
            }

            System.Array.Copy(System.BitConverter.GetBytes(this.checksum), 0, ret, 2, 2);
            return(ret);
        }
        public override byte[] encode()
        {
            int ih_and_original_dd_size = 0;

            if (this.ih_and_original_dd != null)
            {
                ih_and_original_dd_size = this.ih_and_original_dd.Length;
            }
            byte[] ret = new byte[8 + ih_and_original_dd_size];

            ret[0] = this.type;
            ret[1] = this.code;
            if (!this.b_comput_checksum)
            {
                System.Array.Copy(System.BitConverter.GetBytes(this.checksum), 0, ret, 2, 2);
            }
            else
            {
                // checksum to 0
                ret[2] = 0;
                ret[3] = 0;
            }

            ret[4] = this.pointer;
            // unused
            System.Array.Copy(System.BitConverter.GetBytes(this.unused), 1, ret, 5, 3);
            if (ih_and_original_dd_size > 0)
            {
                System.Array.Copy(this.ih_and_original_dd, 0, ret, 8, ih_and_original_dd_size);
            }
            if (this.b_comput_checksum)
            {
                // comput checksum
                this.checksum = Cchecksum.checksum(ret, true);
                System.Array.Copy(System.BitConverter.GetBytes(this.checksum), 0, ret, 2, 2);
            }
            return(ret);
        }
        public override byte[] encode()
        {
            int data_size = 0;

            if (this.data != null)
            {
                data_size = this.data.Length;
            }
            byte[] ret = new byte[8 + data_size];

            ret[0] = this.type;
            ret[1] = this.code;
            if (!this.b_comput_checksum)
            {
                System.Array.Copy(System.BitConverter.GetBytes(this.checksum), 0, ret, 2, 2);
            }
            else
            {
                // checksum to 0
                ret[2] = 0;
                ret[3] = 0;
            }
            System.Array.Copy(System.BitConverter.GetBytes(this.identifier), 0, ret, 4, 2);
            System.Array.Copy(System.BitConverter.GetBytes(this.sequence_number), 0, ret, 6, 2);
            if (data_size > 0)
            {
                System.Array.Copy(this.data, 0, ret, 8, data_size);
            }

            if (this.b_comput_checksum)
            {
                // comput checksum
                this.checksum = Cchecksum.checksum(ret, true);
                System.Array.Copy(System.BitConverter.GetBytes(this.checksum), 0, ret, 2, 2);
            }
            return(ret);
        }