Exemple #1
0
        /// <summary>
        /// Writes the layer to the buffer.
        /// </summary>
        /// <param name="buffer">The buffer to write the layer to.</param>
        /// <param name="offset">The offset in the buffer to start writing the layer at.</param>
        /// <param name="payloadLength">The length of the layer's payload (the number of bytes after the layer in the packet).</param>
        /// <param name="previousLayer">The layer that comes before this layer. null if this is the first layer.</param>
        /// <param name="nextLayer">The layer that comes after this layer. null if this is the last layer.</param>
        public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer)
        {
            EthernetType etherType = GetEthernetType(EtherType, nextLayer);

            MacAddress         destination       = Destination;
            IEthernetNextLayer ethernetNextLayer = nextLayer as IEthernetNextLayer;

            if (destination == MacAddress.Zero)
            {
                if (ethernetNextLayer != null && ethernetNextLayer.PreviousLayerDefaultDestination != null)
                {
                    destination = ethernetNextLayer.PreviousLayerDefaultDestination.Value;
                }
            }

            EthernetDatagram.WriteHeader(buffer, offset, Source, destination, etherType);
        }
Exemple #2
0
 internal static void WriteHeader(byte[] buffer, int offset, MacAddress ethernetSource, MacAddress ethernetDestination, EthernetType ethernetType)
 {
     buffer.Write(offset + Offset.Source, ethernetSource, Endianity.Big);
     buffer.Write(offset + Offset.Destination, ethernetDestination, Endianity.Big);
     buffer.Write(offset + Offset.EtherTypeLength, (ushort)ethernetType, Endianity.Big);
 }