From c86834d40fa6b07828b10e2c6d8d2c6bd35fe116 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 11 Jun 2015 20:59:00 +0200 Subject: replaced gethostname on Windows with GetComputerNameEx --- src/NMakefile | 1 + src/cli.c | 2 +- src/coordinator.c | 6 +++--- src/system.c | 12 ++++++++++++ src/system.h | 2 ++ src/worker.c | 2 +- 6 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/NMakefile b/src/NMakefile index e7fb64a..ede3e98 100644 --- a/src/NMakefile +++ b/src/NMakefile @@ -90,4 +90,5 @@ run: all @-copy "$(GTK3_BUNDLE_DIR)\bin\pthreadGC2.dll" . @-copy "$(GTK3_BUNDLE_DIR)\bin\gspawn-win32-helper-console.exe . @-biruda -c biruda.conf -p + @-biruda --guess-env --human-readable diff --git a/src/cli.c b/src/cli.c index f5bdcd1..3f8f903 100644 --- a/src/cli.c +++ b/src/cli.c @@ -398,7 +398,7 @@ int start_interactive( bool colors, const char *host, unsigned short port, FILE void print_guessed_env( bool human_readable ) { char hostname[100]; - gethostname( hostname, sizeof( hostname ) ); + system_hostname( hostname, sizeof( hostname ) ); unsigned int nofCpus = system_available_cpus( ); unsigned int nofPhysMem = system_phys_memory( ); char os_name[100]; diff --git a/src/coordinator.c b/src/coordinator.c index 356a402..c74c822 100644 --- a/src/coordinator.c +++ b/src/coordinator.c @@ -42,7 +42,7 @@ static char *create_worker_started_answer( const char *name, bool worker_found ) * or additionally the MAC of the first interface or hostid?) */ char hostname[100]; - gethostname( hostname, sizeof( hostname ) ); + system_hostname( hostname, sizeof( hostname ) ); json_object *host = json_object_new_string( hostname ); json_object_object_add( obj, "host", host ); @@ -75,7 +75,7 @@ static char *create_worker_stopped_answer( const char *name, bool worker_found ) * or additionally the MAC of the first interface or hostid?) */ char hostname[100]; - gethostname( hostname, sizeof( hostname ) ); + system_hostname( hostname, sizeof( hostname ) ); json_object *host = json_object_new_string( hostname ); json_object_object_add( obj, "host", host ); @@ -108,7 +108,7 @@ static char *create_register_answer( ) * or additionally the MAC of the first interface or hostid?) */ char hostname[100]; - gethostname( hostname, sizeof( hostname ) ); + system_hostname( hostname, sizeof( hostname ) ); json_object *host = json_object_new_string( hostname ); json_object_object_add( obj, "host", host ); diff --git a/src/system.c b/src/system.c index 766e264..7d2e052 100644 --- a/src/system.c +++ b/src/system.c @@ -20,6 +20,7 @@ #ifdef __NetBSD__ #include #else /* __NetBSD__ */ +#include #endif /* __NetBSD__ */ #endif /* __FreeBSD__ */ #endif /* _WIN32 */ @@ -391,6 +392,17 @@ void system_arch( char *name, size_t len ) #endif } +int system_hostname( char *name, size_t len ) +{ +#ifdef _WIN32 + DWORD dwSize = len; + int res = GetComputerNameExA( ComputerNamePhysicalDnsFullyQualified, name, &dwSize ); + return ( res > 0 ) ? 0 : -1; +#else + return gethostname( name, len ); +#endif +} + unsigned int system_phys_memory( ) { #ifdef _WIN32 diff --git a/src/system.h b/src/system.h index 3ff2ebb..dee8669 100644 --- a/src/system.h +++ b/src/system.h @@ -9,6 +9,8 @@ void system_os( char *name, size_t len ); void system_arch( char *name, size_t len ); +int system_hostname( char *name, size_t len ); + /* in kilobytes */ unsigned int system_phys_memory( ); diff --git a/src/worker.c b/src/worker.c index 4360432..733718c 100644 --- a/src/worker.c +++ b/src/worker.c @@ -335,7 +335,7 @@ static char *expand_system_variables( const char *s ) state = COPYING; } else if( strncmp( var, "HOST", 4 ) == 0 ) { char hostname[100]; - gethostname( hostname, sizeof( hostname ) ); + system_hostname( hostname, sizeof( hostname ) ); strncpy( d, hostname, strlen( hostname ) ); d += strlen( hostname ); state = COPYING; -- cgit v1.2.3-54-g00ecf