Source-Changes-HG archive

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

[src/trunk]: src/tests/net/mcast - deal with MacOS/X not having clock_*()



details:   https://anonhg.NetBSD.org/src/rev/1b434cb2491f
branches:  trunk
changeset: 803416:1b434cb2491f
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Oct 26 18:33:43 2014 +0000

description:
- deal with MacOS/X not having clock_*()
- change multicast address
- set the interface
XXX: Now the ipv6 code works on MacOS/X but does not work for us still.

diffstat:

 tests/net/mcast/t_mcast.c |  34 ++++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 4 deletions(-)

diffs (85 lines):

diff -r 9bfbde09fef9 -r 1b434cb2491f tests/net/mcast/t_mcast.c
--- a/tests/net/mcast/t_mcast.c Sun Oct 26 18:22:32 2014 +0000
+++ b/tests/net/mcast/t_mcast.c Sun Oct 26 18:33:43 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_mcast.c,v 1.8 2014/10/13 06:57:08 martin Exp $       */
+/*     $NetBSD: t_mcast.c,v 1.9 2014/10/26 18:33:43 christos Exp $     */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$NetBSD: t_mcast.c,v 1.8 2014/10/13 06:57:08 martin Exp $");
+__RCSID("$NetBSD: t_mcast.c,v 1.9 2014/10/26 18:33:43 christos Exp $");
 #else
 extern const char *__progname;
 #define getprogname() __progname
@@ -39,6 +39,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/wait.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 
 #include <assert.h>
@@ -77,7 +78,7 @@
 #define PORT_V4 "6666"
 #define HOST_V4 "239.1.1.1"
 #define PORT_V6 "6666"
-#define HOST_V6 "FF05:0:0:0:0:0:0:1"
+#define HOST_V6 "FF02:0:0:0:0:0:0:1"
 
 struct message {
        size_t seq;
@@ -91,6 +92,7 @@
        struct ipv6_mreq m6;
        struct sockaddr_in *s4;
        struct sockaddr_in6 *s6;
+       unsigned int ifc;
        
        switch (ai->ai_family) {
        case AF_INET:
@@ -121,7 +123,23 @@
                }
                assert(sizeof(*s6) == ai->ai_addrlen);
                memset(&m6, 0, sizeof(m6));
-               m6.ipv6mr_interface = 0;
+#if 0
+               ifc = 1;
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
+                   &ifc, sizeof(ifc))) == -1)
+                       return -1;
+               ifc = 224;
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
+                   &ifc, sizeof(ifc)) == -1)
+                       return -1;
+#endif
+#if 1
+               ifc = 1;
+               if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &ifc,
+                   sizeof(ifc)) == -1)
+                       return -1;
+#endif
+               m6.ipv6mr_interface = ifc;
                m6.ipv6mr_multiaddr = s6->sin6_addr;
                return setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP,
                    &m6, sizeof(m6));
@@ -223,8 +241,16 @@
 
        s = getsocket(host, port, conn ? connect : connector, &slen, bug);
        for (msg.seq = 0; msg.seq < n; msg.seq++) {
+#ifdef CLOCK_MONOTONIC
                if (clock_gettime(CLOCK_MONOTONIC, &msg.ts) == -1)
                        ERRX(EXIT_FAILURE, "clock (%s)", strerror(errno));
+#else
+               struct timeval tv;
+               if (gettimeofday(&tv, NULL) == -1)
+                       ERRX(EXIT_FAILURE, "clock (%s)", strerror(errno));
+               msg.ts.tv_sec = tv.tv_sec;
+               msg.ts.tv_nsec = tv.tv_usec * 1000;
+#endif
                if (debug)
                        show("sending", &msg);
                l = conn ? send(s, &msg, sizeof(msg), 0) :



Home | Main Index | Thread Index | Old Index