git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Kramer <benny.kra@googlemail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, jdl@jdl.com
Subject: [PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo
Date: Thu, 07 May 2009 14:22:32 +0200	[thread overview]
Message-ID: <4A02D288.6040804@googlemail.com> (raw)

git daemon's interpolated paths didn't support IPv6.
Every IPv6 address was being converted to `0.0.0.0'.

Fix this by replacing inet_ntop(3) with the protocol
agnostic getnameinfo(3) API.

Signed-off-by: Benjamin Kramer <benny.kra@googlemail.com>
---

With this patch we'll have colons in the per-IP directories
for IPv6 addresses. Creating files with a : in the name fails
on some OSes (e.g. Windows).

Is this OK for git or do we need to special case IPv6 addresses?

 daemon.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/daemon.c b/daemon.c
index daa4c8e..339d7ab 100644
--- a/daemon.c
+++ b/daemon.c
@@ -446,17 +446,15 @@ static void parse_extra_args(char *extra_args, int buflen)
 		struct addrinfo hints;
 		struct addrinfo *ai;
 		int gai;
-		static char addrbuf[HOST_NAME_MAX + 1];
+		static char addrbuf[NI_MAXHOST];
 
 		memset(&hints, 0, sizeof(hints));
 		hints.ai_flags = AI_CANONNAME;
 
 		gai = getaddrinfo(hostname, 0, &hints, &ai);
 		if (!gai) {
-			struct sockaddr_in *sin_addr = (void *)ai->ai_addr;
-
-			inet_ntop(AF_INET, &sin_addr->sin_addr,
-				  addrbuf, sizeof(addrbuf));
+			getnameinfo(ai->ai_addr, ai->ai_addrlen, addrbuf,
+				    sizeof(addrbuf), NULL, 0, NI_NUMERICHOST);
 			free(ip_address);
 			ip_address = xstrdup(addrbuf);
 
-- 
1.6.3.1.g882bf

             reply	other threads:[~2009-05-07 12:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-07 12:22 Benjamin Kramer [this message]
2009-05-07 12:41 ` [PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo Andreas Ericsson
2009-05-07 12:54   ` Benjamin Kramer
2009-05-07 13:15     ` Johannes Sixt
2009-05-07 14:30       ` Benjamin Kramer
2009-05-07 13:34     ` Jakub Narebski
2009-05-07 13:45       ` Brian Gernhardt
2009-05-07 13:51       ` Miles Bader

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=4A02D288.6040804@googlemail.com \
    --to=benny.kra@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jdl@jdl.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).