{"thread":{"id":"2173","subject":"[PATCH] Use sensible domain name (the DNS one) when guessing ident information","startedAt":"2005-10-21T01:57:39Z","lastAt":"2005-10-21T01:57:39Z","messageCount":1,"participants":["Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"10397","messageId":"20051021015739.16471.21112.stgit@machine.or.cz","threadId":"2173","inReplyTo":null,"subject":"[PATCH] Use sensible domain name (the DNS one) when guessing ident information","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-10-21T01:57:39Z","receivedAt":"2005-10-21T01:57:39Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Currently, the code would use getdomainname() call, which however returns\nsomething usually unset and not necessarily related at all to the DNS\ndomain name (it seems to be mostly some scary NIS/YP thing).\n\nThis patch changes the code to actually use the DNS domain name, which is\nalso what tends to be used in emails, and we aim at emails with our ident\ncode.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n ident.c |   10 +++++++++-\n 1 files changed, 9 insertions(+), 1 deletions(-)\n\ndiff --git a/ident.c b/ident.c\nindex 06d0e6c..bc89e1d 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -8,6 +8,7 @@\n #include \"cache.h\"\n \n #include <pwd.h>\n+#include <netdb.h>\n \n static char git_default_date[50];\n \n@@ -64,9 +65,16 @@ int setup_ident(void)\n \tgit_default_email[len++] = '@';\n \tgethostname(git_default_email + len, sizeof(git_default_email) - len);\n \tif (!strchr(git_default_email+len, '.')) {\n+\t\tstruct hostent *he = gethostbyname(git_default_email + len);\n+\t\tchar *domainname;\n+\n \t\tlen = strlen(git_default_email);\n \t\tgit_default_email[len++] = '.';\n-\t\tgetdomainname(git_default_email+len, sizeof(git_default_email)-len);\n+\t\tif (he && (domainname = strchr(he->h_name, '.')))\n+\t\t\tstrncpy(git_default_email + len, domainname + 1, sizeof(git_default_email) - len);\n+\t\telse\n+\t\t\tstrncpy(git_default_email + len, \"(none)\", sizeof(git_default_email) - len);\n+\t\tgit_default_email[sizeof(git_default_email) - 1] = 0;\n \t}\n \t/* And set the default date */\n \tdatestamp(git_default_date, sizeof(git_default_date));\n"}]}