Skip to content

Commit 508f367

Browse files
author
-
committed
v2.0.0.2: Modified GetNetworkInterfaceIPs to only return IP Addresses on operational network interfaces.
Truncated data sent by network data diagnostic trace to reduce output size under high packet loss conditions. Minor test updates.
1 parent d4a381d commit 508f367

File tree

11 files changed

+35
-14
lines changed

11 files changed

+35
-14
lines changed

Machina.FFXIV/FFXIVBundleDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public unsafe void StoreData(byte[] buffer)
123123
if (message_offset > messageBufferSize)
124124
{
125125
Trace.WriteLine("FFXIVBundleDecoder: Bad message offset - offset=" + message_offset.ToString() + ", bufferSize=" + messageBufferSize.ToString() +
126-
", data: " + Utility.ByteArrayToHexString(data));
126+
", data: " + Utility.ByteArrayToHexString(data, 0, 50));
127127

128128
_allocated = 0;
129129
return;

Machina.FFXIV/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.0.0.1")]
36-
[assembly: AssemblyFileVersion("2.0.0.1")]
35+
[assembly: AssemblyVersion("2.0.0.2")]
36+
[assembly: AssemblyFileVersion("2.0.0.2")]

Machina.Tests/FirewallWrapperTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public void FirewallWrapper_IsFirewallDisabledTest()
2323
var sut = new FirewallWrapper();
2424

2525
var result = sut.IsFirewallDisabled();
26-
Assert.IsTrue(result);
26+
27+
// result could be either true or false based on local configuration.
28+
2729
Assert.AreEqual(0, TestInfrastructure.Listener.Messages.Count);
2830
}
2931

Machina.Tests/IPDecoderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ public void IPDecoder_GetNextIPPayload_SingleFragmentTimeout()
478478
Assert.AreEqual(i + 11, ret[i]);
479479

480480
Assert.AreEqual(0, sut.Fragments.Count);
481-
Assert.AreEqual(1, TestInfrastructure.Listener.Messages.Count);
482-
Assert.IsTrue(TestInfrastructure.Listener.Messages[0].Contains("fragment purged"));
481+
Assert.AreEqual(0, TestInfrastructure.Listener.Messages.Count);
483482
}
484483

485484
/// <summary>

Machina.Tests/RawPCapTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Threading;
2121

2222
using Machina;
23+
using System.Threading.Tasks;
2324

2425
namespace Machina.Tests
2526
{
@@ -39,16 +40,23 @@ public void TestCleanup()
3940
[TestMethod()]
4041
public void RawPCap_GetDataTwiceTest()
4142
{
42-
string ip = Utility.GetNetworkInterfaceIPs().First();
43+
string ip = Utility.GetNetworkInterfaceIPs().FirstOrDefault();
44+
Assert.IsTrue(!string.IsNullOrEmpty(ip), "Unable to locate a network interface to test WinPCap capture.");
45+
4346
System.Net.IPAddress address = System.Net.IPAddress.Parse(ip);
4447

4548
var sut = new RawPCap();
4649

50+
// start an async download
51+
System.Net.WebClient client = new System.Net.WebClient();
52+
Task t = client.DownloadStringTaskAsync("http://www.google.com");
53+
4754
int receivedCount = 0;
4855

4956
try
5057
{
5158
sut.Create((uint)address.Address);
59+
t.Wait();
5260

5361
byte[] buffer;
5462
for (int i = 0; i < 100; i++)

Machina.Tests/RawSocketTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using System.Linq;
2222

2323
using Machina;
24+
using System.Threading.Tasks;
2425

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

4749
var sut = new RawSocket();
4850

51+
// start an async download
52+
System.Net.WebClient client = new System.Net.WebClient();
53+
Task t = client.DownloadStringTaskAsync("http://www.google.com");
54+
4955
int receivedCount = 0;
5056

5157
try
5258
{
5359
sut.Create((uint)address.Address);
60+
t.Wait();
5461

5562
byte[] buffer;
5663
for (int i=0;i<100;i++)

Machina.Tests/TCPNetworkMonitorTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ public void TCPNetworkMonitor_RawSocket_SendAndReceiveData()
3333

3434
for (int i=0;i<100;i++)
3535
{
36-
if (dataReceivedCount > 2)
36+
if (dataSentCount > 1 && dataReceivedCount > 1)
3737
break;
3838

3939
System.Threading.Thread.Sleep(10);
4040
}
4141

42+
monitor.Stop();
43+
4244
Assert.IsTrue(dataReceivedCount >= 1);
4345
Assert.IsTrue(dataSentCount >= 1);
4446
}

Machina/IPDecoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ public unsafe byte[] GetNextIPPayload()
255255
Fragments.RemoveAt(j);
256256
else if (Utility.ntohs(BitConverter.ToUInt16(Fragments[j], 4)) < currentId - 99)
257257
{
258-
Trace.WriteLine("IP: Old fragment purged. Current ID: [" + currentId.ToString("X4") + "], Old ID: + [" +
259-
IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(Fragments[j], 4)) + "] " + Utility.ByteArrayToHexString(Fragments[j]));
258+
//Trace.WriteLine("IP: Old fragment purged. Current ID: [" + currentId.ToString("X4") + "], Old ID: + [" +
259+
//IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(Fragments[j], 4)) + "] " + Utility.ByteArrayToHexString(Fragments[j], 0, 50));
260260
Fragments.RemoveAt(j);
261261
}
262262
}

Machina/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("2.0.0.1")]
54+
[assembly: AssemblyVersion("2.0.0.2")]
5555
[assembly: AssemblyInformationalVersion("1.0.0.0")]
56-
[assembly: AssemblyFileVersion("2.0.0.1")]
56+
[assembly: AssemblyFileVersion("2.0.0.2")]
5757

Machina/TCPDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public unsafe byte[] GetNextTCPDatagram()
155155
if (packetOffset >= packet.Length - header.DataOffset)
156156
{
157157
// this packet will get removed once we exit the loop.
158-
Trace.WriteLine("TCPDecoder: packet data already processed, expected sequence [" + _NextSequence.ToString() + "], received [" + header.SequenceNumber + "], size [" + (packet.Length - header.DataOffset) + "]. Data: " + Utility.ByteArrayToHexString(packet));
158+
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));
159159
continue;
160160
}
161161

0 commit comments

Comments
 (0)