diff options
author | Steven Barth <steven@midlink.org> | 2013-05-13 17:17:07 +0200 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2013-05-13 17:17:07 +0200 |
commit | aeb7c37224051811553c898b2a784944f26276b0 (patch) | |
tree | 5dbf54850371f9f977ca8c85f0afedf6af4a643a /src/script.c | |
parent | aabacd97af729d44fe6e6e171fb65b1086e23417 (diff) | |
download | odhcp6c-aeb7c37224051811553c898b2a784944f26276b0.tar.gz |
Export AFTR-IP as well and update README
Diffstat (limited to 'src/script.c')
-rw-r--r-- | src/script.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/script.c b/src/script.c index b9bf0aa..9d88daf 100644 --- a/src/script.c +++ b/src/script.c @@ -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); |