From 18ef4ce52ceca13743ecc1625964362bd906ff53 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Thu, 28 Jun 2018 15:10:28 -0400 Subject: [PATCH] include ipv4 addresses and hostname (if galaxy) in %eyre %born --- vere/http.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/vere/http.c b/vere/http.c index 52eca13bdb..346078eebc 100644 --- a/vere/http.c +++ b/vere/http.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -1071,14 +1072,98 @@ _http_release_ports_file(c3_c *pax_c) u3a_free(paf_c); } +/* _http_czar_host(): galaxy hostname as (unit host:eyre) +*/ +static u3_noun +_http_czar_host(void) +{ + u3_noun dom = u3_nul; + + if ( (0 == u3_Host.ops_u.imp_c) || (c3n == u3_Host.ops_u.net) ) { + return dom; + } + + { + c3_c* dns_c = u3_Host.ops_u.dns_c; + c3_w len_w = strlen(dns_c); + c3_w dif_w; + c3_c* dom_c; + c3_c* dot_c; + + while ( 0 != len_w ) { + if ( 0 == (dot_c = strchr(dns_c, '.'))) { + len_w = 0; + dom = u3nc(u3i_string(dns_c), dom); + break; + } + else { + dif_w = dot_c - dns_c; + dom_c = c3_malloc(1 + dif_w); + strncpy(dom_c, dns_c, dif_w); + dom_c[dif_w] = 0; + + dom = u3nc(u3i_string(dom_c), dom); + + // increment to skip leading '.' + dns_c = dot_c + 1; + free(dom_c); + + // XX confirm that underflow is impossible here + len_w -= c3_min(dif_w, len_w); + } + } + } + + if ( u3_nul == dom ) { + return dom; + } + + // increment to skip '~' + dom = u3nc(u3i_string(u3_Host.ops_u.imp_c + 1), u3kb_flop(u3k(dom))); + + return u3nt(u3_nul, c3y, u3kb_flop(u3k(dom))); +} + /* u3_http_ef_bake(): notify %eyre that we're live */ void u3_http_ef_bake(void) { + u3_noun ipf = u3_nul; + + { + struct ifaddrs* iad_u; + getifaddrs(&iad_u); + + struct ifaddrs* dia_u = iad_u; + + while ( iad_u ) { + struct sockaddr_in* adr_u = (struct sockaddr_in *)iad_u->ifa_addr; + + if ( (0 != adr_u) && (AF_INET == adr_u->sin_family) ) { + c3_w ipf_w = ntohl(adr_u->sin_addr.s_addr); + + if ( INADDR_LOOPBACK != ipf_w ) { + ipf = u3nc(u3nc(c3n, u3i_words(1, &ipf_w)), ipf); + } + } + + iad_u = iad_u->ifa_next; + } + + freeifaddrs(dia_u); + } + + u3_noun hot = _http_czar_host(); + + if ( u3_nul != hot ) { + ipf = u3nc(u3k(u3t(hot)), ipf); + u3z(hot); + } + u3_noun pax = u3nq(u3_blip, c3__http, u3k(u3A->sen), u3_nul); - u3v_plan(pax, u3nc(c3__born, u3_nul)); + u3v_plan(pax, u3nc(c3__born, ipf)); } /* u3_http_ef_thou(): send %thou from %eyre as http response.