inet_net_pton() alternative for IPv6

Florian Weimer fweimer@redhat.com
Mon Jul 4 19:57:11 GMT 2022


* Ian Pilcher:

> On 7/4/22 13:34, Florian Weimer wrote:
>> There's inet_pton, or getaddrinfo AI_NUMERICHOST if you want to produce
>> a full socket address (with a port number as well).
>
> I just need to parse an IP address and prefix length or network address,
> in CIDR format.  Unfortunately, inet_pton() won't parse the address
> portion of a CIDR address, so it looks like I'm going to have to make a
> zero-terminated copy of that part of the address, just so I can pass it
> to inet_pton().

I guess that's just living with C strings. 8-/

We have the same issue with separating IPv6 addresses from their scope
IDs, and have an internal __inet_pton_length function, which is used to
avoid that copy.  But pretty much anything that operates on C strings
could also work with an explicit length, so there's really no good
reason to start exporting __inet_pton_length, I'm afraid.

Thanks,
Florian



More information about the Libc-help mailing list