From e03bf5d416776cb5ea27c7354657920939c04e71 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 4 Mar 2015 23:02:15 +0100 Subject: o Adding the hostname to the data. --- apps/apps.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'apps/apps.cpp') diff --git a/apps/apps.cpp b/apps/apps.cpp index 2da8359..ca7cd81 100644 --- a/apps/apps.cpp +++ b/apps/apps.cpp @@ -1,6 +1,7 @@ #include "apps.h" #include #include +#include namespace trygvis { namespace apps { @@ -59,6 +60,35 @@ int launch_app(int argc, char *argv[], app& app) { return app.main(execution); } + +std::string get_hostname() { + struct addrinfo hints, *info, *p; +// int gai_result; + + char hostname[1024]; + hostname[1023] = '\0'; + gethostname(hostname, 1023); + + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_CANONNAME; + + if (getaddrinfo(hostname, "http", &hints, &info)) { + return "uknown"; + } + + string s = "unknown"; + + if (info) { + s = string(info->ai_canonname); + } + + freeaddrinfo(info); + + return s; +} + void app_execution::usage() { cerr << desc << endl; } -- cgit v1.2.3