]> PatchyGit - patchyircd.git/commitdiff
main: ensure hostname is FQDN
authorEgor <egor@patchysicp.xyz>
Thu, 22 Jan 2026 15:02:40 +0000 (17:02 +0200)
committerEgor <egor@patchysicp.xyz>
Thu, 22 Jan 2026 15:02:40 +0000 (17:02 +0200)
src/main.cpp

index 91532fa..06ab55c 100644 (file)
@@ -169,14 +169,24 @@ static void accept_from_sock(struct listener *listener)
 
 static void determine_hostname(void)
 {
-       static char buf[256];
+       static char buf[257];
        if (!hostname) {
                if (gethostname(buf, 255) == -1) {
                        perror("gethostname");
-                       hostname = "localhost";
+                       hostname = "localhost.";
                } else {
+                       // ensure the hostname is FQDN
+                       if (!strchr(buf, '.')) {
+                               size_t len = strlen(buf);
+                               buf[len] = '.';
+                               buf[len+1] = '\0';
+                       }
                        hostname = buf;
                }
+       } else {
+               if (!strchr(hostname, '.')) {
+                       abortf("Hostname must be FQDN.\n(If necessary, put a period at the end, like so: --hostname '%s.')\n", hostname);
+               }
        }
 }