For Linux, it uses the uname() function.
For Windows, it uses the GetVersion() API.
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/host.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
src/host.h | 2 +
src/qmf/hostagent.cpp | 1 +
3 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/src/host.cpp b/src/host.cpp
index 730529c..4792557 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -196,6 +196,58 @@ host_get_hostname()
}
string
+host_get_operating_system()
+{
+ static string operating_system;
+
+ if(operating_system.empty())
+ {
+#ifdef __linux__
+
+ struct utsname details;
+
+ if(!uname(&details))
+ {
+ operating_system = string(details.sysname) +
+ " (" + details.release + ")";
+ }
+
+#elif defined WIN32
+
+ HINSTANCE dll;
+
+ dll = LoadLibrary("kernel32");
+
+ if(dll != NULL)
+ {
+ typedef DWORD(WINAPI *version_function)(void);
+ version_function proc;
+ DWORD version;
+
+ proc = (version_function)GetProcAddress(dll,"GetVersion");
+
+ if(proc)
+ {
+ version = (*proc)();
+
+ DWORD major, minor, build;
+
+ major = (DWORD)(LOBYTE(LOWORD(version)));
+ minor = (DWORD)(HIBYTE(LOWORD(version)));
+ build = (DWORD)(HIWORD(version));
+
+ operating_system = string("Windows ") +
+ "(" + major + "." + minor + "." + build + ")";
+ }
+ }
+
+#endif
+ }
+
+ return operating_system;
+}
+
+string
host_get_hypervisor()
{
static string hypervisor;
diff --git a/src/host.h b/src/host.h
index a680861..f83e3fd 100644
--- a/src/host.h
+++ b/src/host.h
@@ -37,6 +37,8 @@ string host_get_uuid();
string host_get_hostname();
+string host_get_operating_system();
+
string host_get_hypervisor();
unsigned int host_get_platform();
diff --git a/src/qmf/hostagent.cpp b/src/qmf/hostagent.cpp
index 49bb40b..b67a1d6 100644
--- a/src/qmf/hostagent.cpp
+++ b/src/qmf/hostagent.cpp
@@ -42,6 +42,7 @@ HostAgent::setup(ManagementAgent* agent)
_management_object->set_uuid(host_get_uuid());
_management_object->set_hostname(host_get_hostname());
+ _management_object->set_operating_system(host_get_operating_system());
_management_object->set_hypervisor(host_get_hypervisor());
_management_object->set_platform(host_get_platform());
_management_object->set_arch(host_get_architecture());
--
1.7.2