forked from Loriowar/IpHlpApidotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cs
50 lines (45 loc) · 1.44 KB
/
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Text;
using System.Net;
using System.Collections.Generic;
namespace IpHlpApidotnet
{
public enum Protocol { TCP, UDP, None };
public class SortConnections : IComparer<TCPUDPConnection>
{
/// <summary>
/// Method is used to compare two <seealso cref="TCPUDPConnection"/>.
///
/// </summary>
/// <param name="first"></param>
/// <param name="second"></param>
/// <returns></returns>
public virtual int CompareConnections(TCPUDPConnection first, TCPUDPConnection second)
{
int i = Utils.CompareIPEndPoints(first.Local, second.Local);
if (i != 0)
return i;
if (first.Protocol == Protocol.TCP &&
second.Protocol == Protocol.TCP)
{
i = Utils.CompareIPEndPoints(first.Remote, second.Remote);
if (i != 0)
return i;
}
i = first.PID - second.PID;
if (i != 0)
return i;
if (first.Protocol == second.Protocol)
return 0;
if (first.Protocol == Protocol.TCP)
return -1;
else
return 1;
}
#region IComparer<TCPUDPConnection> Members
public int Compare(TCPUDPConnection x, TCPUDPConnection y)
{
return this.CompareConnections(x, y);
}
#endregion
}
}