コード例 #1
0
ファイル: IpV6Datagram.cs プロジェクト: pedoc/Pcap.Net
        internal static void WriteHeader(byte[] buffer, int offset,
                                         byte trafficClass, int flowLabel, ushort payloadLength, IpV4Protocol?nextHeader, IpV4Protocol?nextLayerProtocol,
                                         byte hopLimit, IpV6Address source, IpV6Address currentDestination, IpV6ExtensionHeaders extensionHeaders)
        {
            buffer.Write(offset + Offset.Version, (uint)((((DefaultVersion << 8) | trafficClass) << 20) | flowLabel), Endianity.Big);
            buffer.Write(offset + Offset.PayloadLength, payloadLength, Endianity.Big);
            IpV4Protocol actualNextHeader;

            if (nextHeader.HasValue)
            {
                actualNextHeader = nextHeader.Value;
            }
            else if (extensionHeaders.Any())
            {
                actualNextHeader = extensionHeaders.FirstHeader.Value;
            }
            else if (nextLayerProtocol.HasValue)
            {
                actualNextHeader = nextLayerProtocol.Value;
            }
            else
            {
                throw new InvalidOperationException("Can't determine next header. No extension headers and no known next layer protocol.");
            }
            buffer.Write(offset + Offset.NextHeader, (byte)actualNextHeader);
            buffer.Write(offset + Offset.HopLimit, hopLimit);
            buffer.Write(offset + Offset.SourceAddress, source, Endianity.Big);
            buffer.Write(offset + Offset.DestinationAddress, currentDestination, Endianity.Big);
            extensionHeaders.Write(buffer, offset + HeaderLength, nextLayerProtocol);
        }
コード例 #2
0
ファイル: IpV6Datagram.cs プロジェクト: amitla/Pcap.Net
 internal static void WriteHeader(byte[] buffer, int offset,
                                  byte trafficClass, int flowLabel, ushort payloadLength, IpV4Protocol? nextHeader, IpV4Protocol? nextLayerProtocol,
                                  byte hopLimit, IpV6Address source, IpV6Address currentDestination, IpV6ExtensionHeaders extensionHeaders)
 {
     buffer.Write(offset + Offset.Version, (uint)((((DefaultVersion << 8) | trafficClass) << 20) | flowLabel), Endianity.Big);
     buffer.Write(offset + Offset.PayloadLength, payloadLength, Endianity.Big);
     IpV4Protocol actualNextHeader;
     if (nextHeader.HasValue)
         actualNextHeader = nextHeader.Value;
     else if (extensionHeaders.Any())
         actualNextHeader = extensionHeaders.FirstHeader.Value;
     else if (nextLayerProtocol.HasValue)
         actualNextHeader = nextLayerProtocol.Value;
     else
         throw new InvalidOperationException("Can't determine next header. No extension headers and no known next layer protocol.");
     buffer.Write(offset + Offset.NextHeader, (byte)actualNextHeader);
     buffer.Write(offset + Offset.HopLimit, hopLimit);
     buffer.Write(offset + Offset.SourceAddress, source, Endianity.Big);
     buffer.Write(offset + Offset.DestinationAddress, currentDestination, Endianity.Big);
     extensionHeaders.Write(buffer, offset + HeaderLength, nextLayerProtocol);
 }