windows, i love you
[ardour.git] / libs / midi++2 / ipmidi_port.cc
index cf4e6b243d644ddf9fcc987b25ba429929b18657..440374eadea1630c12b31fd9ca1644456ad00d48 100644 (file)
@@ -194,7 +194,7 @@ IPMIDIPort::open_sockets (int base_port, const string& ifname)
 #endif
 
        struct ip_mreq mreq;
-       mreq.imr_multiaddr.s_addr = ::inet_addr("225.0.0.37");
+       mreq.imr_multiaddr.s_addr = ::inet_addr("225.0.0.37"); /* ipMIDI group multicast address */
        mreq.imr_interface.s_addr = if_addr_in.s_addr;
        if(::setsockopt (sockin, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof(mreq)) < 0) {
                ::perror("setsockopt(IP_ADD_MEMBERSHIP)");
@@ -212,6 +212,7 @@ IPMIDIPort::open_sockets (int base_port, const string& ifname)
        }
 
        // Will Hall, Oct 2007
+#ifndef PLATFORM_WINDOWS
        if (!ifname.empty()) {
                struct in_addr if_addr_out;
                if (!get_address(sockout, &if_addr_out, ifname)) {
@@ -223,19 +224,40 @@ IPMIDIPort::open_sockets (int base_port, const string& ifname)
                        return false;
                }
        }
+#endif
 
        ::memset(&addrout, 0, sizeof(struct sockaddr_in));
        addrout.sin_family = AF_INET;
        addrout.sin_addr.s_addr = ::inet_addr("225.0.0.37");
        addrout.sin_port = htons (base_port);
 
+#ifndef PLATFORM_WINDOWS
+       int loop;
+       socklen_t size;
+#else
+       u_char loop;
+       int size;
+#endif
+
+       if (::getsockopt (sockin, IPPROTO_IP, IP_MULTICAST_LOOP, (void *) &loop, &size)) {
+               ::perror ("getsockopt(IP_MULTICAST_LOOP)");
+       } else {
+               cout << "********* 1. multicast loopback: " << loop << " size was " << size << endl;
+       }
+
        // Turn off loopback...
-       int loop = 0;
-       if (::setsockopt(sockout, IPPROTO_IP, IP_MULTICAST_LOOP, (char *) &loop, sizeof (loop)) < 0) {
+       loop = 0;
+       if (::setsockopt(sockout, IPPROTO_IP, IP_MULTICAST_LOOP, (void *) &loop, sizeof (loop)) < 0) {
                ::perror("setsockopt(IP_MULTICAST_LOOP)");
                return false;
        }
 
+       if (::getsockopt (sockin, IPPROTO_IP, IP_MULTICAST_LOOP, (void *) &loop, &size)) {
+               ::perror ("getsockopt(IP_MULTICAST_LOOP)");
+       } else {
+               cout << "********* 2. multicast loopback: " << loop << " size was " << size << endl;
+       }
+
 #ifndef PLATFORM_WINDOWS
 
        if (fcntl (sockin, F_SETFL, O_NONBLOCK)) {
@@ -249,14 +271,14 @@ IPMIDIPort::open_sockets (int base_port, const string& ifname)
        }
 
 #else
-       // If iMode!=0, non-blocking mode is enabled.
+       // If imode !=0, non-blocking mode is enabled.
        u_long mode=1;
-       if (ioctlsocket(sockin,FIONBIO,&imode)) {
+       if (ioctlsocket(sockin,FIONBIO,&mode)) {
                error << "cannot set non-blocking mode for IP MIDI input socket (" << ::strerror (errno) << ')' << endmsg;
                return false;
        }
-       imode = 1;
-       if (ioctlsocket(sockout,FIONBIO,&iMode)) {
+       mode = 1; /* just in case it was modified in the previous call */
+       if (ioctlsocket(sockout,FIONBIO,&mode)) {
                error << "cannot set non-blocking mode for IP MIDI output socket (" << ::strerror (errno) << ')' << endmsg;
                return false;
        }
@@ -299,6 +321,10 @@ IPMIDIPort::parse (framecnt_t timestamp)
        socklen_t slen = sizeof(sender);
        int r = ::recvfrom (sockin, (char *) buf, sizeof(buf), 0, (struct sockaddr *) &sender, &slen);
 
+       if (r != 18) {
+               cout << "IPMIDI: received from socket: " << r << endl;
+       }
+
        if (r >= 0) {
 
                _parser->set_timestamp (timestamp);