Enabled initialization of IP addresses from another host address.
authorFredrik Tolf <fredrik@dolda2000.com>
Thu, 13 May 2010 02:45:40 +0000 (04:45 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Thu, 13 May 2010 02:45:40 +0000 (04:45 +0200)
common-net.lisp

index 00ae20d..fadf080 100644 (file)
        (error "Too few octets in IPv4 address")
        buf)))
 
-(defmethod initialize-instance :after ((instance ipv4-address) &key host-bytes host-string)
+(defmethod initialize-instance :after ((instance ipv4-address) &key host-bytes host-string host-address)
   (let ((octets (or host-bytes
+                   (when host-address
+                     (check-type host-address ipv4-address)
+                     (slot-value host-address 'host-bytes))
                    (when host-string (parse-dotted-quad host-string))
                    '(0 0 0 0))))
     (assert (and (typep octets 'sequence)
            (aref host-bytes 2)
            (aref host-bytes 3))))
 
-(export '(ipv4-address make-ipv4-address parse-ipv4-address))
+(defparameter *ipv4-localhost* (make-instance 'ipv4-host-address :host-bytes '(127 0 0 1)))
+
+(export '(ipv4-address ipv4-host-address make-ipv4-address parse-ipv4-address *ipv4-localhost*))
 
 ;;; IPv6 addresses
 
   (declare (ignore string))
   (error "IPv6 parsing not implemented yet"))
 
-(defmethod initialize-instance :after ((instance ipv6-address) &key host-bytes host-string)
+(defmethod initialize-instance :after ((instance ipv6-address) &key host-bytes host-string host-address)
   (let ((octets (or host-bytes
+                   (when host-address
+                     (check-type host-address ipv6-address)
+                     (slot-value host-address 'host-bytes))
                    (when host-string (parse-ipv6-string host-string))
                    '(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))))
     (assert (and (typep octets 'sequence)
 (defun parse-ipv6-host-address (string)
   (make-instance 'ipv6-host-address :host-string string))
 
-(export '(ipv6-address parse-ipv6-address))
+(defparameter *ipv6-localhost* (make-instance 'ipv6-host-address :host-bytes '(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1)))
+
+(export '(ipv6-address ipv6-host-address parse-ipv6-address *ipv6-localhost*))
 
 ;;; TCP code