From 59ea885da07c0916fb5917efb5538df2ecec1553 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Fri, 23 Apr 2021 20:16:50 +0900 Subject: Treat 127.0.0.1, [::1], and hostname as localhost --- main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index fa41cce..6f15e36 100644 --- a/main.c +++ b/main.c @@ -455,6 +455,18 @@ main(int argc, char **argv, char **envp) BookmarkFile = NULL; config_file = NULL; + { + char hostname[HOST_NAME_MAX + 2]; + if (gethostname(hostname, HOST_NAME_MAX + 2) == 0) { + size_t hostname_len; + /* Don't use hostname if it is truncated. */ + hostname[HOST_NAME_MAX + 1] = '\0'; + hostname_len = strlen(hostname); + if (hostname_len <= HOST_NAME_MAX && hostname_len <= INT_MAX) + HostName = allocStr(hostname, (int)hostname_len); + } + } + /* argument search 1 */ for (i = 1; i < argc; i++) { if (*argv[i] == '-') { -- cgit v1.2.3