Initializer

init(destinationHost:protocol:)

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

Declaration

Current

init(destinationHost hostEndpoint: NWHostEndpoint, protocol: NENetworkRule.`Protocol`)

Previous

init(destinationHost hostEndpoint: NWHostEndpoint, protocol: NENetworkRule.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(destinationHost: NWHostEndpoint(hostname: "com", port: "0"), protocol: .any)

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

NENetworkRule(destinationHost: NWHostEndpoint(hostname: "example.com", port: "0"), protocol: .any)

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

NENetworkRule(destinationHost: NWHostEndpoint(hostname: "example.com", port: "53"), protocol: .any)

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

NENetworkRule(destinationHost: NWHostEndpoint(hostname: "example.com", port: "443"), protocol: .TCP)

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

See Also

Creating a Network Rule

init(destinationNetwork: NWHostEndpoint, prefix: Int, protocol: NENetworkRule.`Protocol`)

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