From 0178e09ff9f99128afa54fa8268e9d408deee161 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Fri, 20 Jan 2006 23:29:12 +0000 Subject: [PATCH] Server ID sent in broadcast reply --- config.c | 1 + mvpserver.c | 42 ++++++++++++++++++++++++++++++++++++++++-- mvpserver.h | 2 +- udpreplier.c | 10 ++++++++-- udpreplier.h | 3 ++- 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/config.c b/config.c index 272f352..dccf524 100644 --- a/config.c +++ b/config.c @@ -57,6 +57,7 @@ int Config::init(char* takeFileName) fclose(file); initted = 1; + log->log("Config", Log::DEBUG, "Opened config file: %s", fileName); return 1; } diff --git a/mvpserver.c b/mvpserver.c index 29a1fbe..c02e75e 100644 --- a/mvpserver.c +++ b/mvpserver.c @@ -48,9 +48,47 @@ int MVPServer::run() { if (threadIsActive()) return 1; - log.init(Log::DEBUG, "/tmp/vompserver.log", 0); + log.init(Log::DEBUG, "/tmp/vompserver.log", 1); - if (!udpr.run()) + char serverName[1024]; + bool nameSuccess = false; + + // Try to get a server name from vomp.conf + const char* configDir = cPlugin::ConfigDirectory(); + if (!configDir) + { + log.log("Client", Log::DEBUG, "No config dir!"); + } + else + { + char configFileName[PATH_MAX]; + snprintf(configFileName, PATH_MAX, "%s/vomp.conf", configDir); + + Config c; + if (c.init(configFileName)) + { + char* fc = c.getValueString("General", "Server name"); + if (fc) + { + strncpy(serverName, fc, 1024); + delete[] fc; + nameSuccess = true; + } + } + c.shutdown(); + } + + if (!nameSuccess) + { + if (gethostname(serverName, 1024)) // if fail + { + strcpy(serverName, "-"); + } + } + + serverName[1023] = '\0'; + + if (!udpr.run(serverName)) { log.log("MVPServer", Log::CRIT, "Could not start UDP replier"); log.shutdown(); diff --git a/mvpserver.h b/mvpserver.h index a14b1f3..d64268d 100644 --- a/mvpserver.h +++ b/mvpserver.h @@ -23,7 +23,7 @@ #include #include -#include // sleep +#include #include #include "defines.h" diff --git a/udpreplier.c b/udpreplier.c index 922231a..ed3bf84 100644 --- a/udpreplier.c +++ b/udpreplier.c @@ -23,11 +23,14 @@ UDPReplier::UDPReplier() : ds(3024) { + serverName = NULL; } UDPReplier::~UDPReplier() { if (threadIsActive()) stop(); + if (serverName) delete[] serverName; + serverName = NULL; } int UDPReplier::stop() @@ -37,10 +40,13 @@ int UDPReplier::stop() return 1; } -int UDPReplier::run() +int UDPReplier::run(char* tserverName) { if (threadIsActive()) return 1; + serverName = new char[strlen(tserverName)+1]; + strcpy(serverName, tserverName); + if (!threadStart()) return 0; Log::getInstance()->log("UDP", Log::DEBUG, "UDP replier started"); @@ -56,6 +62,6 @@ void UDPReplier::threadMethod() if (retval == 1) continue; if (!strcmp(ds.getData(), "VOMP")) - ds.send(ds.getFromIPA(), 3024, "VOMP SERVER", 11); + ds.send(ds.getFromIPA(), 3024, serverName, strlen(serverName)); } } diff --git a/udpreplier.h b/udpreplier.h index bdcc810..371e5a1 100644 --- a/udpreplier.h +++ b/udpreplier.h @@ -34,13 +34,14 @@ class UDPReplier : public Thread UDPReplier(); virtual ~UDPReplier(); - int run(); + int run(char* tserverName); int stop(); private: void threadMethod(); DatagramSocket ds; + char* serverName; }; #endif -- 2.39.5