From 3798c09b765ec1344da5efd7b157e608fd0af2d8 Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Mon, 18 Feb 2008 09:54:47 +0100 Subject: [PATCH] Add INET-ADDRESS-NETWORK-CLASS. Signed-off-by: Stelian Ionescu --- net.sockets/address-arithmetic.lisp | 11 +++++++++++ net.sockets/pkgdcl.lisp | 1 + 2 files changed, 12 insertions(+) diff --git a/net.sockets/address-arithmetic.lisp b/net.sockets/address-arithmetic.lisp index f81f23f..818e7e2 100644 --- a/net.sockets/address-arithmetic.lisp +++ b/net.sockets/address-arithmetic.lisp @@ -85,3 +85,14 @@ subnet specified by NETWORK and MASK.") (subnet (address-network-portion network mask))) (and (address= address1-network subnet) (address= address2-network subnet))))) + +(defgeneric inet-address-network-class (address) + (:documentation "Return the network class of ADDRESS: one of :A, :B, :C, :D OR :E .") + (:method ((address ipv4-address)) + (let ((octet (aref (address-name address) 0))) + (cond + ((= #b0000 (ldb (byte 1 7) octet)) :a) + ((= #b0010 (ldb (byte 2 6) octet)) :b) + ((= #b0110 (ldb (byte 3 5) octet)) :c) + ((= #b1110 (ldb (byte 4 4) octet)) :d) + ((= #b1111 (ldb (byte 4 4) octet)) :e))))) diff --git a/net.sockets/pkgdcl.lisp b/net.sockets/pkgdcl.lisp index 088f6cf..7b485e9 100644 --- a/net.sockets/pkgdcl.lisp +++ b/net.sockets/pkgdcl.lisp @@ -155,6 +155,7 @@ #:inet-address-host-portion #:inet-address-in-network-p #:inet-addresses-in-same-network-p + #:inet-address-network-class ;; Hostname, Service, and Protocol Lookups #:ensure-hostname -- 2.11.4.GIT