ACK
On Mon, Jul 26, 2010 at 4:23 PM, Darryl L. Pierce <dpierce(a)redhat.com> wrote:
Added conditional code for get the hostname via Windows APIs when
compiling on Windows.
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
src/host.cpp | 29 +++++++++++++++++++++++++++--
1 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/host.cpp b/src/host.cpp
index d6955a5..2f86dea 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -27,8 +27,17 @@
#include <stdexcept>
#include <string>
#include <sys/sysinfo.h>
+
+#ifdef __linux__
+
#include <sys/utsname.h>
+#elif defined WIN32
+
+#include <winsock.h>
+
+#endif
+
// TODO remove this wrapper once rhbz#583747 is fixed
extern "C" {
#include <libudev.h>
@@ -117,16 +126,32 @@ host_get_hostname()
if(hostname.empty())
{
-
#ifdef __linux__
+
struct utsname details;
if(!uname(&details))
{
hostname = string(details.nodename);
}
- #endif
+#elif defined WIN32
+
+ char buffer[512];
+ WORD verreq;
+ WSADATA wsadata;
+
+ verreq = MAKEWORD(2, 2);
+ if(!WSAStartup(verreq, &wsadata))
+ {
+ if(!gethostname(buffer, 512))
+ {
+ hostname = string(buffer);
+ }
+ WSACleanup();
+ }
+
+ #endif
}
return hostname;
--
1.7.1.1
_______________________________________________
Matahari mailing list
Matahari(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/matahari