Function: dns-mode-ipv6-to-nibbles

dns-mode-ipv6-to-nibbles is an interactive and byte-compiled function defined in dns-mode.el.gz.

Signature

(dns-mode-ipv6-to-nibbles &optional NEGATE-PREFIX)

Documentation

Convert an IPv6 address around or before point.

Replace the address by its ip6.arpa-representation for use in reverse zone files, placing the original address in the kill ring.

The address can be: a complete address (no prefix designator); with a normal prefix designator (e.g. /48), in which case only the required number of nibbles are output; or with a negative prefix designator (e.g. /-112), in which case only the part of the address *not* covered by the absolute value of the prefix length is output, as a relative address (without ".ip6.arpa." at the end). This is useful when $ORIGIN is specified in the zone file.

Optional prefix argument NEGATE-PREFIX negates the value of the detected prefix length.

Examples:

2001:db8::12 =>
2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.

2001:db8::12/32 =>
8.b.d.0.1.0.0.2.ip6.arpa.

2001:db8::12/-32 =>
2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0

::42/112 (with prefix argument) =>
2.4.0.0

Probably introduced at or before Emacs version 26.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/dns-mode.el.gz
(defun dns-mode-ipv6-to-nibbles (&optional negate-prefix)
  "Convert an IPv6 address around or before point.
Replace the address by its ip6.arpa-representation for use in
reverse zone files, placing the original address in the kill ring.

The address can be: a complete address (no prefix designator);
with a normal prefix designator (e.g. /48), in which case only
the required number of nibbles are output; or with a negative
prefix designator (e.g. /-112), in which case only the part of
the address *not* covered by the absolute value of the prefix
length is output, as a relative address (without \".ip6.arpa.\" at
the end).  This is useful when $ORIGIN is specified in the zone file.

Optional prefix argument NEGATE-PREFIX negates the value of the
detected prefix length.

Examples:

2001:db8::12  =>
2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.

2001:db8::12/32  =>
8.b.d.0.1.0.0.2.ip6.arpa.

2001:db8::12/-32  =>
2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0

::42/112 (with prefix argument) =>
2.4.0.0"
  (interactive "P")
  (skip-syntax-backward " ")
  (skip-syntax-backward "w_.")
  (re-search-forward "\\([[:xdigit:]:]+\\)\\(/-?[0-9]\\{2,3\\}\\)?")
  (let ((address (match-string 1))
        (prefix-length (match-string 2)))
    (kill-new (match-string 0))
    (when prefix-length
      (setq prefix-length (string-to-number (substring prefix-length 1)))
      (if negate-prefix
          (setq prefix-length (- prefix-length))))
    (replace-match
     (save-match-data
       (dns-mode-reverse-and-expand-ipv6 address prefix-length)))))