From d716fe118643f845b127b5a12be8b6a08d735a82 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Mon, 2 Apr 2007 09:43:08 +0000 Subject: [PATCH] Removed assignment of global_parameters.server->host by gethostname() in src/config.c, if listen/@host is empty. This had the very unpleasent side effect in src/http.c:980 in function void http_init(const char *addr) that the if statement 'if (pp)' got triggered, with the string 'flurry:9090' (in mine config) and therefore the only bind has beem made to the loop-back device. As a consequence, pazpar2/masterkey could only be accessed from localhost, which is kind of very useless. What is really needed is that the global_parameters.server->host variable is set to gethostname() in such a way that we are sure to go into the 'else' of the above 'if (pp)', such that we still are listening to all existing interfaces. I tried to do this by assigning global_parameters.server->host = gethostname() using a nmem_strdup(9, but failed due to the fact that I have no access to the correct nmem memory handler here. See src/http.c:1009 for details. Still, I would like to have set global_parameters.server->host = gethostname() somewhere to ensure the 'Via:' header is correct. --- src/config.c | 12 +----------- src/http.c | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/config.c b/src/config.c index 6e31cb9..ccaf13b 100644 --- a/src/config.c +++ b/src/config.c @@ -1,7 +1,6 @@ -/* $Id: config.c,v 1.20 2007-03-31 20:55:19 marc Exp $ */ +/* $Id: config.c,v 1.21 2007-04-02 09:43:08 marc Exp $ */ #include -#include #include #include @@ -228,15 +227,6 @@ 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); } diff --git a/src/http.c b/src/http.c index 98b9489..a327cf3 100644 --- a/src/http.c +++ b/src/http.c @@ -1,5 +1,5 @@ /* - * $Id: http.c,v 1.20 2007-03-31 20:27:15 marc Exp $ + * $Id: http.c,v 1.21 2007-04-02 09:43:08 marc Exp $ */ #include @@ -21,10 +21,11 @@ #endif #include +#include #include #include -#include +#include #include "cconfig.h" #include "util.h" @@ -39,6 +40,7 @@ static void http_destroy(IOCHAN i); extern IOCHAN channel_list; extern struct parameters global_parameters; +//extern NMEM nmem; // If this is set, we proxy normal HTTP requests static struct sockaddr_in *proxy_addr = 0; @@ -988,16 +990,37 @@ void http_init(const char *addr) yaz_log(YLOG_FATAL, "Unable to resolve '%s'", hostname); exit(1); } + memcpy(&myaddr.sin_addr.s_addr, he->h_addr_list[0], he->h_length); port = atoi(pp + 1); + + yaz_log(YLOG_LOG, "HTTP address %s:%d", + "" == he->h_addr_list[0] ? he->h_addr_list[0] : "127.0.0.1" , + port); + } else { + //size_t len = 128; + //char h[len]; port = atoi(addr); myaddr.sin_addr.s_addr = INADDR_ANY; + +#if 0 + // get hostname from system - after deciding to bind to any + // IP address this box might have. + if (0 == gethostname(h, len)){ + h[len - 1] = '\0'; + global_parameters.server->host = nmem_strdup(nmem, h); + } else + yaz_log(YLOG_WARN, "Could not get host name"); +#endif } + + myaddr.sin_port = htons(port); + if (!(p = getprotobyname("tcp"))) { abort(); } -- 1.7.10.4