Skip to content

Commit

Permalink
add hostname and domain to EvnInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoby committed Sep 26, 2023
1 parent 40816e1 commit f722ccf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
6 changes: 4 additions & 2 deletions inc_internal/internal_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) \
Expand Down
2 changes: 2 additions & 0 deletions inc_internal/zt_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions library/internal_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef uint32_t in_addr_t;
#endif

#include <string.h>
#include <unistd.h>
#include "ziti/ziti_buffer.h"
#include "ziti/ziti.h"

Expand Down Expand Up @@ -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)

Expand Down
10 changes: 1 addition & 9 deletions library/ziti_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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) {
Expand Down

0 comments on commit f722ccf

Please sign in to comment.