{"thread":{"id":"19228","subject":"[PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo","startedAt":"2009-05-07T12:22:32Z","lastAt":"2009-05-07T14:30:43Z","messageCount":8,"participants":["Benjamin Kramer","Andreas Ericsson","Johannes Sixt","Jakub Narebski","Brian Gernhardt","Miles Bader"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"113210","messageId":"4A02D288.6040804@googlemail.com","threadId":"19228","inReplyTo":null,"subject":"[PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo","fromName":"Benjamin Kramer","fromEmail":"benny.kra@googlemail.com","sentAt":"2009-05-07T12:22:32Z","receivedAt":"2009-05-07T12:22:32Z","isPatch":true,"sender":{"key":"benny.kra@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/16542?v=4"},"body":"git daemon's interpolated paths didn't support IPv6.\nEvery IPv6 address was being converted to `0.0.0.0'.\n\nFix this by replacing inet_ntop(3) with the protocol\nagnostic getnameinfo(3) API.\n\nSigned-off-by: Benjamin Kramer <benny.kra@googlemail.com>\n---\n\nWith this patch we'll have colons in the per-IP directories\nfor IPv6 addresses. Creating files with a : in the name fails\non some OSes (e.g. Windows).\n\nIs this OK for git or do we need to special case IPv6 addresses?\n\n daemon.c |    8 +++-----\n 1 files changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/daemon.c b/daemon.c\nindex daa4c8e..339d7ab 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -446,17 +446,15 @@ static void parse_extra_args(char *extra_args, int buflen)\n \t\tstruct addrinfo hints;\n \t\tstruct addrinfo *ai;\n \t\tint gai;\n-\t\tstatic char addrbuf[HOST_NAME_MAX + 1];\n+\t\tstatic char addrbuf[NI_MAXHOST];\n \n \t\tmemset(&hints, 0, sizeof(hints));\n \t\thints.ai_flags = AI_CANONNAME;\n \n \t\tgai = getaddrinfo(hostname, 0, &hints, &ai);\n \t\tif (!gai) {\n-\t\t\tstruct sockaddr_in *sin_addr = (void *)ai->ai_addr;\n-\n-\t\t\tinet_ntop(AF_INET, &sin_addr->sin_addr,\n-\t\t\t\t  addrbuf, sizeof(addrbuf));\n+\t\t\tgetnameinfo(ai->ai_addr, ai->ai_addrlen, addrbuf,\n+\t\t\t\t    sizeof(addrbuf), NULL, 0, NI_NUMERICHOST);\n \t\t\tfree(ip_address);\n \t\t\tip_address = xstrdup(addrbuf);\n \n-- \n1.6.3.1.g882bf\n"},{"id":"113213","messageId":"4A02D70B.6090305@op5.se","threadId":"19228","inReplyTo":"4A02D288.6040804@googlemail.com","subject":"Re: [PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2009-05-07T12:41:47Z","receivedAt":"2009-05-07T12:41:47Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Benjamin Kramer wrote:\n> git daemon's interpolated paths didn't support IPv6.\n> Every IPv6 address was being converted to `0.0.0.0'.\n> \n> Fix this by replacing inet_ntop(3) with the protocol\n> agnostic getnameinfo(3) API.\n> \n> Signed-off-by: Benjamin Kramer <benny.kra@googlemail.com>\n> ---\n> \n> With this patch we'll have colons in the per-IP directories\n> for IPv6 addresses. Creating files with a : in the name fails\n> on some OSes (e.g. Windows).\n> \n\nWhat per-IP directories are you talking about?\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n\nRegister now for Nordic Meet on Nagios, June 3-4 in Stockholm\n http://nordicmeetonnagios.op5.org/\n\nConsidering the successes of the wars on alcohol, poverty, drugs and\nterror, I think we should give some serious thought to declaring war\non peace.\n"},{"id":"113214","messageId":"EC96A79E-4D4E-467A-A10F-D905FE02E508@gmail.com","threadId":"19228","inReplyTo":"4A02D70B.6090305@op5.se","subject":"Re: [PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo","fromName":"Benjamin Kramer","fromEmail":"benny.kra@googlemail.com","sentAt":"2009-05-07T12:54:43Z","receivedAt":"2009-05-07T12:54:43Z","isPatch":true,"sender":{"key":"benny.kra@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/16542?v=4"},"body":"\nAndreas Ericsson wrote:\n\n> What per-IP directories are you talking about?\n\ngit daemon has a feature called interpolated paths\n\nIf git daemon is started like this:\n     git daemon --interpolated-path=%IP/%D\n(the machine has two IPs: 123.123.123.123 (v4) and 2001:db8::1 (v6))\nand someone clones a repository:\n     git clone git://123.123.123.123/frotz\ngit daemon will look for the repository in the directory  \n`123.123.123.123/frotz'\n\nBut if git daemon listens on the IPv6 interface and someone clones a  \nrepository:\n     git clone git://2001:db8::1/frotz\nThen git daemon will look for the repository in `0.0.0.0/frotz'\n\nMy patch makes it converting IPv6 addresses properly and if you the  \nclone\nin my previous example it'll now look in `2001:db8::1/frotz' (with  \ncolons in the\ndirectory name)\n\nI hope my intentions are now a bit clearer ;)\n"},{"id":"113215","messageId":"4A02DEE3.1080006@viscovery.net","threadId":"19228","inReplyTo":"EC96A79E-4D4E-467A-A10F-D905FE02E508@gmail.com","subject":"Re: [PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-05-07T13:15:15Z","receivedAt":"2009-05-07T13:15:15Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Benjamin Kramer schrieb:\n> git daemon has a feature called interpolated paths\n> \n> If git daemon is started like this:\n>     git daemon --interpolated-path=%IP/%D\n> (the machine has two IPs: 123.123.123.123 (v4) and 2001:db8::1 (v6))\n> and someone clones a repository:\n>     git clone git://123.123.123.123/frotz\n> git daemon will look for the repository in the directory\n> `123.123.123.123/frotz'\n> \n> But if git daemon listens on the IPv6 interface and someone clones a\n> repository:\n>     git clone git://2001:db8::1/frotz\n> Then git daemon will look for the repository in `0.0.0.0/frotz'\n> \n> My patch makes it converting IPv6 addresses properly and if you the clone\n> in my previous example it'll now look in `2001:db8::1/frotz' (with\n> colons in the\n> directory name)\n\nI don't particularly care about git-daemon on Windows at this time because\nwe don't build it anyway. But others have already had limited success, and\nthey might care since getnameinfo() is not available. If we did have IPv6\nsupport on Windows, we would indeed have troubles with those path names.\n\nBut even on non-Windows, a directory name with colons does not look kosher\nto me. Don't they look like PATH values? Or like remote addresses? Are\nIPv6 addresses used in this way by other software?\n\nMoreover, I think that since IPv6 addresses can have at most one '::'\nabbreviation, but not in an unambiguous way, users of path-interpolation\nof IPv6 addresses are at the mercy of whether and how getnameinfo() makes\nuse of '::'.\n\n-- Hannes\n"},{"id":"113217","messageId":"m3tz3xm3zt.fsf@localhost.localdomain","threadId":"19228","inReplyTo":"EC96A79E-4D4E-467A-A10F-D905FE02E508@gmail.com","subject":"Re: [PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-05-07T13:34:10Z","receivedAt":"2009-05-07T13:34:10Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Benjamin Kramer <benny.kra@googlemail.com> writes:\n\n> Andreas Ericsson wrote:\n> \n> > What per-IP directories are you talking about?\n> \n> git daemon has a feature called interpolated paths\n> \n> If git daemon is started like this:\n>      git daemon --interpolated-path=%IP/%D\n> (the machine has two IPs: 123.123.123.123 (v4) and 2001:db8::1 (v6))\n> and someone clones a repository:\n>      git clone git://123.123.123.123/frotz\n> git daemon will look for the repository in the directory\n> `123.123.123.123/frotz'\n> \n> But if git daemon listens on the IPv6 interface and someone clones a\n> repository:\n>      git clone git://2001:db8::1/frotz\n> Then git daemon will look for the repository in `0.0.0.0/frotz'\n> \n> My patch makes it converting IPv6 addresses properly and if you the\n> clone in my previous example it'll now look in `2001:db8::1/frotz'\n> (with colons in the directory name)\n\nBTW. this is not only MS Windows that have problems with ':' in paths\n(because of it being drive letter separator), but also IIRC MacOS X,\nwhere ':' and not '/' is directory separator.\n\nThe fact that ':' is separator of paths in $PATH environmental variable\nis a bit complication, but you can always escape ':' in $PATH.\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"113219","messageId":"89EC8961-0122-4616-A497-9204F52B8807@silverinsanity.com","threadId":"19228","inReplyTo":"m3tz3xm3zt.fsf@localhost.localdomain","subject":"Re: [PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2009-05-07T13:45:48Z","receivedAt":"2009-05-07T13:45:48Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn May 7, 2009, at 9:34 AM, Jakub Narebski wrote:\n\n> BTW. this is not only MS Windows that have problems with ':' in paths\n> (because of it being drive letter separator), but also IIRC MacOS X,\n> where ':' and not '/' is directory separator.\n\nJust FYI:\n\n: was the directory separator in Mac OS 1-9.  OS X uses / like most  \nsane people.  Finder will stop you from creating files or directories  \nwith : in the name, but the following works just fine from Terminal.app:\n\n$ uname -a\nDarwin Laptop.local 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24  \n17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE_I386 i386\n$ touch test:test\n$ ls test*\ntest:test\n$ rm test:test\n$\n\n~~ Brian\n"},{"id":"113220","messageId":"87tz3x9g2o.fsf@catnip.gol.com","threadId":"19228","inReplyTo":"m3tz3xm3zt.fsf@localhost.localdomain","subject":"Re: [PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo","fromName":"Miles Bader","fromEmail":"miles@gnu.org","sentAt":"2009-05-07T13:51:27Z","receivedAt":"2009-05-07T13:51:27Z","isPatch":true,"sender":{"key":"miles@gnu.org","avatar":"https://gravatar.com/avatar/01069b69593af7bff28e2f97afeb3644ae6fe2f5f56cb3a8cf34c5fb8c36efe5?d=mp&s=160"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n> BTW. this is not only MS Windows that have problems with ':' in paths\n> (because of it being drive letter separator), but also IIRC MacOS X,\n> where ':' and not '/' is directory separator.\n>\n> The fact that ':' is separator of paths in $PATH environmental variable\n> is a bit complication, but you can always escape ':' in $PATH.\n\nNo, that was in \"classic mac os\"; osx uses \"/\".\n\n-Miles\n\n-- \nPolitics, n. A strife of interests masquerading as a contest of\nprinciples. The conduct of public affairs for private advantage.\n"},{"id":"113222","messageId":"4A02F093.50003@googlemail.com","threadId":"19228","inReplyTo":"4A02DEE3.1080006@viscovery.net","subject":"Re: [PATCH/RFC] daemon.c: replace inet_ntop with getnameinfo","fromName":"Benjamin Kramer","fromEmail":"benny.kra@googlemail.com","sentAt":"2009-05-07T14:30:43Z","receivedAt":"2009-05-07T14:30:43Z","isPatch":true,"sender":{"key":"benny.kra@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/16542?v=4"},"body":"Johannes Sixt schrieb:\n> \n> I don't particularly care about git-daemon on Windows at this time because\n> we don't build it anyway. But others have already had limited success, and\n> they might care since getnameinfo() is not available. If we did have IPv6\n> support on Windows, we would indeed have troubles with those path names.\n\nThe getnameinfo(3) code is in a #ifndef NO_IPV6 block anyways, so it won't\nhurt non-ipv6 builds. afaik getnameinfo(3) is available when getaddrinfo(3)\nis and that seems to be the case on newer windows versions.\n\n> But even on non-Windows, a directory name with colons does not look kosher\n> to me. Don't they look like PATH values? Or like remote addresses? Are\n> IPv6 addresses used in this way by other software?\n> \n> Moreover, I think that since IPv6 addresses can have at most one '::'\n> abbreviation, but not in an unambiguous way, users of path-interpolation\n> of IPv6 addresses are at the mercy of whether and how getnameinfo() makes\n> use of '::'.\n\nI did a quick test with apache's VirtualDocumentRootIP and it looks like\nthey are using :: only when it's unambigous. And yes, they use colons\nin the file name.\n\n::1 stays ::1\n\n2001:db8::abab:abab:0:abab:abab becomes 2001:db8:0:abab:abab:0:abab:abab\n\nI don't know if they also use colons on windows because I don't have a\nwindows box with IPv6 to test.\n\n\n-->8-->8--\n\nhttpd.conf:\nVirtualDocumentRootIP /foo/bar/%0\n\nnow point your browser to http://[::1]/ and watch your logs.\n"}]}