From 2e72b212d3019a23accfd9d001bcec5d3ee5ab46 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Fri, 10 Jun 2016 15:53:07 +0200 Subject: hostname function --- slstatus.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'slstatus.c') diff --git a/slstatus.c b/slstatus.c index 9cd5ae2..5bbf58a 100644 --- a/slstatus.c +++ b/slstatus.c @@ -208,6 +208,29 @@ entropy(const char *null) return smprintf("%d", entropy); } +/* hostname */ +char * +hostname(const char *null) +{ + char *hostname = ""; + 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", hostname); + + /* close hostname file */ + fclose(fp); + + /* return entropy */ + return smprintf("%s", hostname); +} + /* ip address */ char * ip(const char *interface) -- cgit v1.2.3