;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 123.133
;;; Reason:
;;;  By analogy with (chaos:address-parse), (ip:parse-internet-address) now returns an
;;;  additional value -- the host object corresponding to the address.
;;; Written 2-Dec-87 14:53:13 by pld at site Gigamos Cambridge
;;; while running on Jack Flanders from band 2
;;; with Experimental System 123.132, Experimental Local-File 73.3, Experimental FILE-Server 22.1, Experimental Unix-Interface 11.0, Experimental Tape 18.0, Experimental KERMIT 34.0, Experimental ZMail 71.0, Experimental Lambda-Diag 15.0, Experimental Site Data Editor 8.4, microcode 1754, SDU Boot Tape 3.12, SDU ROM 8.




; From modified file DJ: L.NETWORK.IP-TCP.KERNEL; IP.LISP#277 at 2-Dec-87 14:55:13
#10R INTERNET#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "INTERNET")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; IP-TCP; KERNEL; IP  "

(defun parse-internet-address (address &aux host name)
  (declare (values address host-object))
  (labels ((glom-address (string)
	     (let* ((first (string-search-char #\. string))
		    (second (and first (string-search-char #\. string (1+ first))))
		    (third (and second (string-search-char #\. string (1+ second)))))
	       (if first			;If at least one dot, must be three of them...
		   (when (and second third)
		     (let ((one (parse-integer string :start 0 :end first :junk-allowed t))
			   (two (parse-integer string :start (1+ first) :end second :junk-allowed t))
			   (three (parse-integer string :start (1+ second) :end third :junk-allowed t))
			   (four (parse-integer string :start (1+ third) :junk-allowed t)))
		       (when (and one (not (minusp one)) (< one 256)
				  two (not (minusp two)) (< two 256)
				  three (not (minusp three)) (< three 256)
				  four (not (minusp four)) (< four 256))
			 (dpb one (byte 8 24)
			      (dpb two (byte 8 16)
				   (dpb three (byte 8 8)
					four))))))
		 (parse-integer string :junk-allowed t)))))	;If no dots, address given as an integer
    (let ((parsed-address (cond ((null address) nil)
				((numberp address) address)
				((or (and (symbolp address)
					  (setq name (symbol-name address)))
				     (and (stringp address)
					  (setq name address)))
				 (setq host (si:parse-host name t nil))
				 (if host
				     (send host :network-address :internet t)
				   (glom-address name)))
				((typep address 'si:host)
				 (setq host address)
				 (send address :network-address :internet t))
				(t nil))))
      (when parsed-address
	(values parsed-address (or host (si:get-host-from-address parsed-address :internet)))))))

))
