]> PatchyGit - patchyircd.git/commitdiff
use system hostname by default
authorEgor <egor@patchysicp.xyz>
Thu, 27 Mar 2025 07:35:32 +0000 (09:35 +0200)
committerEgor <egor@patchysicp.xyz>
Thu, 27 Mar 2025 07:35:32 +0000 (09:35 +0200)
README.md
src/config.h
src/irc.cpp
src/main.cpp

index 3149caa..99dccd5 100644 (file)
--- a/README.md
+++ b/README.md
@@ -10,7 +10,8 @@ make
 ```
 
 Some things are configurable via compile-time flags. In particular, `-DHAS_TLS`
-and some constants defined in `src/config.h`.
+and some constants defined in `src/config.h`. See the section on paths for
+additional flags.
 
 ## Config files
 These have to go in datadir (see below).
@@ -65,6 +66,10 @@ IPv4 and IPv6 must be specified separately.
 With `--autojoin \#ircmoment` clients will automatically join the `#ircmoment`
 channel. This option can be specified multiple times.
 
+The server hostname can be set via `--hostname`. The default is the machine's
+actual hostname
+
+## Paths
 Data directory can be configured with `--datadir` argument. The default can be
 configured at compile time via `IRCDDATADIR` define. Otherwise it deafults to
 `LOCALSTATEDIR/lib/patchyircd` if `LOCALSTATEDIR` is defined. Otherwise it's
index 97952c4..6f45e27 100644 (file)
@@ -7,6 +7,3 @@
 #ifndef ADMINEMAIL
 #define ADMINEMAIL "admin@example.com"
 #endif
-#ifndef IRCDHOSTNAME
-#define IRCDHOSTNAME "example.com"
-#endif
index 871845d..c11efc7 100644 (file)
@@ -9,7 +9,7 @@ clientmap client_map = {};
 channelmap channel_map = {};
 stringset autojoin = {};
 
-const char *hostname = IRCDHOSTNAME;
+const char *hostname = 0;
 void sendbuf(struct client_data *client) {
        fprintf(stderr, "SERVER %" PRISocket ": %.*s", client->FD, (int)databuf.len, (char*)databuf.buf);
        sendClient(client, databuf.buf, databuf.len);
index e235383..faa4af5 100644 (file)
@@ -177,6 +177,19 @@ static void accept_from_sock(struct listener *listener)
        }
 }
 
+static void determine_hostname(void)
+{
+       static char buf[256];
+       if (!hostname) {
+               if (gethostname(buf, 255) == -1) {
+                       net_perror("gethostname");
+                       hostname = "localhost";
+               } else {
+                       hostname = buf;
+               }
+       }
+}
+
 int main(int argc, char *argv[])
 {
 #define MAX_LISTENERS 16
@@ -241,11 +254,18 @@ int main(int argc, char *argv[])
                                return fprintf(stderr, "not enough parameters\n"), 1;
                        luadir = argv[i+1];
                        i += 1;
+               } else if(!strcmp(argv[i], "--hostname")) {
+                       if (i + 1 >= argc)
+                               return fprintf(stderr, "not enough parameters\n"), 1;
+                       hostname = argv[i+1];
+                       i += 1;
                } else {
                        return fprintf(stderr, "unknown flag '%s'\n", argv[i]), 1;
                }
        }
 
+       determine_hostname();
+
        if (!listener_count) {
                listeners[listener_count].ctx = NULL;
                listeners[listener_count++].sock = create_listen_sock("0", "6667");