<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Mar 15, 2015 at 1:36 PM, Zbigniew Jędrzejewski-Szmek <span dir="ltr"><<a href="mailto:zbyszek@in.waw.pl" target="_blank">zbyszek@in.waw.pl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sun, Mar 15, 2015 at 01:28:05PM -0700, Shawn Landden wrote:<br>
> On Sun, Mar 15, 2015 at 1:07 PM, Zbigniew Jędrzejewski-Szmek <<br>
> <a href="mailto:zbyszek@in.waw.pl">zbyszek@in.waw.pl</a>> wrote:<br>
><br>
> > On Wed, Mar 11, 2015 at 08:13:47AM -0700, Shawn Landden wrote:<br>
> > > if we are going to have a function to fix up the deficiencies of<br>
> > > inet_pton(), better go all the way.<br>
> > > ---<br>
> > > src/shared/in-addr-util.c | 17 +++++++++++++++++<br>
> > > src/shared/in-addr-util.h | 1 +<br>
> > > 2 files changed, 18 insertions(+)<br>
> > ><br>
> > > diff --git a/src/shared/in-addr-util.c b/src/shared/in-addr-util.c<br>
> > > index ade4012..b7532a6 100644<br>
> > > --- a/src/shared/in-addr-util.c<br>
> > > +++ b/src/shared/in-addr-util.c<br>
> > > @@ -206,7 +206,18 @@ int in_addr_to_string(int family, const union<br>
> > in_addr_union *u, char **ret) {<br>
> > > return 0;<br>
> > > }<br>
> > ><br>
> > > +struct in6_addr in_addr_to_in6_addr(struct in_addr ipv4) {<br>
> > > + struct in6_addr r = { { {<br>
> > > + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0<br>
> > > + } } };<br>
> > > +<br>
> > > + r.s6_addr32[3] = ipv4.s_addr;<br>
> > > +<br>
> > > + return r;<br>
> > > +}<br>
> > > +<br>
> > > int in_addr_from_string(int family, const char *s, void *ret) {<br>
> > > + struct in_addr v4mapped;<br>
> > ><br>
> > > assert(s);<br>
> > > assert(ret);<br>
> > > @@ -214,6 +225,12 @@ int in_addr_from_string(int family, const char *s,<br>
> > void *ret) {<br>
> > > if (!IN_SET(family, AF_INET, AF_INET6))<br>
> > > return -EAFNOSUPPORT;<br>
> > ><br>
> > > + if (family == AF_INET6)<br>
> > > + if (inet_pton(AF_INET, s, &v4mapped) == 1) {<br>
> > > + *((struct in6_addr *)ret) =<br>
> > in_addr_to_in6_addr(v4mapped);<br>
> > > + return 0;<br>
> > > + }<br>
> > > +<br>
> > Hm, IIUC, an ipv6 address was specified, but the user gave an ipv4 address.<br>
> > Automatically converting seems like a way to entice confusion...<br>
> ><br>
> > Except that the linux kernel supports binding to ipv4 this way, (see<br>
> ipv6(7)).<br>
><br>
> In the inet_pton man page:<br>
><br>
> BUGS<br>
> AF_INET6 does not recognize IPv4 addresses. An explicit IPv4-mapped<br>
> IPv6 address must be supplied in src instead.<br>
</div></div>Right, but looking at how in_addr_from_string is used, we usually call it<br>
with an explicit family, and if it parses as ipv4, assume the family is ipv4,<br>
otherwise parse it as ipv6. So your change would either be a noop (if<br>
the check for ipv4 syntax was already done before), or would mess up this<br>
detection.<br>
<br>
What scenario are you trying to solve?<br>
<br></blockquote><div>nothing is particular, I was just trying to give myself a reason not to refactor these to just call inet_pton() directly as without this change the wrapper function does nothing except check for NULL. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Zbyszek<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
><br>
> Zbyszek<br>
> ><br>
> > > errno = 0;<br>
> > > if (inet_pton(family, s, ret) <= 0)<br>
> > > return errno ? -errno : -EINVAL;<br>
> > > diff --git a/src/shared/in-addr-util.h b/src/shared/in-addr-util.h<br>
> > > index 8b3a07c..f140ec9 100644<br>
> > > --- a/src/shared/in-addr-util.h<br>
> > > +++ b/src/shared/in-addr-util.h<br>
> > > @@ -37,6 +37,7 @@ int in_addr_equal(int family, const union<br>
> > in_addr_union *a, const union in_addr_<br>
> > > int in_addr_prefix_intersect(int family, const union in_addr_union *a,<br>
> > unsigned aprefixlen, const union in_addr_union *b, unsigned bprefixlen);<br>
> > > int in_addr_prefix_next(int family, union in_addr_union *u, unsigned<br>
> > prefixlen);<br>
> > > int in_addr_to_string(int family, const union in_addr_union *u, char<br>
> > **ret);<br>
> > > +struct in6_addr in_addr_to_in6_addr(struct in_addr ipv4) _const_;<br>
> > > int in_addr_from_string(int family, const char *s, void *ret);<br>
> > > int in_addr_from_string_auto(const char *s, int *family, union<br>
> > in_addr_union *ret);<br>
> > > unsigned char in_addr_netmask_to_prefixlen(const struct in_addr *addr);<br>
> > > --<br>
> > > 2.2.1.209.g41e5f3a<br>
> > ><br>
> > > _______________________________________________<br>
> > > systemd-devel mailing list<br>
> > > <a href="mailto:systemd-devel@lists.freedesktop.org">systemd-devel@lists.freedesktop.org</a><br>
> > > <a href="http://lists.freedesktop.org/mailman/listinfo/systemd-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
> > _______________________________________________<br>
> > systemd-devel mailing list<br>
> > <a href="mailto:systemd-devel@lists.freedesktop.org">systemd-devel@lists.freedesktop.org</a><br>
> > <a href="http://lists.freedesktop.org/mailman/listinfo/systemd-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
> ><br>
><br>
><br>
><br>
> --<br>
> Shawn Landden<br>
_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org">systemd-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/systemd-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Shawn Landden</div>
</div></div>