Skip to content

Add CIDR and domain pattern matching as utilities#44

Open
kpodosin wants to merge 1 commit into
kpodosin/swiftNAT64from
kpodosin/IPAddress+CIDR
Open

Add CIDR and domain pattern matching as utilities#44
kpodosin wants to merge 1 commit into
kpodosin/swiftNAT64from
kpodosin/IPAddress+CIDR

Conversation

@kpodosin

@kpodosin kpodosin commented Jul 6, 2026

Copy link
Copy Markdown

Adds to Utilities/IPAddress+CIDR:

  • IPv4 and IPv6 CIDR subnet matching
  • right-to-left domain pattern matching with wildcard and suffix support
  • NAT64 synthesis detection on IPv6Address

Adds tests for above in SwiftNetworkCIDRTests

@kpodosin kpodosin changed the base branch from main to kpodosin/swiftNAT64 July 6, 2026 17:37
extension Endpoint {
/// Returns true if this endpoint matches `pattern`. `"*"` matches all endpoints. Host endpoints
/// are matched by hostname; address endpoints are matched by IP address or CIDR block.
func matchesProxyPattern(_ pattern: String) -> Bool {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this should be just "matchesPattern", not specific to proxies?

@kpodosin kpodosin force-pushed the kpodosin/IPAddress+CIDR branch from 7d74301 to 31fa22d Compare July 6, 2026 18:04
}

var inAddr = in_addr()
guard inet_pton(AF_INET, addrString, &inAddr) == 1 else { return nil }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove any use of inet_pton, in_addr, etc. We should make this pure swift and standalone, with no platform dependencies.

var in6Addr = in6_addr()
guard inet_pton(AF_INET6, String(parts[0]), &in6Addr) == 1 else { return nil }

let rawNet = withUnsafeBytes(of: in6Addr) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid unsafe


// MARK: - CIDR parsing

#if !NETWORK_STANDALONE

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this check and not rely on inet_ functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants