Function: nsm-network-same-subnet
nsm-network-same-subnet is a byte-compiled function defined in
nsm.el.gz.
Signature
(nsm-network-same-subnet LOCAL-IP MASK IP)
Documentation
Return t if IP is in the same subnet as LOCAL-IP/MASK.
LOCAL-IP, MASK, and IP are specified as vectors of integers, and are expected to have the same length. Works for both IPv4 and IPv6 addresses.
Source Code
;; Defined in /usr/src/emacs/lisp/net/nsm.el.gz
(defun nsm-network-same-subnet (local-ip mask ip)
"Return t if IP is in the same subnet as LOCAL-IP/MASK.
LOCAL-IP, MASK, and IP are specified as vectors of integers, and
are expected to have the same length. Works for both IPv4 and
IPv6 addresses."
(let ((matches t)
(ip-length (length ip))
(local-length (length local-ip)))
(unless (and (memq ip-length '(4 5 8 9))
(memq local-length '(4 5 8 9)))
(error "Unexpected length of IP address %S" local-ip))
(if (/= ip-length local-length)
nil
(dotimes (i local-length)
(setq matches (and matches
(=
(logand (aref local-ip i)
(aref mask i))
(logand (aref ip i)
(aref mask i))))))
matches)))