encode actual hostname in RSPRO
The RSPRO ComponentIdentity includes a 'name' for each remsim component.
So far we always used "fixme-name" instead of something meaningful.
Let's use the hostname of the system instead.
Change-Id: I14925f16ae242dae89fa853a2fe31c5c1b32981d
diff --git a/src/bankd/bankd_main.c b/src/bankd/bankd_main.c
index d8dab03..8ec0966 100644
--- a/src/bankd/bankd_main.c
+++ b/src/bankd/bankd_main.c
@@ -59,6 +59,7 @@
__thread void *talloc_asn1_ctx;
struct bankd *g_bankd;
static void *g_tall_ctx;
+static char g_hostname[256];
static void *worker_main(void *arg);
@@ -91,7 +92,7 @@
bankd->srvc.bankd.num_slots = 8;
bankd->comp_id.type = ComponentType_remsimBankd;
- OSMO_STRLCPY_ARRAY(bankd->comp_id.name, "fixme-name");
+ OSMO_STRLCPY_ARRAY(bankd->comp_id.name, g_hostname);
OSMO_STRLCPY_ARRAY(bankd->comp_id.software, "remsim-bankd");
OSMO_STRLCPY_ARRAY(bankd->comp_id.sw_version, PACKAGE_VERSION);
/* FIXME: other members of app_comp_id */
@@ -363,6 +364,9 @@
g_bankd = talloc_zero(NULL, struct bankd);
OSMO_ASSERT(g_bankd);
+ if (gethostname(g_hostname, sizeof(g_hostname)) < 0)
+ OSMO_STRLCPY_ARRAY(g_hostname, "unknown");
+
bankd_init(g_bankd);
srvc = &g_bankd->srvc;
@@ -370,7 +374,7 @@
srvc->server_port = 9998;
srvc->handle_rx = bankd_srvc_handle_rx;
srvc->own_comp_id.type = ComponentType_remsimBankd;
- OSMO_STRLCPY_ARRAY(srvc->own_comp_id.name, "fixme-name");
+ OSMO_STRLCPY_ARRAY(srvc->own_comp_id.name, g_hostname);
OSMO_STRLCPY_ARRAY(srvc->own_comp_id.software, "remsim-bankd");
OSMO_STRLCPY_ARRAY(srvc->own_comp_id.sw_version, PACKAGE_VERSION);
diff --git a/src/client/user_ifdhandler.c b/src/client/user_ifdhandler.c
index 551db00..5704fba 100644
--- a/src/client/user_ifdhandler.c
+++ b/src/client/user_ifdhandler.c
@@ -125,7 +125,6 @@
/* configuration of client thread; passed in from IFD thread */
struct client_thread_cfg {
- const char *name;
const char *server_host;
int server_port;
int client_id;
@@ -367,8 +366,12 @@
struct client_thread_cfg *cfg = arg;
struct client_config *ccfg;
struct client_thread *ct;
+ char hostname[256];
int rc;
+ if (gethostname(hostname, sizeof(hostname)) < 0)
+ OSMO_STRLCPY_ARRAY(hostname, "unknown");
+
osmo_select_init();
rc = osmo_ctx_init("client");
OSMO_ASSERT(rc == 0);
@@ -387,7 +390,7 @@
if (!talloc_asn1_ctx)
talloc_asn1_ctx= talloc_named_const(ct, 0, "asn1");
- ct->bc = remsim_client_create(ct, cfg->name, "remsim_ifdhandler", ccfg);
+ ct->bc = remsim_client_create(ct, hostname, "remsim_ifdhandler", ccfg);
OSMO_ASSERT(ct->bc);
ct->bc->data = ct;
@@ -560,7 +563,6 @@
{
struct ifd_client *ic;
struct client_thread_cfg cfg = {
- .name = "fixme-name",
.server_host = "127.0.0.1",
.server_port = -1,
.client_id = 0,
diff --git a/src/server/remsim_server.c b/src/server/remsim_server.c
index c2d54e5..71590f4 100644
--- a/src/server/remsim_server.c
+++ b/src/server/remsim_server.c
@@ -80,9 +80,13 @@
int main(int argc, char **argv)
{
+ char hostname[256];
void *talloc_rest_ctx;
int rc;
+ if (gethostname(hostname, sizeof(hostname)) < 0)
+ OSMO_STRLCPY_ARRAY(hostname, "unknown");
+
g_tall_ctx = talloc_named_const(NULL, 0, "global");
talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
talloc_rest_ctx = talloc_named_const(g_tall_ctx, 0, "rest");
@@ -106,7 +110,7 @@
goto out_rspro;
g_rps->comp_id.type = ComponentType_remsimServer;
- OSMO_STRLCPY_ARRAY(g_rps->comp_id.name, "fixme-name");
+ OSMO_STRLCPY_ARRAY(g_rps->comp_id.name, hostname);
OSMO_STRLCPY_ARRAY(g_rps->comp_id.software, "remsim-server");
OSMO_STRLCPY_ARRAY(g_rps->comp_id.sw_version, PACKAGE_VERSION);
/* FIXME: other members of app_comp_id */