10 private enum EndPointType
18 internal string hostname;
24 internal bool wildcard;
30 private static char[] DotSeparator =
new char[1]
35 private const string encSeperator =
"#";
57 return CheckEndPointName(hostname) == EndPointType.DnsOrWildcard;
61 private bool IsValidWildcard
65 int length = hostname.Length;
70 if (hostname[0] ==
'.' || hostname[length - 1] ==
'.')
76 for (
int i = 0; i < hostname.Length; i++)
78 if (hostname[i] ==
'.')
82 else if (hostname[i] ==
'*')
86 else if (!
char.IsDigit(hostname[i]))
99 internal EndpointPermission(
string epname,
int port,
TransportType trtype)
101 if (CheckEndPointName(epname) == EndPointType.Invalid)
103 throw new ArgumentException(SR.GetString(
"net_perm_epname", epname),
"epname");
105 if (!ValidationHelper.ValidateTcpPort(port) && port != -1)
122 if (
string.Compare(hostname, endpointPermission.hostname,
StringComparison.OrdinalIgnoreCase) != 0)
126 if (port != endpointPermission.port)
130 if (transport != endpointPermission.transport)
158 if (IsDns && e.IsDns)
160 return string.Compare(hostname, e.hostname,
StringComparison.OrdinalIgnoreCase) == 0;
164 if ((address ==
null && !wildcard) || (e.address ==
null && !e.wildcard))
168 if (wildcard && !e.wildcard)
176 if (MatchWildcard(e.hostname))
183 for (
int i = 0; i < address.Length; i++)
185 if (e.MatchWildcard(address[i].ToString()))
194 for (
int j = 0; j < address.Length; j++)
196 for (
int k = 0; k < e.address.Length; k++)
198 if (address[j].
Equals(e.address[k]))
208 internal bool MatchWildcard(
string str)
210 string[] array = hostname.Split(DotSeparator);
211 string[] array2 = str.Split(DotSeparator);
212 if (array2.Length != 4 || array.Length != 4)
216 for (
int i = 0; i < 4; i++)
218 if (array2[i] != array[i] && array[i] !=
"*")
226 internal void Resolve()
228 if (!cached && !wildcard)
236 else if (IPAddress.TryParse(hostname, out iPAddress))
238 address =
new IPAddress[1];
239 address[0] = iPAddress;
246 if (
Dns.TryInternalResolve(hostname, out IPHostEntry result))
248 address = result.AddressList;
262 internal bool SubsetMatch(EndpointPermission e)
264 if ((transport == e.transport || e.transport ==
TransportType.All) && (port == e.port || e.port == -1 || port == 0))
266 return MatchAddress(e);
275 object[] obj =
new object[5]
283 int num = (int)transport;
285 return string.Concat(obj);
292 if (transport ==
E.transport)
298 trtype =
E.transport;
327 if (!
E.Hostname.Equals(
"*.*.*.*") && !
E.Hostname.Equals(
"0.0.0.0"))
333 else if (
E.Hostname.Equals(
"0.0.0.0"))
341 else if (IsDns &&
E.IsDns)
343 if (
string.Compare(hostname,
E.hostname,
StringComparison.OrdinalIgnoreCase) != 0)
353 if ((address ==
null && !wildcard) || (
E.address ==
null && !
E.wildcard))
357 if (wildcard &&
E.wildcard)
359 string[] array = hostname.Split(DotSeparator);
360 string[] array2 =
E.hostname.Split(DotSeparator);
362 if (array2.Length != 4 || array.Length != 4)
366 for (
int i = 0; i < 4; i++)
372 if (array2[i] == array[i])
377 if (array2[i] ==
"*")
393 for (
int j = 0; j <
E.address.Length; j++)
395 if (MatchWildcard(
E.address[j].ToString()))
404 for (
int k = 0; k < address.Length; k++)
406 if (
E.MatchWildcard(address[k].ToString()))
415 if (address ==
E.address)
420 while (text ==
null && num2 < address.Length)
422 for (
int l = 0; l <
E.address.Length; l++)
424 if (address[num2].
Equals(
E.address[l]))
438 return new EndpointPermission(text, num, trtype);
441 private static EndPointType CheckEndPointName(
string name)
445 return EndPointType.Invalid;
450 foreach (
char c
in name)
466 if ((c >
'f' && c <=
'z') || (c >
'F' && c <=
'Z'))
470 else if ((c >=
'a' && c <=
'f') || (c >=
'A' && c <=
'F'))
474 else if (c < '0' || c >
'9')
476 return EndPointType.Invalid;
485 return EndPointType.IPv4;
487 return EndPointType.DnsOrWildcard;
489 return EndPointType.DnsOrWildcard;
493 return EndPointType.IPv6;
495 return EndPointType.Invalid;
The host name is a domain name system (DNS) style host name.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
TransportType Transport
Gets the transport type that is associated with this endpoint.
Defines an endpoint that is authorized by a T:System.Net.SocketPermission instance.
int Port
Gets the network port number that is associated with this endpoint.
override bool Equals(object obj)
Determines whether the specified Object is equal to the current Object.
Provides an Internet Protocol (IP) address.
The host name is an Internet Protocol (IP) version 4 host address.
The host name is an Internet Protocol (IP) version 6 host address.
string Hostname
Gets the DNS host name or IP address of the server that is associated with this endpoint.
TransportType
Defines transport types for the T:System.Net.SocketPermission and T:System.Net.Sockets....
override int GetHashCode()
Serves as a hash function for a particular type.
override string ToString()
Returns a string that represents the current T:System.Net.EndpointPermission instance.
Specifies that the class can be serialized.
The exception that is thrown when a security error is detected.