-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworkAddress.cs
60 lines (53 loc) · 1.76 KB
/
NetworkAddress.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
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Dusty.Net
{
public class NetworkAddress : SubnetIpAddress
{
//Constructors from base class
public NetworkAddress(long newAddress) : base(newAddress) { init(); }
public NetworkAddress(byte[] address) : base(address) { init(); }
public NetworkAddress(byte[] address, long scopeid) : base(address, scopeid) { init(); }
public NetworkAddress(IPAddress ipaddress, SubnetMask subnetMask) : base(ipaddress, subnetMask)
{
init();
}
public NetworkAddress(long newAddress, long subnetMask) : base(newAddress, subnetMask)
{
init();
}
public NetworkAddress(byte[] address, byte[] subnetMask) : base(address, subnetMask)
{
init();
}
public NetworkAddress(byte[] address, byte[] subnetMask, long scopeid) : base(address, subnetMask, scopeid)
{
init();
}
private void init()
{
IPAddress zero = this.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 ?
IPAddress.Parse("::0") :
IPAddress.Parse("0.0.0.0");
if (
Utils.CompareHostBits(
this.GetAddressBits(),
zero.GetAddressBits(),
this.subnetMask.NetworkPrefixLength
)
) { }
else
{
throw new ArgumentException("Host bits supplied to NetworkAddress constructor");
}
}
new public NetworkAddress GetNetworkAddress()
{
return this;
}
}
}