+void dhcpv6_enum_ia_addrs(struct interface *iface, struct dhcpv6_assignment *c,
+ time_t now, dhcpv6_binding_cb_handler_t func, void *arg)
+{
+ struct odhcpd_ipaddr *addrs = (c->managed) ? c->managed : iface->ia_addr;
+ size_t addrlen = (c->managed) ? (size_t)c->managed_size : iface->ia_addr_len;
+ size_t m = get_preferred_addr(addrs, addrlen);
+
+ for (size_t i = 0; i < addrlen; ++i) {
+ struct in6_addr addr;
+ uint32_t pref, valid;
+ int prefix = c->managed ? addrs[i].prefix : c->length;
+
+ if (!valid_addr(&addrs[i], now))
+ continue;
+
+ addr = addrs[i].addr.in6;
+ pref = addrs[i].preferred;
+ valid = addrs[i].valid;
+ if (prefix == 128) {
+ if (!ADDR_ENTRY_VALID_IA_ADDR(iface, i, m, addrs))
+ continue;
+
+ addr.s6_addr32[3] = htonl(c->assigned);
+ } else {
+ if (!valid_prefix_length(c, addrs[i].prefix))
+ continue;
+
+ addr.s6_addr32[1] |= htonl(c->assigned);
+ addr.s6_addr32[2] = addr.s6_addr32[3] = 0;
+ }
+
+ if (pref != UINT32_MAX)
+ pref -= now;
+
+ if (valid != UINT32_MAX)
+ valid -= now;
+
+ func(&addr, prefix, pref, valid, arg);
+ }
+}
+
+struct write_ctxt {
+ FILE *fp;
+ md5_ctx_t md5;
+ struct dhcpv6_assignment *c;
+ struct interface *iface;
+ char *buf;
+ int buf_len;
+ int buf_idx;
+};
+
+void dhcpv6_write_ia_addr(struct in6_addr *addr, int prefix, _unused uint32_t pref,
+ _unused uint32_t valid, void *arg)
+{
+ struct write_ctxt *ctxt = (struct write_ctxt *)arg;
+ char ipbuf[INET6_ADDRSTRLEN];
+
+ inet_ntop(AF_INET6, addr, ipbuf, sizeof(ipbuf) - 1);
+
+ if (ctxt->c->length == 128 && ctxt->c->hostname) {
+ fputs(ipbuf, ctxt->fp);
+
+ char b[256];
+ if (dn_expand(ctxt->iface->search, ctxt->iface->search + ctxt->iface->search_len,
+ ctxt->iface->search, b, sizeof(b)) > 0)
+ fprintf(ctxt->fp, "\t%s.%s", ctxt->c->hostname, b);
+
+ fprintf(ctxt->fp, "\t%s\n", ctxt->c->hostname);
+ md5_hash(ipbuf, strlen(ipbuf), &ctxt->md5);
+ md5_hash(ctxt->c->hostname, strlen(ctxt->c->hostname), &ctxt->md5);
+ }
+
+ ctxt->buf_idx += snprintf(ctxt->buf + ctxt->buf_idx,ctxt->buf_len - ctxt->buf_idx,
+ "%s/%d ", ipbuf, prefix);
+}