diff --git a/inc_internal/internal_model.h b/inc_internal/internal_model.h index 6722d593..b6207625 100644 --- a/inc_internal/internal_model.h +++ b/inc_internal/internal_model.h @@ -90,11 +90,13 @@ XX(app_version, string, none, appVersion, __VA_ARGS__) XX(os, string, none, os, __VA_ARGS__) \ XX(os_release, string, none, osRelease, __VA_ARGS__) \ XX(os_version, string, none, osVersion, __VA_ARGS__) \ -XX(arch, string, none, arch, __VA_ARGS__) +XX(arch, string, none, arch, __VA_ARGS__) \ +XX(hostname, string, none, hostname, __VA_ARGS__) \ +XX(domain, string, none, domain, __VA_ARGS__) #define ZITI_AUTH_REQ(XX, ...) \ XX(sdk_info, ziti_sdk_info, none, sdkInfo, __VA_ARGS__) \ -XX(env_info, ziti_env_info, none, envInfo, __VA_ARGS__) \ +XX(env_info, ziti_env_info, ptr, envInfo, __VA_ARGS__) \ XX(config_types, string, list, configTypes, __VA_ARGS__) #define ZITI_ENROLLMENT_RESP(XX, ...) \ diff --git a/inc_internal/zt_internal.h b/inc_internal/zt_internal.h index e0829a2c..893b1810 100644 --- a/inc_internal/zt_internal.h +++ b/inc_internal/zt_internal.h @@ -386,6 +386,8 @@ extern void ziti_send_event(ziti_context ztx, const ziti_event_t *e); void reject_dial_request(uint32_t conn_id, ziti_channel_t *ch, int32_t req_id, const char *reason); +const ziti_env_info* get_env_info(); + extern uv_timer_t *new_ztx_timer(ziti_context ztx); #ifdef __cplusplus diff --git a/library/internal_model.c b/library/internal_model.c index df226ff3..e72055b4 100644 --- a/library/internal_model.c +++ b/library/internal_model.c @@ -28,6 +28,7 @@ typedef uint32_t in_addr_t; #endif #include +#include #include "ziti/ziti_buffer.h" #include "ziti/ziti.h" @@ -166,6 +167,32 @@ int ziti_service_get_config(ziti_service *service, const char *cfg_type, void *c return ZITI_OK; } +static uv_once_t info_once; +static ziti_env_info s_info; +static void ziti_info_init() { + static uv_utsname_t os_info; + static char s_hostname[UV_MAXHOSTNAMESIZE]; + static char s_domain[UV_MAXHOSTNAMESIZE]; + + uv_os_uname(&os_info); + s_info.os = os_info.sysname; + s_info.os_release = os_info.release; + s_info.os_version = os_info.version; + s_info.arch = os_info.machine; + size_t len = sizeof(s_hostname); + uv_os_gethostname(s_hostname, &len); + len = sizeof(s_domain); + getdomainname(s_domain, len); + + s_info.hostname = s_hostname; + s_info.domain = s_domain; +} + +const ziti_env_info* get_env_info() { + uv_once(&info_once, ziti_info_init); + return &s_info; +} + static int cmp_ziti_address0(ziti_address *lh, ziti_address *rh) { null_checks(lh, rh) diff --git a/library/ziti_ctrl.c b/library/ziti_ctrl.c index e8a51408..b591f09e 100644 --- a/library/ziti_ctrl.c +++ b/library/ziti_ctrl.c @@ -454,9 +454,6 @@ void ziti_ctrl_login( void(*cb)(ziti_api_session *, const ziti_error *, void *), void *ctx) { - uv_utsname_t osInfo; - uv_os_uname(&osInfo); - ziti_auth_req authreq = { .sdk_info = { .type = "ziti-sdk-c", @@ -466,12 +463,7 @@ void ziti_ctrl_login( .app_id = (char *) APP_ID, .app_version = (char *) APP_VERSION, }, - .env_info = { - .os = osInfo.sysname, - .os_release = osInfo.release, - .os_version = osInfo.version, - .arch = osInfo.machine, - }, + .env_info = (ziti_env_info *)get_env_info(), .config_types = {0} }; if (cfg_types) {