]> git.decadent.org.uk Git - odhcp6c.git/commitdiff
Export AFTR-IP as well and update README
authorSteven Barth <steven@midlink.org>
Mon, 13 May 2013 15:17:07 +0000 (17:17 +0200)
committerSteven Barth <steven@midlink.org>
Mon, 13 May 2013 15:17:07 +0000 (17:17 +0200)
README
src/script.c

diff --git a/README b/README
index 3dd52896f029f07f50a5d8d32efeb317c178d66a..a6fa29897a9b3d6bcfbd2f7c441af88f736dc345 100644 (file)
--- a/README
+++ b/README
@@ -28,6 +28,7 @@ especially routers. It compiles to only about 30 KB (-Os -s).
        f) SIP Options
        g) Information-Refresh Options
        h) SOL_MAX_RT default to 3600
+       i) DS-Lite AFTR-Name Option
 
 4. Support for requesting and parsing Router Advertisements
        a) parsing of prefixes, routes, MTU and RDNSS options
@@ -75,3 +76,5 @@ Environment:
 * RA_ROUTES            A space-separated list of routes from the RA
                                Format: <address>/<length>,gateway,valid,metric
 * RA_DNS               A space-separated list of recursive DNS servers from the RA
+* AFTR                 The DS-Lite AFTR domain name
+* AFTR_IP              The DS-Lite AFTR resolved IPv6 address
index b9bf0aa094ade19926eaadee5e6f31eaee089f01..9d88daf43676054a4c415b917b8f8a7931d38452 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <stdio.h>
+#include <netdb.h>
 #include <resolv.h>
 #include <stdlib.h>
 #include <string.h>
@@ -115,6 +116,29 @@ static void fqdn_to_env(const char *name, const uint8_t *fqdn, size_t len)
 }
 
 
+static void fqdn_to_ip_env(const char *name, const uint8_t *fqdn, size_t len)
+{
+       size_t buf_len = strlen(name);
+       char *buf = realloc(NULL, INET6_ADDRSTRLEN + buf_len + 3);
+       memcpy(buf, name, buf_len);
+       buf[buf_len++] = '=';
+
+       char namebuf[256];
+       if (dn_expand(fqdn, fqdn + len, fqdn, namebuf, sizeof(namebuf)) <= 0)
+               return;
+
+       struct addrinfo hints = {.ai_family = AF_INET6}, *r;
+       if (getaddrinfo(namebuf, NULL, &hints, &r))
+               return;
+
+       struct sockaddr_in6 *sin6 = (struct sockaddr_in6*)r->ai_addr;
+       inet_ntop(AF_INET6, &sin6->sin6_addr, &buf[buf_len], INET6_ADDRSTRLEN);
+
+       freeaddrinfo(r);
+       putenv(buf);
+}
+
+
 static void bin_to_env(uint8_t *opts, size_t len)
 {
        uint8_t *oend = opts + len, *odata;
@@ -230,6 +254,7 @@ void script_call(const char *status)
                fqdn_to_env("SNTP_FQDN", sntp_dns, sntp_dns_len);
                fqdn_to_env("SIP_DOMAIN", sip_fqdn, sip_fqdn_len);
                fqdn_to_env("AFTR", aftr_name, aftr_name_len);
+               fqdn_to_ip_env("AFTR_IP", aftr_name, aftr_name_len);
                bin_to_env(custom, custom_len);
                entry_to_env("PREFIXES", prefix, prefix_len, ENTRY_PREFIX);
                entry_to_env("ADDRESSES", address, address_len, ENTRY_ADDRESS);