anchor.diff:  						(when (or (= result SOCKET_ERROR) (= result 0))
   							(return)))))
   			(closesocket descriptor)
  -			(setf (socket-descriptor s) nil))))
  +			(setf (socket-descriptor s) nil) t)))
  +
  +(defmethod close-socket ((s local-socket))
  +    (let ((soc (socket-descriptor s)))
  +        (when soc (if (eq (socket-type s) 'sock_stream) (call-next-method)
  +                             (let () (closesocket soc) (setf (socket-descriptor s) nil) t)))))
  +
  +;;; Methods to read and write Datagrams
  +
  +(defvar *datagram-size* 1024)
  +
  +(defmethod receive-from ((socket local-socket) &optional bytep)
  +    (unless (eq (socket-type socket) 'sock_dgram) (error "RECEIVE-FROM is used for Datagram Sockets only."))
  +    (let* ((data (malloc *datagram-size*)) (from (malloc *addr-size*))
  +             (addr-size (let ((addr-size (malloc 4))) (setf (cref (int *) addr-size *) *addr-size*) addr-size))
  +             (n (with-socket-error-check () (recvfrom (socket-descriptor socket) data *datagram-size* 0 from addr-size))))
  +        (and (not bytep) (< n *datagram-size*) (setf (cref (byte *) data n) 0))
  +        (values (if bytep (c-bytes-to-lisp-bytes data n) (c-string-to-lisp-string data)) (c-to-addr from))))
  +
  +(defmethod send-to :before ((socket server-socket) byte-vector-or-string &key to)
  +    (declare (ignore byte-vector-or-string))
  +    (unless to (error "The :TO key must be specified for Server Sockets.")))
  +
  +(defmethod send-to ((socket local-socket) byte-vector-or-string &key to)
  +    (unless (eq (socket-type socket) 'sock_dgram) (error "SEND-TO is used for Datagram Sockets only."))
  +    (with-socket-error-check ()
  +        (sendto (socket-descriptor socket)
  +                     (if (eq (array-element-type byte-vector-or-string) 'character)
  +                         (lisp-string-to-c-string byte-vector-or-string)
  +                         (lisp-bytes-to-c-bytes byte-vector-or-string))
  +                     (length byte-vector-or-string) 0 (if to (addr-to-c to) null) *addr-size*)))
  +
  +;;;
   
   (defgeneric do-ffi-write-socket (s buffer length)
   	(:documentation
  
positive.code: ;;; In a protocol-independent approach, it is more convenient to use the ADDR instead of the ipaddr proper.
  ;;; We define the functions host-to-ipaddr, ipaddr-to-dotted and ipaddr-to-dotted with this in mind.
  
  (defun host-to-ipaddr (dotted-or-name &key port (ipv6 *ipv6*)) "Return the ipaddr (addr) given a host name or dotted IP address.
  Port: symbol, string or integer. IPv6: nil, :only or t"
      (get-addr-info dotted-or-name :port (or port 0) :host-is-name :unspec :ipv6 ipv6 :errorp t))
  
  (defun ipaddr-to-name (addr) "Given an ipaddr (addr), lookup the host name"
      (get-name-info addr :errorp t))
  
  (defun ipaddr-to-dotted (addr) "Given ipaddr (addr), return the dotted name."
      (or (getf addr :dotted) (get-name-info addr :dottedp t :errorp t)))
  
  (defclass base-socket ()
  
negative.code: 				,@body)
  			(stop-sockets))))
  
  (defvar *ipv6* nil "Controls whether IPv6 addresses will be looked up by default during name resolution. Valid values: nil, :only or t.")
  
  (defun ipv6-installed-p () (get-addr-info "::" :ipv6 :only))
  
  