From a04cc88f24fbdc1f561a154b01e7975bb49fffd3 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 27 Mar 2025 09:35:32 +0200 Subject: [PATCH] use system hostname by default --- README.md | 7 ++++++- src/config.h | 3 --- src/irc.cpp | 2 +- src/main.cpp | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3149caa..99dccd5 100644 --- 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 diff --git a/src/config.h b/src/config.h index 97952c4..6f45e27 100644 --- a/src/config.h +++ b/src/config.h @@ -7,6 +7,3 @@ #ifndef ADMINEMAIL #define ADMINEMAIL "admin@example.com" #endif -#ifndef IRCDHOSTNAME -#define IRCDHOSTNAME "example.com" -#endif diff --git a/src/irc.cpp b/src/irc.cpp index 871845d..c11efc7 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -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); diff --git a/src/main.cpp b/src/main.cpp index e235383..faa4af5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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"); -- 2.56.0