anchor.diff:    (let ((code (or ecode *errno*)))
       (error 'posix-error :code code)))
   
  +(defun with-funcall-else-socket-error (call)
  +  (if (= call +socket-error+)
  +      (get-last-error)
  +      nil))
   ;; --------------------------------------
   
   (defctype canid_t :uint32) 
  
positive.code: (defun socket-sendto (fd buffer addr &key (start 0) end)
    "Send data to the address on the socket.
  FD ::= socket.
  BUFFER ::= octet vector or foreign pointer.
  ADDR ::= destination address, either a SOCKADDR-IN or SOCKADDR-IN6 structure.
  START ::= buffer start index.
  END ::= buffer end index.
  
  Returns the number of octets actually sent, which can be less than the number requested."
    (declare (type (or (vector (unsigned-byte 8)) foreign-pointer can-packet) buffer))
    (etypecase buffer
      ((vector (unsigned-byte 8))
       (let ((count (- (or end (length buffer)) start))
  	   (alen 0))
         (with-foreign-objects ((p :uint8 count)
  			      (a :uint8 +sockaddr-storage+))
  	 (dotimes (i count)
  	   (setf (mem-aref p :uint8 i)
  		 (aref buffer (+ start i))))
  	 (etypecase addr
  	   (sockaddr-in
  	    (setf (mem-aref a '(:struct sockaddr-in)) addr
  		  alen (foreign-type-size '(:struct sockaddr-in))))
  	   (sockaddr-in6
  	    (setf (mem-aref a '(:struct sockaddr-in6)) addr
  		  alen (foreign-type-size '(:struct sockaddr-in6))))
  	   (string 
  	    (setf (mem-aref a '(:struct sockaddr-un)) addr
  		  alen (foreign-type-size '(:struct sockaddr-un)))))
  	 (let ((sts (%sendto fd
  			     p
  			     count
  			     0
  			     a
  			     alen)))
  	   (if (= sts +socket-error+)
  	       (get-last-error)
  	       sts)))))
      (foreign-pointer
       (let ((alen 0)
  	   (count (- (or end (error "Must provide end when passing pointer"))
  		     start)))
         (with-foreign-object (a :uint8 +sockaddr-storage+)
  	 (etypecase addr
  	   (sockaddr-in (setf (mem-aref a '(:struct sockaddr-in)) addr
  			      alen (foreign-type-size '(:struct sockaddr-in))))
  	   (sockaddr-in6
  	    (setf (mem-aref a '(:struct sockaddr-in6)) addr
  		  alen (foreign-type-size '(:struct sockaddr-in6)))))
  	 (let ((sts (%sendto fd 
  			     (inc-pointer buffer start)
  			     count
  			     0
  			     a
  			     alen)))
  	   (if (= sts +socket-error+)
  	       (get-last-error)
  	       sts)))))
  
      (can-packet
       ;; todo: avoid copy-paste
       (let* ((id (can-packet-id buffer))
  	    (payload (can-packet-data buffer))
  	    (payload-size (length payload))
  	    (n (can-interface-name addr))
  	    (n-size (length n)))       
         (with-foreign-object (ifr '(:struct ifreq))
  	 (with-foreign-object (sockaddr '(:struct sockaddr-can))
  	   (with-foreign-object (frame '(:struct can-frame))
  	     (lisp-string-to-foreign n (foreign-slot-value ifr '(:struct ifreq) 'name) (1+ n-size))
  	     (%ioctl fd +siocgifindex+ ifr)
  	     (setf (foreign-slot-value sockaddr '(:struct sockaddr-can) 'can_family) +pf-can+)
  	     (let* ((ifrdata (foreign-slot-value ifr '(:struct ifreq) 'data))
  		    (index (foreign-slot-value ifrdata '(:union ifreq-data) 'ifindex)))      
  	       (setf (foreign-slot-value sockaddr '(:struct sockaddr-can) 'can_ifindex) index))
  	     (setf (foreign-slot-value frame '(:struct can-frame) 'can_id) id)
  	     (setf (foreign-slot-value frame '(:struct can-frame) 'can_dlc) payload-size)
  	     (let ((ptr (foreign-slot-pointer frame '(:struct can-frame) 'data)))	       
  	       (lisp-array-to-foreign payload ptr `(:array :uint8 ,payload-size))
  	       ;; todo: handle +socket-error+	       
  	       (%sendto
  		fd
  		frame
  		(foreign-type-size '(:struct can-frame))
  		0
  		sockaddr
  		(foreign-type-size '(:struct can-frame)))))))))))
  
  ;; ssize_t recv(int sockfd, void *buf, size_t len, int flags);
  (defcfun (%recv "recv") ssize-t
  
negative.code: 	    (setq sock-addr-pointer p
  		  sock-addr-len len))))	 
  
      (with-funcall-else-socket-error
  	(%bind fd sock-addr-pointer sock-addr-len))))
        
  
   ;; int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
  (defcfun (%connect "connect") :int32
  