X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-bsd-sockets%2Finet.lisp;h=e6265ed45e8da3990ee6f8c38461fbdfc039e00b;hb=1b7d7105bac89ae7c5b5dae579965cd20f81c345;hp=59f95f0fd5de945083c93a4fe5cc22dd94ab0816;hpb=d4c7ab04ed10729a2cfa3321f4382d8a218ad958;p=sbcl.git
diff --git a/contrib/sb-bsd-sockets/inet.lisp b/contrib/sb-bsd-sockets/inet.lisp
index 59f95f0..e6265ed 100644
--- a/contrib/sb-bsd-sockets/inet.lisp
+++ b/contrib/sb-bsd-sockets/inet.lisp
@@ -1,21 +1,18 @@
(in-package :sb-bsd-sockets)
-#||
INET-domain sockets
-
-The TCP and UDP sockets that you know and love. Some representation issues:
-
-- These functions do not accept hostnames directly: see name resolution
-
- Internet addresses are represented by vectors of (unsigned-byte 8) - viz. #(127 0 0 1). Ports are just integers: 6010. No conversion between network- and host-order data is needed from the user of this package.
-
- socket addresses are represented by the two values for address and port, so for example, (socket-connect s #(192 168 1 1) 80)
-
-
-|#
-
;;; Our class and constructor
(eval-when (:compile-toplevel :load-toplevel :execute)
(defclass inet-socket (socket)
- ((family :initform sockint::AF-INET))))
+ ((family :initform sockint::AF-INET))
+ (:documentation "Class representing TCP and UDP sockets.
+
+Examples:
+
+ (make-instance 'inet-socket :type :stream :protocol :tcp)
+
+ (make-instance 'inet-socket :type :datagram :protocol :udp)
+")))
;;; XXX should we *...* this?
(defparameter inet-address-any (vector 0 0 0 0))
@@ -30,6 +27,13 @@
#'parse-integer
(split dotted-quads nil '(#\.))))
+(define-condition unknown-protocol ()
+ ((name :initarg :name
+ :reader unknown-protocol-name))
+ (:report (lambda (c s)
+ (format s "Protocol not found: ~a" (prin1-to-string
+ (unknown-protocol-name c))))))
+
;;; getprotobyname only works in the internet domain, which is why this
;;; is here
(defun get-protocol-by-name (name) ;exported
@@ -38,6 +42,8 @@ using getprotobyname(2) which typically looks in NIS or /etc/protocols"
;; for extra brownie points, could return canonical protocol name
;; and aliases as extra values
(let ((ent (sockint::getprotobyname name)))
+ (if (sb-alien::null-alien ent)
+ (error 'unknown-protocol :name name))
(sockint::protoent-proto ent)))
;;; our protocol provides make-sockaddr-for, size-of-sockaddr,
@@ -55,7 +61,7 @@ using getprotobyname(2) which typically looks in NIS or /etc/protocols"
;; We have no truck with such dreadful type punning. Octets to
;; octets, dust to dust.
-
+
(setf (sockint::sockaddr-in-family sockaddr) sockint::af-inet)
(setf (sb-alien:deref (sockint::sockaddr-in-port sockaddr) 0) (ldb (byte 8 8) port))
(setf (sb-alien:deref (sockint::sockaddr-in-port sockaddr) 1) (ldb (byte 8 0) port))
@@ -76,11 +82,11 @@ using getprotobyname(2) which typically looks in NIS or /etc/protocols"
"Returns address and port of SOCKADDR as multiple values"
(values
(coerce (loop for i from 0 below 4
- collect (sb-alien:deref (sockint::sockaddr-in-addr sockaddr) i))
- '(vector (unsigned-byte 8) 4))
+ collect (sb-alien:deref (sockint::sockaddr-in-addr sockaddr) i))
+ '(vector (unsigned-byte 8) 4))
(+ (* 256 (sb-alien:deref (sockint::sockaddr-in-port sockaddr) 0))
(sb-alien:deref (sockint::sockaddr-in-port sockaddr) 1))))
-
+
(defun make-inet-socket (type protocol)
"Make an INET socket. Deprecated in favour of make-instance"
(make-instance 'inet-socket :type type :protocol protocol))