X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/67203c66600113259f4f25b1021c6395f3a62dd6..c7f3a407f4f8d539fe68cbf7dde76876cbcbccaa:/slstatus.c diff --git a/slstatus.c b/slstatus.c index 9cd5ae2..404ead6 100644 --- a/slstatus.c +++ b/slstatus.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -208,6 +209,29 @@ entropy(const char *null) return smprintf("%d", entropy); } +/* hostname */ +char * +hostname(const char *null) +{ + char hostname[HOST_NAME_MAX]; + FILE *fp; + + /* open hostname file */ + if (!(fp = fopen("/proc/sys/kernel/hostname", "r"))) { + fprintf(stderr, "Could not open hostname file.\n"); + return smprintf("n/a"); + } + + /* extract hostname */ + fscanf(fp, "%s\n", hostname); + + /* close hostname file */ + fclose(fp); + + /* return entropy */ + return smprintf("%s", hostname); +} + /* ip address */ char * ip(const char *interface)