Skip to content

DRAFT: Factor gen_host46_byname() out. #1519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

infrastation
Copy link
Member

This is the more difficult part of a prototype I started, but could not quickly complete earlier. The intent is simple: since gateway X nominally includes not host X, and since both gen_gateway() and gen_scode() call pcap_addrinfo() and process the result(s) in a very similar manner, having a slightly different code block in each function makes the code harder to maintain. However, the complexity turned out to be in the detail (including #1512), so this work-in-progress revision fails many tests. Also before this can be progressed any further, the reject filter tests must cover all code paths that go through pcap_addrinfo() and fail to resolve the hostname.

The function needs to translate a [well-formed] IPv6 address string to a
struct in6_addr.  Although pcap_nametoaddrinfo() in fact does that, it
overshoots the problem space unnecessarily and requires managing of the
associated freeaddrinfo() call.  Also the "resolved to multiple address"
condition is never true because in this case the string is an address,
not a hostname, and cannot translate to more than one binary address.

Switch to inet_pton(), which fits the problem space much better, and
verify that it has not failed (very unlikely, but still).
In gen_scode() case Q_GATEWAY delegate the remaining memory management
and error handling away; now if gen_gateway() returns, it always returns
a non-NULL value.  In gen_gateway() handle all errors as early as
possible; instead of testing whether ai_addr is NULL test whether
ai_family is set to the AF of interest, when that's the case, ai_addr is
not NULL (this is how gen_scode() implements case Q_HOST).
@infrastation infrastation marked this pull request as draft May 22, 2025 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

1 participant