public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer) { EthernetType ethernetType = EthernetBaseLayer.GetEthernetType(this.EtherType, nextLayer); MacAddress destination = this.Destination; IEthernetNextLayer ethernetNextLayer = nextLayer as IEthernetNextLayer; if (destination == MacAddress.Zero && ethernetNextLayer != null && ethernetNextLayer.PreviousLayerDefaultDestination.HasValue) { destination = ethernetNextLayer.PreviousLayerDefaultDestination.Value; } EthernetDatagram.WriteHeader(buffer, offset, this.Source, destination, ethernetType); }
internal static EthernetType GetEthernetType(EthernetType ethernetType, ILayer nextLayer) { if (ethernetType != EthernetType.None) { return(ethernetType); } if (nextLayer == null) { throw new ArgumentException("Can't determine ether type automatically from next layer because there is not next layer"); } IEthernetNextLayer ethernetNextLayer = nextLayer as IEthernetNextLayer; if (ethernetNextLayer == null) { throw new ArgumentException("Can't determine ether type automatically from next layer (" + (object)nextLayer.GetType() + ")"); } return(ethernetNextLayer.PreviousLayerEtherType); }
public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer) { EthernetType protocolType = this.ProtocolType; if (protocolType == EthernetType.None) { if (nextLayer == null) { throw new ArgumentException("Can't determine protocol type automatically from next layer because there is not next layer"); } IEthernetNextLayer ethernetNextLayer = nextLayer as IEthernetNextLayer; if (ethernetNextLayer == null) { throw new ArgumentException("Can't determine protocol type automatically from next layer (" + (object)nextLayer.GetType() + ")"); } protocolType = ethernetNextLayer.PreviousLayerEtherType; } GreDatagram.WriteHeader(buffer, offset, this.RecursionControl, this.FutureUseBits, this.Version, protocolType, this.ChecksumPresent, this.Key, this.SequenceNumber, this.AcknowledgmentSequenceNumber, this.Routing, this.RoutingOffset, this.StrictSourceRoute); }