From 4a38ccb53ad957635ab31eb99bec186f2f3fb00f Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Mon, 18 Feb 2008 15:43:13 +0100 Subject: [PATCH] INET-ADDRESS-PRIVATE-P now returns the class of the address as second value. Signed-off-by: Stelian Ionescu --- net.sockets/address-arithmetic.lisp | 17 +++++++++++++++++ net.sockets/address-predicates.lisp | 16 ---------------- net.sockets/pkgdcl.lisp | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/net.sockets/address-arithmetic.lisp b/net.sockets/address-arithmetic.lisp index 818e7e2..8745df9 100644 --- a/net.sockets/address-arithmetic.lisp +++ b/net.sockets/address-arithmetic.lisp @@ -96,3 +96,20 @@ subnet specified by NETWORK and MASK.") ((= #b0110 (ldb (byte 3 5) octet)) :c) ((= #b1110 (ldb (byte 4 4) octet)) :d) ((= #b1111 (ldb (byte 4 4) octet)) :e))))) + +(defgeneric inet-address-private-p (address) + (:documentation "Returns T if ADDRESS is in a private network range. +Private IPv4 networks are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. +See http://en.wikipedia.org/wiki/Private_network for details.") + (:method ((address ipv4-address)) + (let* ((address-name (address-name address)) + (first (aref address-name 0)) + (second (aref address-name 1))) + (values (or (= first 10) + (and (= first 172) + (<= 16 second 31)) + (and (= first 192) + (= second 168))) + (inet-address-network-class address)))) + (:method ((address address)) + nil)) diff --git a/net.sockets/address-predicates.lisp b/net.sockets/address-predicates.lisp index 0242a0b..37f2278 100644 --- a/net.sockets/address-predicates.lisp +++ b/net.sockets/address-predicates.lisp @@ -130,22 +130,6 @@ address object, NIL is returned.") (not (inet-address-loopback-p address)) (not (inet-address-multicast-p address)))))) -(defgeneric inet-address-private-p (address) - (:documentation "Returns T if ADDRESS is in a private network range. -Private IPv4 networks are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. -See http://en.wikipedia.org/wiki/Private_network for details.") - (:method ((address ipv4-address)) - (let* ((address-name (address-name address)) - (first (aref address-name 0)) - (second (aref address-name 1))) - (or (= first 10) - (and (= first 172) - (<= 16 second 31)) - (and (= first 192) - (= second 168))))) - (:method ((address address)) - nil)) - (defun ipv6-ipv4-mapped-p (address) "Returns T if ADDRESS is an IPv6 address representing an IPv4 mapped address." diff --git a/net.sockets/pkgdcl.lisp b/net.sockets/pkgdcl.lisp index 7b485e9..fc4ffab 100644 --- a/net.sockets/pkgdcl.lisp +++ b/net.sockets/pkgdcl.lisp @@ -128,7 +128,6 @@ #:inet-address-type #:inet-address-unicast-p #:inet-address-unspecified-p - #:inet-address-private-p #:ipv4-address-p #:ipv6-address-p #:ipv6-admin-local-multicast-p @@ -151,6 +150,7 @@ ;; Network masks and subnets #:make-subnet-mask + #:inet-address-private-p #:inet-address-network-portion #:inet-address-host-portion #:inet-address-in-network-p -- 2.11.4.GIT