Skip to content

Commit

Permalink
v2.0.0.2: Modified GetNetworkInterfaceIPs to only return IP Addresses…
Browse files Browse the repository at this point in the history
… on operational network interfaces.

Truncated data sent by network data diagnostic trace to reduce output size under high packet loss conditions.

Minor test updates.
  • Loading branch information
- committed Nov 10, 2017
1 parent d4a381d commit 508f367
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Machina.FFXIV/FFXIVBundleDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public unsafe void StoreData(byte[] buffer)
if (message_offset > messageBufferSize)
{
Trace.WriteLine("FFXIVBundleDecoder: Bad message offset - offset=" + message_offset.ToString() + ", bufferSize=" + messageBufferSize.ToString() +
", data: " + Utility.ByteArrayToHexString(data));
", data: " + Utility.ByteArrayToHexString(data, 0, 50));

_allocated = 0;
return;
Expand Down
4 changes: 2 additions & 2 deletions Machina.FFXIV/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.1")]
[assembly: AssemblyFileVersion("2.0.0.1")]
[assembly: AssemblyVersion("2.0.0.2")]
[assembly: AssemblyFileVersion("2.0.0.2")]
4 changes: 3 additions & 1 deletion Machina.Tests/FirewallWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public void FirewallWrapper_IsFirewallDisabledTest()
var sut = new FirewallWrapper();

var result = sut.IsFirewallDisabled();
Assert.IsTrue(result);

// result could be either true or false based on local configuration.

Assert.AreEqual(0, TestInfrastructure.Listener.Messages.Count);
}

Expand Down
3 changes: 1 addition & 2 deletions Machina.Tests/IPDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,7 @@ public void IPDecoder_GetNextIPPayload_SingleFragmentTimeout()
Assert.AreEqual(i + 11, ret[i]);

Assert.AreEqual(0, sut.Fragments.Count);
Assert.AreEqual(1, TestInfrastructure.Listener.Messages.Count);
Assert.IsTrue(TestInfrastructure.Listener.Messages[0].Contains("fragment purged"));
Assert.AreEqual(0, TestInfrastructure.Listener.Messages.Count);
}

/// <summary>
Expand Down
10 changes: 9 additions & 1 deletion Machina.Tests/RawPCapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Threading;

using Machina;
using System.Threading.Tasks;

namespace Machina.Tests
{
Expand All @@ -39,16 +40,23 @@ public void TestCleanup()
[TestMethod()]
public void RawPCap_GetDataTwiceTest()
{
string ip = Utility.GetNetworkInterfaceIPs().First();
string ip = Utility.GetNetworkInterfaceIPs().FirstOrDefault();
Assert.IsTrue(!string.IsNullOrEmpty(ip), "Unable to locate a network interface to test WinPCap capture.");

System.Net.IPAddress address = System.Net.IPAddress.Parse(ip);

var sut = new RawPCap();

// start an async download
System.Net.WebClient client = new System.Net.WebClient();
Task t = client.DownloadStringTaskAsync("http://www.google.com");

int receivedCount = 0;

try
{
sut.Create((uint)address.Address);
t.Wait();

byte[] buffer;
for (int i = 0; i < 100; i++)
Expand Down
9 changes: 8 additions & 1 deletion Machina.Tests/RawSocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Linq;

using Machina;
using System.Threading.Tasks;

namespace Machina.Tests
{
Expand All @@ -41,16 +42,22 @@ public void TestCleanup()
[TestMethod()]
public void RawSocket_GetDataTwiceTest()
{
string ip = Utility.GetNetworkInterfaceIPs().First();
string ip = Utility.GetNetworkInterfaceIPs().FirstOrDefault();
Assert.IsTrue(!string.IsNullOrEmpty(ip), "Unable to locate a network interface to test RawSocket.");
System.Net.IPAddress address = System.Net.IPAddress.Parse(ip);

var sut = new RawSocket();

// start an async download
System.Net.WebClient client = new System.Net.WebClient();
Task t = client.DownloadStringTaskAsync("http://www.google.com");

int receivedCount = 0;

try
{
sut.Create((uint)address.Address);
t.Wait();

byte[] buffer;
for (int i=0;i<100;i++)
Expand Down
4 changes: 3 additions & 1 deletion Machina.Tests/TCPNetworkMonitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ public void TCPNetworkMonitor_RawSocket_SendAndReceiveData()

for (int i=0;i<100;i++)
{
if (dataReceivedCount > 2)
if (dataSentCount > 1 && dataReceivedCount > 1)
break;

System.Threading.Thread.Sleep(10);
}

monitor.Stop();

Assert.IsTrue(dataReceivedCount >= 1);
Assert.IsTrue(dataSentCount >= 1);
}
Expand Down
4 changes: 2 additions & 2 deletions Machina/IPDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ public unsafe byte[] GetNextIPPayload()
Fragments.RemoveAt(j);
else if (Utility.ntohs(BitConverter.ToUInt16(Fragments[j], 4)) < currentId - 99)
{
Trace.WriteLine("IP: Old fragment purged. Current ID: [" + currentId.ToString("X4") + "], Old ID: + [" +
IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(Fragments[j], 4)) + "] " + Utility.ByteArrayToHexString(Fragments[j]));
//Trace.WriteLine("IP: Old fragment purged. Current ID: [" + currentId.ToString("X4") + "], Old ID: + [" +
//IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(Fragments[j], 4)) + "] " + Utility.ByteArrayToHexString(Fragments[j], 0, 50));
Fragments.RemoveAt(j);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Machina/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.1")]
[assembly: AssemblyVersion("2.0.0.2")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.1")]
[assembly: AssemblyFileVersion("2.0.0.2")]

2 changes: 1 addition & 1 deletion Machina/TCPDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public unsafe byte[] GetNextTCPDatagram()
if (packetOffset >= packet.Length - header.DataOffset)
{
// this packet will get removed once we exit the loop.
Trace.WriteLine("TCPDecoder: packet data already processed, expected sequence [" + _NextSequence.ToString() + "], received [" + header.SequenceNumber + "], size [" + (packet.Length - header.DataOffset) + "]. Data: " + Utility.ByteArrayToHexString(packet));
Trace.WriteLine("TCPDecoder: packet data already processed, expected sequence [" + _NextSequence.ToString() + "], received [" + header.SequenceNumber + "], size [" + (packet.Length - header.DataOffset) + "]. Data: " + Utility.ByteArrayToHexString(packet, 0, 50));
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions Machina/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public static List<string> GetNetworkInterfaceIPs()

foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces())
{
if (netInterface.OperationalStatus != OperationalStatus.Up)
continue;

IPInterfaceProperties ipProps = netInterface.GetIPProperties();
foreach (string ip in ipProps.UnicastAddresses.Select(x => x.Address.ToString() ?? ""))
if (ip.Length <= 15 && ip.Contains('.')) // ipv4 addresses only
Expand Down

0 comments on commit 508f367

Please sign in to comment.