Function: erc-ip-to-decimal

erc-ip-to-decimal is an interactive and byte-compiled function defined in erc-dcc.el.gz.

Signature

(erc-ip-to-decimal IP)

Documentation

Convert IP address to its decimal representation.

Argument IP is the address as a string. The result is also a string.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc-dcc.el.gz
(defun erc-ip-to-decimal (ip)
  "Convert IP address to its decimal representation.
Argument IP is the address as a string.  The result is also a string."
  (interactive "sIP Address: ")
  (if (not (string-match erc-dcc-ipv4-regexp ip))
      (error "Not an IP address")
    (let* ((ips (mapcar
                 (lambda (str)
                   (let ((n (string-to-number str)))
                     (if (and (>= n 0) (< n 256))
                         n
                       (error "%d out of range" n))))
                 (split-string ip "\\.")))
           (res (+ (* (car ips) 16777216.0)
                   (* (nth 1 ips) 65536.0)
                   (* (nth 2 ips) 256.0)
                   (nth 3 ips))))
      (if (called-interactively-p 'interactive)
          (message "%s is %.0f" ip res)
        (format "%.0f" res)))))