Commit 689c2352 authored by Brickner_cp's avatar Brickner_cp

ARP read sender protocol address as IPv4 address.

TCP calculate payload length and next sequence number.
Code Coverage 95.02%
parent a02ebcf1
......@@ -301,7 +301,7 @@ namespace PcapDotNet.Core.Test
// Wait for more statistics
TestGetStatistics(SourceMac, DestinationMac, NumPacketsToSend, 0, int.MaxValue, 5.5, PacketSize,
PacketCommunicatorReceiveResult.None, 5, NumPacketsToSend, 5.5, 5.54);
PacketCommunicatorReceiveResult.None, 5, NumPacketsToSend, 5.5, 5.85);
// Break loop
TestGetStatistics(SourceMac, DestinationMac, NumPacketsToSend, NumStatisticsToGather, 0, 5, PacketSize,
......
......@@ -446,6 +446,13 @@ namespace PcapDotNet.Core.Test
case "eth.type":
field.AssertShowHex((ushort)ethernetDatagram.EtherType);
break;
case "eth.trailer":
case "":
break;
default:
throw new InvalidOperationException("Invalid etherent field " + field.Name());
}
}
}
......@@ -476,25 +483,38 @@ namespace PcapDotNet.Core.Test
field.AssertShowHex((ushort)arpDatagram.Operation);
break;
// case "arp.isgratuitous":
// field.AssertShowDecimal(false);
// break;
case "arp.src.hw":
case "arp.src.hw_mac":
field.AssertShow(arpDatagram.SenderHardwareAddress.BytesSequenceToHexadecimalString(":"));
break;
case "arp.src.proto":
field.AssertShow(arpDatagram.SenderProtocolAddress.BytesSequenceToHexadecimalString(":"));
break;
case "arp.src.proto_ipv4":
field.AssertShow(arpDatagram.SenderProtocolIpV4Address.ToString());
break;
case "arp.dst.hw":
case "arp.dst.hw_mac":
field.AssertShow(arpDatagram.TargetHardwareAddress.BytesSequenceToHexadecimalString(":"));
break;
case "arp.dst.proto":
field.AssertShow(arpDatagram.TargetProtocolAddress.BytesSequenceToHexadecimalString(":"));
break;
case "arp.dst.proto_ipv4":
field.AssertShow(arpDatagram.TargetProtocolIpV4Address.ToString());
break;
case "arp.isgratuitous":
break;
default:
throw new InvalidOperationException("Invalid arp field " + field.Name());
}
}
}
......@@ -508,6 +528,13 @@ namespace PcapDotNet.Core.Test
case "eth.addr":
field.AssertShow(address.ToString().ToLower());
break;
case "eth.ig":
case "eth.lg":
break;
default:
throw new InvalidOperationException("Invalid ethernet address field " + field.Name());
}
}
}
......@@ -576,16 +603,27 @@ namespace PcapDotNet.Core.Test
break;
case "ip.src":
case "ip.src_host":
field.AssertShow(ipV4Datagram.Source.ToString());
break;
case "ip.dst":
case "ip.dst_host":
field.AssertShow(ipV4Datagram.Destination.ToString());
break;
case "ip.addr":
case "ip.host":
Assert.IsTrue(field.Show() == ipV4Datagram.Source.ToString() ||
field.Show() == ipV4Datagram.Destination.ToString());
break;
case "":
CompareIpV4Options(field, ipV4Datagram.Options);
break;
default:
throw new InvalidOperationException("Invalid ip field " + field.Name());
}
}
}
......@@ -701,7 +739,7 @@ namespace PcapDotNet.Core.Test
break;
default:
throw new InvalidOperationException("Invalid field name " + field.Name());
throw new InvalidOperationException("Invalid igmp field " + field.Name());
}
}
}
......@@ -738,7 +776,7 @@ namespace PcapDotNet.Core.Test
break;
default:
throw new InvalidOperationException("Invalid field name " + field.Name());
throw new InvalidOperationException("Invalid igmp group record field " + field.Name());
}
}
}
......@@ -759,6 +797,11 @@ namespace PcapDotNet.Core.Test
field.AssertShowDecimal(udpDatagram.DestinationPort);
break;
case "udp.port":
Assert.IsTrue(ushort.Parse(field.Show()) == udpDatagram.SourcePort ||
ushort.Parse(field.Show()) == udpDatagram.DestinationPort);
break;
case "udp.length":
field.AssertShowDecimal(udpDatagram.TotalLength);
break;
......@@ -782,6 +825,13 @@ namespace PcapDotNet.Core.Test
}
}
break;
case "udp.checksum_coverage":
field.AssertShowDecimal(udpDatagram.Length);
break;
default:
throw new InvalidOperationException("Invalid udp field " + field.Name());
}
}
}
......@@ -794,6 +844,10 @@ namespace PcapDotNet.Core.Test
{
switch (field.Name())
{
case "tcp.len":
field.AssertShowDecimal(tcpDatagram.Payload.Length);
break;
case "tcp.srcport":
field.AssertShowDecimal(tcpDatagram.SourcePort);
break;
......@@ -802,10 +856,20 @@ namespace PcapDotNet.Core.Test
field.AssertShowDecimal(tcpDatagram.DestinationPort);
break;
case "tcp.port":
Assert.IsTrue(ushort.Parse(field.Show()) == tcpDatagram.SourcePort ||
ushort.Parse(field.Show()) == tcpDatagram.DestinationPort);
break;
case "tcp.seq":
field.AssertShowDecimal(tcpDatagram.SequenceNumber);
break;
case "tcp.nxtseq":
field.AssertShowDecimal(tcpDatagram.NextSequenceNumber);
break;
case "tcp.ack":
field.AssertShowDecimal(tcpDatagram.AcknowledgmentNumber);
break;
......@@ -883,6 +947,14 @@ namespace PcapDotNet.Core.Test
case "tcp.options":
CompareTcpOptions(field, tcpDatagram.Options);
break;
case "tcp.stream":
case "tcp.pdu.size":
case "":
break;
default:
throw new InvalidOperationException("Invalid tcp field " + field.Name());
}
}
}
......@@ -958,9 +1030,9 @@ namespace PcapDotNet.Core.Test
case "tcp.options.snack.size":
Assert.AreEqual((TcpOptionType)21, option.OptionType);
break;
default:
throw new InvalidOperationException(field.Name());
throw new InvalidOperationException("Invalid tcp options field " + field.Name());
}
if ((option is TcpOptionUnknown))
......
......@@ -2,6 +2,7 @@ using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets.Arp;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.TestUtils;
......@@ -94,6 +95,19 @@ namespace PcapDotNet.Packets.Test
}
}
[TestMethod]
public void ArpProtocolIpV4Address()
{
Packet packet = PacketBuilder.EthernetArp(DateTime.Now,
new MacAddress(),
EthernetType.QInQ, ArpOperation.Request,
new byte[8], new byte[] {1,2,3,4},
new byte[8], new byte[] {11,22,33,44});
Assert.AreEqual(new IpV4Address("1.2.3.4"), packet.Ethernet.Arp.SenderProtocolIpV4Address);
Assert.AreEqual(new IpV4Address("11.22.33.44"), packet.Ethernet.Arp.TargetProtocolIpV4Address);
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ArpIncosistentSenderAddressSizeTest()
......
using System;
using System.Collections.ObjectModel;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Arp
{
......@@ -112,6 +113,14 @@ namespace PcapDotNet.Packets.Arp
get { return new ReadOnlyCollection<byte>(ReadBytes(OffsetSenderProtocolAddress, ProtocolLength)); }
}
/// <summary>
/// Protocol IPv4 address of the sender.
/// </summary>
public IpV4Address SenderProtocolIpV4Address
{
get { return ReadIpV4Address(OffsetSenderProtocolAddress, Endianity.Big); }
}
/// <summary>
/// Hardware address of the intended receiver.
/// This field is ignored in requests.
......@@ -129,6 +138,14 @@ namespace PcapDotNet.Packets.Arp
get { return new ReadOnlyCollection<byte>(ReadBytes(OffsetTargetProtocolAddress, ProtocolLength)); }
}
/// <summary>
/// Protocol IPv4 address of the intended receiver.
/// </summary>
public IpV4Address TargetProtocolIpV4Address
{
get { return ReadIpV4Address(OffsetTargetProtocolAddress, Endianity.Big); }
}
/// <summary>
/// The datagram is valid if the length is correct according to the header.
/// </summary>
......
......@@ -54,6 +54,11 @@ namespace PcapDotNet.Packets.Transport
get { return ReadUInt(Offset.SequenceNumber, Endianity.Big); }
}
public uint NextSequenceNumber
{
get { return (uint)(SequenceNumber + PayloadLength); }
}
/// <summary>
/// If the ACK control bit is set this field contains the value of the next sequence number
/// the sender of the segment is expecting to receive.
......@@ -163,7 +168,12 @@ namespace PcapDotNet.Packets.Transport
/// </summary>
public Datagram Payload
{
get { return new Datagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength); }
get { return new Datagram(Buffer, StartOffset + HeaderLength, PayloadLength); }
}
public int PayloadLength
{
get { return Length - HeaderLength; }
}
/// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment