* inet_net_pton() alternative for IPv6 @ 2022-07-04 18:07 Ian Pilcher 2022-07-04 18:23 ` tomas 2022-07-04 18:34 ` Florian Weimer 0 siblings, 2 replies; 7+ messages in thread From: Ian Pilcher @ 2022-07-04 18:07 UTC (permalink / raw) To: libc-help I am searching for the best way to parse both IPv4 and IPv6 CIDR- formatted addresses. I have found inet_net_pton(), but it only supports IPv4 (AF_INET) addresses. Needless to say, this is pretty disappointing in 2022. Is there an alternative API that I should be using, or am I stuck writing my own? Thanks! -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: inet_net_pton() alternative for IPv6 2022-07-04 18:07 inet_net_pton() alternative for IPv6 Ian Pilcher @ 2022-07-04 18:23 ` tomas 2022-07-05 23:58 ` Ian Pilcher 2022-07-04 18:34 ` Florian Weimer 1 sibling, 1 reply; 7+ messages in thread From: tomas @ 2022-07-04 18:23 UTC (permalink / raw) To: Ian Pilcher; +Cc: libc-help [-- Attachment #1: Type: text/plain, Size: 1914 bytes --] On Mon, Jul 04, 2022 at 01:07:59PM -0500, Ian Pilcher via Libc-help wrote: > I am searching for the best way to parse both IPv4 and IPv6 CIDR- > formatted addresses. I have found inet_net_pton(), but it only supports > IPv4 (AF_INET) addresses. I never tried it, but this is what my version [1] of the libc docs say: -- Function: int inet_pton (int AF, const char *CP, void *BUF) Preliminary: | MT-Safe locale | AS-Safe | AC-Safe | *Note POSIX Safety Concepts::. This function converts an Internet address (either IPv4 or IPv6) from presentation (textual) to network (binary) format. AF should be either ‘AF_INET’ or ‘AF_INET6’, as appropriate for the type of address being converted. CP is a pointer to the input string, and BUF is a pointer to a buffer for the result. It is the caller’s responsibility to make sure the buffer is large enough. -- Function: const char * inet_ntop (int AF, const void *CP, char *BUF, socklen_t LEN) Preliminary: | MT-Safe locale | AS-Safe | AC-Safe | *Note POSIX Safety Concepts::. This function converts an Internet address (either IPv4 or IPv6) from network (binary) to presentation (textual) form. AF should be either ‘AF_INET’ or ‘AF_INET6’, as appropriate. CP is a pointer to the address to be converted. BUF should be a pointer to a buffer to hold the result, and LEN is the length of this buffer. The return value from the function will be this buffer address. so they seem to cover your needs? > Needless to say, this is pretty disappointing in 2022. Is there an > alternative API that I should be using, or am I stuck writing my own? C'm on. Be nice :) Cheers [1] This is ‘The GNU C Library Reference Manual’, for Version (Debian glibc-doc-reference 2.31-1) of the GNU C Library. -- t [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: inet_net_pton() alternative for IPv6 2022-07-04 18:23 ` tomas @ 2022-07-05 23:58 ` Ian Pilcher 2022-07-06 5:04 ` tomas 0 siblings, 1 reply; 7+ messages in thread From: Ian Pilcher @ 2022-07-05 23:58 UTC (permalink / raw) To: tomas; +Cc: libc-help On 7/4/22 13:23, tomas@tuxteam.de wrote: > I never tried it, but this is what my version [1] of the libc docs say: > > -- Function: int inet_pton (int AF, const char *CP, void *BUF) > > Preliminary: | MT-Safe locale | AS-Safe | AC-Safe | *Note POSIX > Safety Concepts::. > > This function converts an Internet address (either IPv4 or IPv6) > from presentation (textual) to network (binary) format. AF should > be either ‘AF_INET’ or ‘AF_INET6’, as appropriate for the type of > address being converted. CP is a pointer to the input string, and > BUF is a pointer to a buffer for the result. It is the caller’s > responsibility to make sure the buffer is large enough. You're looking at the wrong function. inet_pton() does support IPv6; inet_net_pton() does not (even though its interface is designed in a way that it could accomodate it). -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: inet_net_pton() alternative for IPv6 2022-07-05 23:58 ` Ian Pilcher @ 2022-07-06 5:04 ` tomas 0 siblings, 0 replies; 7+ messages in thread From: tomas @ 2022-07-06 5:04 UTC (permalink / raw) To: Ian Pilcher; +Cc: libc-help [-- Attachment #1: Type: text/plain, Size: 1354 bytes --] On Tue, Jul 05, 2022 at 06:58:00PM -0500, Ian Pilcher wrote: > On 7/4/22 13:23, tomas@tuxteam.de wrote: > > I never tried it, but this is what my version [1] of the libc docs say: > > > > -- Function: int inet_pton (int AF, const char *CP, void *BUF) > > > > Preliminary: | MT-Safe locale | AS-Safe | AC-Safe | *Note POSIX > > Safety Concepts::. > > > > This function converts an Internet address (either IPv4 or IPv6) > > from presentation (textual) to network (binary) format. AF should > > be either ‘AF_INET’ or ‘AF_INET6’, as appropriate for the type of > > address being converted. CP is a pointer to the input string, and > > BUF is a pointer to a buffer for the result. It is the caller’s > > responsibility to make sure the buffer is large enough. > > > You're looking at the wrong function. inet_pton() does support IPv6; > inet_net_pton() does not (even though its interface is designed in a > way that it could accomodate it). I see, thanks > -- > ======================================================================== > Google Where SkyNet meets Idiocracy > ======================================================================== The irony is that you are posting from... gmail :) Cheers -- t [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: inet_net_pton() alternative for IPv6 2022-07-04 18:07 inet_net_pton() alternative for IPv6 Ian Pilcher 2022-07-04 18:23 ` tomas @ 2022-07-04 18:34 ` Florian Weimer 2022-07-04 19:34 ` Ian Pilcher 1 sibling, 1 reply; 7+ messages in thread From: Florian Weimer @ 2022-07-04 18:34 UTC (permalink / raw) To: Ian Pilcher via Libc-help; +Cc: Ian Pilcher * Ian Pilcher via Libc-help: > I am searching for the best way to parse both IPv4 and IPv6 CIDR- > formatted addresses. I have found inet_net_pton(), but it only > supports IPv4 (AF_INET) addresses. There's inet_pton, or getaddrinfo AI_NUMERICHOST if you want to produce a full socket address (with a port number as well). Thanks, Florian ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: inet_net_pton() alternative for IPv6 2022-07-04 18:34 ` Florian Weimer @ 2022-07-04 19:34 ` Ian Pilcher 2022-07-04 19:57 ` Florian Weimer 0 siblings, 1 reply; 7+ messages in thread From: Ian Pilcher @ 2022-07-04 19:34 UTC (permalink / raw) To: Florian Weimer, Ian Pilcher via Libc-help 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(). -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: inet_net_pton() alternative for IPv6 2022-07-04 19:34 ` Ian Pilcher @ 2022-07-04 19:57 ` Florian Weimer 0 siblings, 0 replies; 7+ messages in thread From: Florian Weimer @ 2022-07-04 19:57 UTC (permalink / raw) To: Ian Pilcher; +Cc: Ian Pilcher via Libc-help * 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-07-06 5:04 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-07-04 18:07 inet_net_pton() alternative for IPv6 Ian Pilcher 2022-07-04 18:23 ` tomas 2022-07-05 23:58 ` Ian Pilcher 2022-07-06 5:04 ` tomas 2022-07-04 18:34 ` Florian Weimer 2022-07-04 19:34 ` Ian Pilcher 2022-07-04 19:57 ` Florian Weimer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).