From: Dave L. <d.j...@gm...> - 2006-04-12 16:50:15
|
Just as I was about to send a patch for socket-sendto, I find Juho Snellman (and others) have beaten me to it! Before it happens again, here's a patch to add support for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP socket options. Regards, Dave cvs diff: Diffing . Index: constants.lisp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/sbcl/sbcl/contrib/sb-bsd-sockets/constants.lisp,v retrieving revision 1.12 diff -u -r1.12 constants.lisp --- constants.lisp=0914 Jul 2005 16:30:07 -0000=091.12 +++ constants.lisp=0912 Apr 2006 16:42:53 -0000 @@ -29,6 +29,7 @@ (:integer sock-seqpacket "SOCK_SEQPACKET" "Sequenced, reliable, connection-based, datagrams of fixed maximum length.") + (:integer sol-ip "SOL_IP") (:integer sol-socket "SOL_SOCKET") ;; some of these may be linux-specific @@ -61,6 +62,14 @@ #+linux (:integer so-bindtodevice "SO_BINDTODEVICE") (:integer ifnamsiz "IFNAMSIZ") + (:integer ip-add-membership "IP_ADD_MEMBERSHIP") + (:integer ip-drop-membership "IP_DROP_MEMBERSHIP") + + (:structure ip-mreq + ("struct ip_mreq" + ((array (unsigned 8)) multiaddr "struct in_addr" "imr_multia= ddr") + ((array (unsigned 8)) interface "struct in_addr" "imr_interface"))) + (:integer EADDRINUSE "EADDRINUSE") (:integer EAGAIN "EAGAIN") (:integer EBADF "EBADF") Index: inet.lisp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/sbcl/sbcl/contrib/sb-bsd-sockets/inet.lisp,v retrieving revision 1.9 diff -u -r1.9 inet.lisp --- inet.lisp=0926 Jan 2006 23:29:07 -0000=091.9 +++ inet.lisp=0912 Apr 2006 16:42:53 -0000 @@ -90,3 +90,26 @@ (defun make-inet-socket (type protocol) "Make an INET socket. Deprecated in favour of make-instance" (make-instance 'inet-socket :type type :protocol protocol)) + +(defun make-ip-mreq (multiaddr interface) + "Create an ip_mreq structure from the inet addresses of the +multicast group and interface." + (let ((ip-mreq (sockint::allocate-ip-mreq))) + (setf multiaddr (coerce multiaddr '(simple-array (unsigned-byte 8) (4)= ))) + (setf interface (coerce interface '(simple-array (unsigned-byte 8) (4)= ))) + + (setf (sb-alien:deref (sockint::ip-mreq-multiaddr ip-mreq) 0) (elt multiaddr 0)) + (setf (sb-alien:deref (sockint::ip-mreq-multiaddr ip-mreq) 1) (elt multiaddr 1)) + (setf (sb-alien:deref (sockint::ip-mreq-multiaddr ip-mreq) 2) (elt multiaddr 2)) + (setf (sb-alien:deref (sockint::ip-mreq-multiaddr ip-mreq) 3) (elt multiaddr 3)) + + (setf (sb-alien:deref (sockint::ip-mreq-interface ip-mreq) 0) (elt interface 0)) + (setf (sb-alien:deref (sockint::ip-mreq-interface ip-mreq) 1) (elt interface 1)) + (setf (sb-alien:deref (sockint::ip-mreq-interface ip-mreq) 2) (elt interface 2)) + (setf (sb-alien:deref (sockint::ip-mreq-interface ip-mreq) 3) (elt interface 3)) + ip-mreq)) + +(defmacro with-ip-mreq-for ((ip-mreq-name multiaddr interface) &body body) + `(let ((,ip-mreq-name (make-ip-mreq ,multiaddr ,interface))) + (unwind-protect (progn ,@body) + (sockint::free-ip-mreq ,ip-mreq-name)))) Index: sb-bsd-sockets.asd =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/sbcl/sbcl/contrib/sb-bsd-sockets/sb-bsd-sockets.asd,v retrieving revision 1.23 diff -u -r1.23 sb-bsd-sockets.asd --- sb-bsd-sockets.asd=097 Mar 2006 12:04:26 -0000=091.23 +++ sb-bsd-sockets.asd=0912 Apr 2006 16:42:53 -0000 @@ -19,7 +19,7 @@ =09=09 (:file "sockets" =09=09=09:depends-on ("constants")) =09=09 -=09=09 (:file "sockopt" :depends-on ("sockets")) +=09=09 (:file "sockopt" :depends-on ("inet" "sockets")) =09=09 (:file "inet" :depends-on ("sockets" "split" "constants" )) =09=09 (:file "local" :depends-on ("sockets" "split" "constants" )) =09=09 (:file "name-service" :depends-on ("sockets" "constants")) Index: sockopt.lisp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/sbcl/sbcl/contrib/sb-bsd-sockets/sockopt.lisp,v retrieving revision 1.9 diff -u -r1.9 sockopt.lisp --- sockopt.lisp=0914 Jul 2005 16:30:08 -0000=091.9 +++ sockopt.lisp=0912 Apr 2006 16:42:53 -0000 @@ -152,6 +152,28 @@ ;;; other kinds of socket option +;;; Support for the IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP options +;;; for multicast. +(export '(sockopt-ip-add-membership sockopt-ip-drop-membership)) + +(defun (setf sockopt-ip-add-membership) (addresses socket) + "ADDRESSES is a list containing the multicast group and interface addres= s." + (destructuring-bind (multiaddr interface) addresses + (with-ip-mreq-for (ip-mreq multiaddr interface) + (when (=3D -1 (sockint::setsockopt (socket-file-descriptor socket) + sockint::sol-ip sockint::ip-add-membership + ip-mreq sockint::size-of-ip-mreq)) + (socket-error "setsockopt"))))) + +(defun (setf sockopt-ip-drop-membership) (addresses socket) + "ADDRESSES is a list containing the multicast group and interface addres= s." + (destructuring-bind (multiaddr interface) addresses + (with-ip-mreq-for (ip-mreq multiaddr interface) + (when (=3D -1 (sockint::setsockopt (socket-file-descriptor socket) sockint::sol-ip + sockint::ip-drop-membership + ip-mreq sockint::size-of-ip-mreq)) + (socket-error "setsockopt"))))) + ;;; so_peercred takes a ucre structure ;;; so_linger struct linger { ; int l_onoff; /* linger active */ cvs diff: Diffing alien |