]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Fixed a couple of bugs in handling of multicast sockets.
authorMartin Mares <mj@ucw.cz>
Mon, 12 Apr 1999 14:57:46 +0000 (14:57 +0000)
committerMartin Mares <mj@ucw.cz>
Mon, 12 Apr 1999 14:57:46 +0000 (14:57 +0000)
See comments in lib/socket.h for a detailed guide on how to use them.

TODO
lib/socket.h
sysdep/unix/io.c

diff --git a/TODO b/TODO
index 52629ea5f57ef5f08cc670f1031ff9e9dd16c58f..e39678e050197415c89ef7ca96677ee240a79a0e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -37,6 +37,7 @@ Cleanup
 - check if all protocols set proper packet priorities and TTL's.
 - replace all NUM, IPA and expr tokens by constant filter expressions
 - try compiling with -Wunused
+- does everybody test return value of sk_open?
 
 Various ideas
 ~~~~~~~~~~~~~
index 2c5ab4f8f587bd6d1635ac5887b52243a0a73c09..bb9c1c3d065fdc3f3078f9ecdcbab1a9ad6cd8f8 100644 (file)
@@ -55,8 +55,16 @@ void sk_dump_all(void);
 #define SK_TCP         2
 #define SK_UDP         3          /* ?  ?  -  -  -  ?   ?      */
 #define SK_UDP_MC       4          /* ?  ?  *  *  *  *   -     */
-#define SK_IP          5          /* ?  ?  -  *  -  ?   ?      */
-#define SK_IP_MC       6          /* ?  ?  *  *  *  *   -      */
+#define SK_IP          5          /* ?  -  -  *  -  ?   ?      */
+#define SK_IP_MC       6          /* ?  -  *  *  *  *   -      */
 #define SK_MAGIC       7          /* Internal use by sysdep code */
 
+/*
+ *  Multicast sockets are slightly different from the other ones:
+ *  If you want to send packets only, just set the destination
+ *  address to the corresponding multicast group and iface to
+ *  the interface to be used. If you also want receiving, set
+ *  source address to the same multicast group as well.
+ */
+
 #endif
index 9a388442dc4250861b2f75d350c8af71e0ab5fa2..69f8a5c7b727af54b64e77557b1a66d9ae369513 100644 (file)
@@ -408,21 +408,18 @@ sk_open(sock *s)
     case SK_IP_MC:
       {
 #ifdef HAVE_IP_MREQN
+       /* FIXME: Define HAVE_IP_MREQN somewhere :) */
        struct ip_mreqn mreq;
 #define mreq_add mreq
+       ASSERT(s->iface);
        mreq.imr_ifindex = s->iface->index;
-       if (has_src)
-         set_inaddr(&mreq.imr_address, s->saddr);
-       else
-         set_inaddr(&mreq.imr_address, s->iface->ifa->ip);
+       set_inaddr(&mreq.imr_address, s->iface->ip);
 #else
        struct in_addr mreq;
        struct ip_mreq mreq_add;
-       if (has_src)
-         set_inaddr(&mreq, s->saddr);
-       else
-         set_inaddr(&mreq, s->iface->ip);
-       memcpy(&mreq_add.imr_interface, &mreq, sizeof(struct in_addr));
+       ASSERT(s->iface);
+       set_inaddr(&mreq, s->iface->ip);
+       mreq_add.imr_interface = mreq;
 #endif
        set_inaddr(&mreq_add.imr_multiaddr, s->daddr);
        if (has_dest)
@@ -439,9 +436,11 @@ sk_open(sock *s)
 #endif
                setsockopt(fd, SOL_IP, IP_MULTICAST_LOOP, &zero, sizeof(zero)) < 0)
              ERR("IP_MULTICAST_LOOP");
+           /* This defines where should we send _outgoing_ multicasts */
            if (setsockopt(fd, SOL_IP, IP_MULTICAST_IF, &mreq, sizeof(mreq)) < 0)
              ERR("IP_MULTICAST_IF");
        }
+      /* And this one sets interface for _receiving_ multicasts from */
       if (has_src && setsockopt(fd, SOL_IP, IP_ADD_MEMBERSHIP, &mreq_add, sizeof(mreq_add)) < 0)
        ERR("IP_ADD_MEMBERSHIP");
       break;