guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multicast? [patch]


From: Greg Troxel
Subject: Re: multicast? [patch]
Date: 30 Nov 2004 16:03:32 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

  I have created a socket, bound it to a port and connected it to a
  mcast destination address and port.  Sending works fine.  Looking in
  libguile/socket.c, I can't find support for joining multicast groups.
  This is via setsockopt with struct mreq.

--- libguile/socket.c.orig      2004-08-26 22:16:38.000000000 -0400
+++ libguile/socket.c
@@ -563,12 +563,18 @@ SCM_DEFINE (scm_setsockopt, "setsockopt"
 {
   int fd;
   int optlen = -1;
+
   /* size of optval is the largest supported option.  */
+  union bigopt {
+    size_t a;
 #ifdef HAVE_STRUCT_LINGER
-  char optval[sizeof (struct linger)];
-#else
-  char optval[sizeof (size_t)];
+    struct linger l;
 #endif
+    struct ip_mreq m;
+  };
+  /* XXX: why not just use the union? */
+  char optval[sizeof (union bigopt) + 20];
+
   int ilevel, ioptname;
 
   sock = SCM_COERCE_OUTPORT (sock);
@@ -630,6 +636,21 @@ SCM_DEFINE (scm_setsockopt, "setsockopt"
            (*(size_t *) optval) = (size_t) lv;
          }
     }
+
+  if (ilevel == IPPROTO_IP &&
+      (ioptname == IP_ADD_MEMBERSHIP || ioptname == IP_DROP_MEMBERSHIP))
+    {
+      struct ip_mreq mreq;
+
+      /* Fourth argument must be a pair of addresses. */
+      SCM_ASSERT (SCM_CONSP (value), value, SCM_ARG4, FUNC_NAME);
+      mreq.imr_multiaddr.s_addr = htonl(SCM_NUM2ULONG (4, SCM_CAR (value)));
+      mreq.imr_interface.s_addr = htonl(SCM_NUM2ULONG (4, SCM_CDR (value)));
+
+      memcpy(optval, &mreq, sizeof(mreq));
+      optlen = sizeof(mreq);
+    }
+
   if (optlen == -1)
     {
       /* Most options take an int.  */
@@ -1393,6 +1414,11 @@ scm_init_socket ()
   scm_c_define ("MSG_DONTROUTE", SCM_MAKINUM (MSG_DONTROUTE));
 #endif
 
+#ifdef IP_ADD_MEMBERSHIP
+  scm_c_define ("IP_ADD_MEMBERSHIP", SCM_MAKINUM (IP_ADD_MEMBERSHIP));
+  scm_c_define ("IP_DROP_MEMBERSHIP", SCM_MAKINUM (IP_DROP_MEMBERSHIP));
+#endif
+
   scm_add_feature ("socket");
 
 #include "libguile/socket.x"

-- 
        Greg Troxel <address@hidden>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]