Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Ip.cs
1using System;
2using System.Net;
3using System.Net.Sockets;
4using System.Threading.Tasks;
5
7{
11 public abstract class Ip : Mechanism
12 {
16 protected IPAddress address;
17
21 protected int cidr;
22
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}
Abstract base class for IP-based SPF mechanisms.
Definition: Ip.cs:12
override Task< SpfResult > Matches()
Checks if the mechamism matches the current request.
Definition: Ip.cs:77
Ip(Term Term, SpfQualifier Qualifier)
Abstract base class for IP-based SPF mechanisms.
Definition: Ip.cs:28
IPAddress address
IP Address
Definition: Ip.cs:16
Abstract base class for SPF mechanisms with a domain specification and an optional CIDR specification...
Abstract base class for SPF Mechanisms.
Definition: Mechanism.cs:11
readonly Term term
Current request.
Definition: Mechanism.cs:20
SpfQualifier Qualifier
Mechanism qualifier
Definition: Mechanism.cs:36
SpfQualifier
SPF Mechanism qualifier
Definition: Term.cs:12
SpfResult
Result of a SPF (Sender Policy Framework) evaluation.
Definition: SpfResult.cs:11