Fix mailsmtp_init_with_ip for IPv6 on Linux #433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
Firstly, thanks for the great work on this library! I've been using it in my TUI email client nmail for 4 years and it's been very solid to work with.
Now to my problem: It appears that
mailsmtp_init_with_ip(smtp, 1)
(i.e. using ip address instead of hostname) fails on Linux when socket address is of IPv6 type.There are two reasons for this:
getnameinfo()
is called withsizeof(addr)
(which is 16) so this call fails withEAI_FAMILY
(-6) for IPv6 addresses. We can fix this by usingaddr_len
which is populated with the actual address length bygetsockname()
.The host address populated by
getnameinfo()
may be suffixed by%
and a network interface specifier, and at least Gmail does not accept this format, and returns an error like:This can be fixed by simply dropping the interface specifier from the IPv6 address.
I've tested the patch on IPv6 and IPv4 on Linux.