From: Marc Cromme Date: Sat, 31 Mar 2007 20:55:19 +0000 (+0000) Subject: get hostname from system call 'gethostname()' if not set in X-Git-Tag: PAZPAR2.1.0.0~375 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=e4455bdba629094b65748532d4454d8c749b53c9;p=pazpar2-moved-to-github.git get hostname from system call 'gethostname()' if not set in in config file. The hostname is under all circumstances needed to produce the correct HTTP headers 'Via:' and 'X-Pazpar2-Server-Host:' --- diff --git a/src/config.c b/src/config.c index cbdbd97..6e31cb9 100644 --- a/src/config.c +++ b/src/config.c @@ -1,6 +1,7 @@ -/* $Id: config.c,v 1.19 2007-03-30 02:45:07 quinn Exp $ */ +/* $Id: config.c,v 1.20 2007-03-31 20:55:19 marc Exp $ */ #include +#include #include #include @@ -227,6 +228,15 @@ static struct conf_server *parse_server(xmlNode *node) r->port = atoi((const char *) port); if (host) r->host = nmem_strdup(nmem, (const char *) host); + else { // get hostname from system + size_t len = 128; + char h[len]; + if (0 == gethostname(h, len)){ + h[len - 1] = '\0'; + r->host = nmem_strdup(nmem, h); + } else + yaz_log(YLOG_WARN, "Could not get host name"); + } xmlFree(port); xmlFree(host); }