git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo

From
Benjamin Kramer <benny.kra@googlemail.com>
Date
May 7, 2009, 12:22 UTC
Message-ID
<4A02D288.6040804@googlemail.com>

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
Next: Andreas Ericsson
Message 1 of 8 in “daemon.c: replace inet_ntop with getnameinfo”
  1. daemon.c: replace inet_ntop with getnameinfoBenjamin Kramer, May 7, 2009
  2. Andreas EricssonMay 7, 2009
  3. Benjamin KramerMay 7, 2009
  4. Johannes SixtMay 7, 2009
  5. Benjamin KramerMay 7, 2009
  6. Jakub NarebskiMay 7, 2009
  7. Brian GernhardtMay 7, 2009
  8. Miles BaderMay 7, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.