From: Jeff King <peff@peff.net>
To: Elia Pinto <gitter.spiros@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] ident.c: add support for IPv6
Date: Fri, 30 Oct 2015 14:29:39 -0400 [thread overview]
Message-ID: <20151030182939.GA4729@sigill.intra.peff.net> (raw)
In-Reply-To: <1446216487-11503-1-git-send-email-gitter.spiros@gmail.com>
On Fri, Oct 30, 2015 at 03:48:07PM +0100, Elia Pinto wrote:
> Add IPv6 support by implementing name resolution with the
> protocol agnostic getaddrinfo(3) API. The old gethostbyname(3)
> code is still available when git is compiled with NO_IPV6.
Makes sense. I'm not excited by the duplication in the early part of the
function, though:
> +#ifndef NO_IPV6
> +
> +static void add_domainname(struct strbuf *out)
> +{
> + char buf[1024];
> + struct addrinfo hints, *ai;
> + int gai;
> +
> + if (gethostname(buf, sizeof(buf))) {
> + warning("cannot get host name: %s", strerror(errno));
> + strbuf_addstr(out, "(none)");
> + return;
> + }
> + if (strchr(buf, '.'))
> + strbuf_addstr(out, buf);
> + else {
> + memset (&hints, '\0', sizeof (hints));
> + hints.ai_flags = AI_CANONNAME;
> + if (!(gai = getaddrinfo(buf, NULL, &hints, &ai)) && ai && strchr(ai->ai_canonname, '.')) {
> + strbuf_addstr(out, ai->ai_canonname);
> + freeaddrinfo(ai);
> + }
> + else
> + strbuf_addf(out, "%s.(none)", buf);
> + }
> +}
Especially the "(none)" stuff is ugly enough as it is, without being
duplicated in two spots. Can we factor out the else clause that calls
gethostbyname(), and just override that part with the #ifdef?
For that matter, we have a few other spots that use getaddrinfo and
#ifdef. I wonder if it would be possible to simply use getaddrinfo
everywhere, and make a compatibility wrapper that uses gethostbyname for
older systems. The cut-and-paste duplication in connect.c, for example,
is pretty egregious.
-Peff
prev parent reply other threads:[~2015-10-30 18:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-30 14:48 [PATCH] ident.c: add support for IPv6 Elia Pinto
2015-10-30 17:26 ` Torsten Bögershausen
2015-10-30 18:13 ` Junio C Hamano
2015-10-30 18:19 ` Eric Sunshine
2015-10-30 18:29 ` Jeff King [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151030182939.GA4729@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitter.spiros@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).