Instance Method

initWithDestinationHost:protocol:

Creates a rule that matches network traffic destined for a host within a specific DNS domain.

Declaration

- (instancetype)initWithDestinationHost:(NWHostEndpoint *)hostEndpoint protocol:(NENetworkRuleProtocol)protocol;

Parameters

destinationHost

An endpoint instance that contains the port and hostname or domain that the rule matches. This endpoint must contain a hostname, not an address.

protocol

The protocol that the rule matches.

Discussion

If the port string of destinationHost is 0 or is the empty string, then the rule matches traffic on any port destined for the given hostname or domain.

If the hostname string of destinationHost consists of a single label, then the rule matches traffic destined to the specific host with that single label as its name.

If the hostname string of destinationHost consists of two or more labels, then the rule matches traffic destined to hosts within the domain specified by the hostname string.

Examples:

Table 1

Examples of initializing network rules in a specific domain

Initializer

Result

[[NENetworkRule alloc] initWithDestinationHost:[NWHostEndpoint endpointWithHostname:@"com" port:@"0"] protocol:NENetworkRuleProtocolAny]

A rule that matches all TCP and UDP traffic to the host named com.

[[NENetworkRule alloc] initWithDestinationHost:[NWHostEndpoint endpointWithHostname:@"example.com" port:@"0"] protocol:NENetworkRuleProtocolAny]

A rule that matches all TCP and UDP domain, including all DNS queries for names in the example.com DNS domain.

[[NENetworkRule alloc] initWithDestinationHost:[NWHostEndpoint endpointWithHostname:@"example.com" port:@"53"] protocol:NENetworkRuleProtocolAny]

A rule that matches all DNS queries/responses for hosts in the example.com domain.

[[NENetworkRule alloc] initWithDestinationHost:[NWHostEndpoint endpointWithHostname:@"example.com" port:@"443"] protocol:NENetworkRuleProtocolTCP]

A rule that matches all TCP port 443 traffic to hosts in the example.com domain.

See Also

Creating a Network Rule

- initWithDestinationNetwork:prefix:protocol:

Creates a rule that matches network traffic destined for a host within a specific network.

- initWithRemoteNetwork:remotePrefix:localNetwork:localPrefix:protocol:direction:

Creates a rule that matches traffic by remote network, local network, protocol, and direction.