Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Ip.cs
1
using
System;
2
using
System.Net;
3
using
System.Net.Sockets;
4
using
System.Threading.Tasks;
5
6
namespace
Waher.Security.SPF.Mechanisms
7
{
11
public
abstract
class
Ip
:
Mechanism
12
{
16
protected
IPAddress
address
;
17
21
protected
int
cidr
;
22
28
public
Ip
(
Term
Term
,
SpfQualifier
Qualifier
)
29
: base(
Term
,
Qualifier
)
30
{
31
if
(
Term
.PeekNextChar() !=
':'
)
32
throw
new
Exception(
": expected."
);
33
34
Term
.NextChar();
35
36
int
Start =
Term
.pos;
37
char
ch;
38
39
while
(
Term
.pos <
Term
.len && (ch =
Term
.s[
Term
.pos]) !=
'/'
&& ch >
' '
)
40
Term
.pos++;
41
42
if
(!IPAddress.TryParse(
Term
.s.Substring(Start,
Term
.pos - Start), out
this
.address))
43
throw
new
Exception(
"IP Address expected."
);
44
45
int
Max;
46
47
switch
(this.address.AddressFamily)
48
{
49
case
AddressFamily.InterNetwork:
50
Max = 32;
51
break
;
52
53
case
AddressFamily.InterNetworkV6:
54
Max = 128;
55
break
;
56
57
default
:
58
throw
new
Exception(
"IP Address expected."
);
59
}
60
61
if
(
Term
.PeekNextChar() ==
'/'
)
62
{
63
Term
.NextChar();
64
65
this.cidr =
Term
.NextInteger();
66
if
(this.cidr < 0 || this.cidr > Max)
67
throw
new
Exception(
"Invalid CIDR"
);
68
}
69
else
70
this.cidr = Max;
71
}
72
77
public
override
Task<SpfResult>
Matches
()
78
{
79
bool
Result =
MechanismDomainCidrSpec
.Matches(
new
IPAddress[] { this.address }, this.
term
, this.
cidr
);
80
return
Task.FromResult<
SpfResult
>(Result ? SpfResult.Pass :
SpfResult
.Fail);
81
}
82
83
}
84
}
Waher.Security.SPF.Mechanisms.Ip
Abstract base class for IP-based SPF mechanisms.
Definition:
Ip.cs:12
Waher.Security.SPF.Mechanisms.Ip.cidr
int cidr
CIDR
Definition:
Ip.cs:21
Waher.Security.SPF.Mechanisms.Ip.Matches
override Task< SpfResult > Matches()
Checks if the mechamism matches the current request.
Definition:
Ip.cs:77
Waher.Security.SPF.Mechanisms.Ip.Ip
Ip(Term Term, SpfQualifier Qualifier)
Abstract base class for IP-based SPF mechanisms.
Definition:
Ip.cs:28
Waher.Security.SPF.Mechanisms.Ip.address
IPAddress address
IP Address
Definition:
Ip.cs:16
Waher.Security.SPF.Mechanisms.MechanismDomainCidrSpec
Abstract base class for SPF mechanisms with a domain specification and an optional CIDR specification...
Definition:
MechanismDomainCidrSpec.cs:13
Waher.Security.SPF.Mechanisms.Mechanism
Abstract base class for SPF Mechanisms.
Definition:
Mechanism.cs:11
Waher.Security.SPF.Mechanisms.Mechanism.term
readonly Term term
Current request.
Definition:
Mechanism.cs:20
Waher.Security.SPF.Mechanisms.Mechanism.Qualifier
SpfQualifier Qualifier
Mechanism qualifier
Definition:
Mechanism.cs:36
Waher.Security.SPF.Term
SPF Term
Definition:
Term.cs:38
Waher.Security.SPF.Mechanisms
Definition:
A.cs:8
Waher.Security.SPF.SpfQualifier
SpfQualifier
SPF Mechanism qualifier
Definition:
Term.cs:12
Waher.Security.SPF.SpfResult
SpfResult
Result of a SPF (Sender Policy Framework) evaluation.
Definition:
SpfResult.cs:11
IoTGateway
Security
Waher.Security.SPF
Mechanisms
Ip.cs
Generated by
1.9.5