Function: dns-mode-reverse-and-expand-ipv6
dns-mode-reverse-and-expand-ipv6 is a byte-compiled function defined
in dns-mode.el.gz.
Signature
(dns-mode-reverse-and-expand-ipv6 ADDRESS &optional PREFIX-LENGTH)
Documentation
Convert an IPv6 address to (parts of) an ip6.arpa nibble format.
ADDRESS is an IPv6 address in the usual colon-separated format, without a prefix designator at the end.
Optional PREFIX-LENGTH is a number whose absolute value is the length in bits of the network part of the address. If nil, return an absolute address representing the full IPv6 address. If positive, return an absolute address representing the network prefix indicated. If negative, return a relative address representing the host parts of the address with respect to the indicated network prefix.
See dns-mode-ipv6-to-nibbles for examples.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/dns-mode.el.gz
(defun dns-mode-reverse-and-expand-ipv6 (address &optional prefix-length)
"Convert an IPv6 address to (parts of) an ip6.arpa nibble format.
ADDRESS is an IPv6 address in the usual colon-separated
format, without a prefix designator at the end.
Optional PREFIX-LENGTH is a number whose absolute value is the
length in bits of the network part of the address. If nil,
return an absolute address representing the full IPv6 address.
If positive, return an absolute address representing the network
prefix indicated. If negative, return a relative address
representing the host parts of the address with respect to the
indicated network prefix.
See `dns-mode-ipv6-to-nibbles' for examples."
(let* ((chunks (split-string address ":"))
(prefix-length-nibbles (if prefix-length
(ceiling (abs prefix-length) 4)
32))
(filler-chunks (- 8 (length (remove "" chunks))))
(expanded-address
(apply #'concat
(cl-loop with filler-done = nil
for chunk in chunks
if (and (not filler-done)
(string= "" chunk))
append (prog1
(cl-loop repeat filler-chunks
collect "0000")
(setq filler-done t))
else
if (not (string= "" chunk))
collect (format "%04x"
(string-to-number chunk 16)))))
(rev-address-nibbles
(nreverse (if (and prefix-length
(cl-minusp prefix-length))
(substring expanded-address prefix-length-nibbles)
(substring expanded-address 0 prefix-length-nibbles)))))
(with-temp-buffer
(cl-loop for char across rev-address-nibbles
do
(insert char)
(insert "."))
(if (and prefix-length
(cl-minusp prefix-length))
(delete-char -1)
(insert "ip6.arpa."))
(insert " ")
(buffer-string))))