anchor.diff:  	      (+ position 2 (aref buffer (1+ position))))))
   
   (defun decode-all-options (buffer)
  -  ())
  +  (loop with pos = 240
  +     with padcount = 0
  +     while (and (< padcount 4) (< pos (length buffer)))
  +     appending (multiple-value-bind (type value newpos) (decode-dhcp-option buffer pos)
  +		 (setf pos newpos)
  +		 (cond ((zerop type) (incf padcount) (list))
  +		       (t (setf padcount 0) (list (cons type value)))))))
   
  -(defun make-dhcp-option (type &key (size 0) value)
  -  (if (zerop type)
  -      (make-array 1 :element-type '(unsigned-byte 8) :initial-element 0)
  -      (let ((option (make-array (+ 2 size) :element-type '(unsigned-byte 8) :initial-element 0)))
  -	(setf (aref option 0) type
  -	      (aref option 1) size)
  -	(if (= 1 size)
  -	    (setf (aref option 2) value) ;assume scalar
  -	    (setf (subseq option 2) value))
  -	option)))
  +(defun make-dhcp-option (type value)
  +  (let* ((size (cond ((zerop type) -1)
  +		     ((arrayp value) (length value))
  +		     ((typep value '(unsigned-byte 8)) 1)
  +		     (t (cerror "Invalid DHCP option format ~A ~A" type value))))
  +	 (option (make-array (+ 2 size) :element-type '(unsigned-byte 8) :initial-element 0)))
  +    (when (zerop size)
  +      (return option))
  +    (setf (aref option 0) type
  +	  (aref option 1) size)
  +    (if (= 1 size)
  +	(setf (aref option 2) value)	;assume scalar
  +	(setf (subseq option 2) value))
  +    option))
   
   (defun send-broadcast-dhcp-packet (sequence interface)
     (let* ((header (make-array 8 :element-type '(unsigned-byte 8)))
  
positive.code: (defconstant +ipv4-broadcast-local-network+ (mezzano.network.ip:make-ipv4-address #xffffffff))
  (defconstant +dhcp-client-port+ 68)
  (defconstant +dhcp-server-port+ 67)
  
  (defun build-dhcp-packet (&key mac-address options (siaddr 0))
    (assert (typep mac-address '(simple-array (unsigned-byte 8) (6))))
  
negative.code: 	 (packet (build-dhcp-packet :mac-address (mezzano.network.ethernet:ethernet-mac iface) :options options :siaddr siaddr)))
      (send-broadcast-dhcp-packet packet iface)))
  
  (defun get-option (alist option)
    (cdr (find option alist :key #'car)))
  
  (defun acquire-lease ()
    (let ((connection (make-instance 'mezzano.network.udp::udp4-connection
  				   :remote-address +ipv4-broadcast-source+ ;;not necessary, just to avoid the stack down choking
  				   :remote-port +dhcp-server-port+
  				   :local-address +ipv4-broadcast-local-network+
  				   :local-port +dhcp-client-port+)))
      (mezzano.supervisor:with-mutex (mezzano.network.udp::*udp-connection-lock*)
        (push connection mezzano.network.udp::*udp-connections*))
      (dhcp-send (list (make-dhcp-option 53 :size 1 :value 1)
  		     (make-dhcp-option 55 :size 5 :value #(1 4 3 15 6))))
      (unwind-protect
  	 (let* ((offer (sys.net:receive connection 4))
  		(siaddr (ub32ref/be offer 20))
  		(yiaddr (ub32ref/be offer 16))
  		(oaddr (make-array 4 :element-type '(unsigned-byte 8)))
  		(options (decode-all-options offer))
  		(dhcpserver (get-option options +opt-dhcp-server+)))
  	   (setf (ub32ref/be oaddr 0) yiaddr)
  	   (if (zerop yiaddr)
  	       nil
  	       (progn
  		 (dhcp-send (list (make-dhcp-option +opt-dhcp-message-type+ +dhcp-request+)
  				  (make-dhcp-option +opt-ip-address+ oaddr)
  				  (make-dhcp-option +opt-dhcp-server+ dhcpserver))
  			    :siaddr siaddr)
  		 (let* ((ack (sys.net:receive connection 4))
  			(ack-options (decode-all-options ack))
  			(confirmation (get-option ack-options +opt-dhcp-message-type+)))
  		   (if (= confirmation +dhcp-ack+)
  		       (values yiaddr (get-option options +opt-netmask+) (get-option options +opt-router+)
  			       (get-option options +opt-dns-servers+) (get-option options +opt-dhcp-server+)
  			       (get-option options +opt-ntp-server+))
  		       nil)))))
        (sys.net:disconnect connection))))
  