aboutsummaryrefslogtreecommitdiff
path: root/apps/apps.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-03-04 23:02:15 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-03-04 23:02:15 +0100
commite03bf5d416776cb5ea27c7354657920939c04e71 (patch)
tree184e66ef69966c7671ef2f3d4750283bb0b4f149 /apps/apps.cpp
parent4fa6e39b7e74761dc54b6203cd05c8d5b89cb7c8 (diff)
downloadble-toys-e03bf5d416776cb5ea27c7354657920939c04e71.tar.gz
ble-toys-e03bf5d416776cb5ea27c7354657920939c04e71.tar.bz2
ble-toys-e03bf5d416776cb5ea27c7354657920939c04e71.tar.xz
ble-toys-e03bf5d416776cb5ea27c7354657920939c04e71.zip
o Adding the hostname to the data.
Diffstat (limited to 'apps/apps.cpp')
-rw-r--r--apps/apps.cpp30
1 files changed, 30 insertions, 0 deletions
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 <log4cplus/logger.h>
#include <log4cplus/configurator.h>
+#include <netdb.h>
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;
}