Fix AVL tree traversal in cache_record_find and cache_host_is_known
[project/mdnsd.git] / interface.c
index 3904c8918125d786e7119f56c8dfdcb1d8cd608f..e3febb8a868e5213e3475c59427921e3b6a5f3af 100644 (file)
@@ -233,7 +233,7 @@ read_socket4(struct uloop_fd *u, unsigned int events)
                }
        }
 
-       if (ttl != 255)
+       if (!inp)
                return;
 
        if (debug > 1) {
@@ -247,6 +247,7 @@ read_socket4(struct uloop_fd *u, unsigned int events)
                fprintf(stderr, "  dst %s\n", buf);
                inet_ntop(AF_INET, &inp->ipi_addr, buf, 256);
                fprintf(stderr, "  real %s\n", buf);
+               fprintf(stderr, "  ttl %u\n", ttl);
        }
 
        if (inp->ipi_ifindex != iface->ifindex)
@@ -310,7 +311,7 @@ read_socket6(struct uloop_fd *u, unsigned int events)
                }
        }
 
-       if (ttl != 255)
+       if (!inp)
                return;
 
        if (debug > 1) {
@@ -322,6 +323,7 @@ read_socket6(struct uloop_fd *u, unsigned int events)
                fprintf(stderr, "  src %s:%d\n", buf, ntohs(from.sin6_port));
                inet_ntop(AF_INET6, &inp->ipi6_addr, buf, 256);
                fprintf(stderr, "  dst %s\n", buf);
+               fprintf(stderr, "  ttl %u\n", ttl);
        }
 
        if (inp->ipi6_ifindex != iface->ifindex)
@@ -359,9 +361,9 @@ interface_mcast_setup4(struct interface *iface)
        setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
 
        if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
-               fprintf(stderr, "failed to join multicast group: %s\n", strerror(errno));
+               fprintf(stderr, "failed to join multicast group: %m\n");
                close(fd);
-               fd = -1;
+               iface->fd.fd = -1;
                return -1;
        }
 
@@ -393,9 +395,9 @@ interface_socket_setup6(struct interface *iface)
 
        setsockopt(fd, IPPROTO_IPV6, IPV6_LEAVE_GROUP, &mreq, sizeof(mreq));
        if (setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
-               fprintf(stderr, "failed to join multicast group: %s\n", strerror(errno));
+               fprintf(stderr, "failed to join multicast group: %m\n");
                close(fd);
-               fd = -1;
+               iface->fd.fd = -1;
                return -1;
        }
 
@@ -415,7 +417,7 @@ reconnect_socket4(struct uloop_timeout *timeout)
        iface->fd.fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK | USOCK_IPV4ONLY,
                (iface->multicast) ? (iface->mcast_addr) : (iface->v4_addrs), "5353");
        if (iface->fd.fd < 0) {
-               fprintf(stderr, "failed to add listener %s: %s\n", iface->mcast_addr, strerror(errno));
+               fprintf(stderr, "failed to add listener %s: %m\n", iface->mcast_addr);
                goto retry;
        }
 
@@ -462,7 +464,7 @@ reconnect_socket6(struct uloop_timeout *timeout)
        snprintf(mcast_addr, sizeof(mcast_addr), "%s%%%s", (iface->multicast) ? (iface->mcast_addr) : (iface->v6_addrs), iface->name);
        iface->fd.fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK | USOCK_IPV6ONLY, mcast_addr, "5353");
        if (iface->fd.fd < 0) {
-               fprintf(stderr, "failed to add listener %s: %s\n", mcast_addr, strerror(errno));
+               fprintf(stderr, "failed to add listener %s: %m\n", mcast_addr);
                goto retry;
        }
 
@@ -509,7 +511,7 @@ static void interface_start(struct interface *iface)
                iface->fd.cb = read_socket4;
                iface->reconnect.cb = reconnect_socket4;
        }
-       uloop_timeout_set(&iface->reconnect, 100);
+       uloop_timeout_set(&iface->reconnect, 1000);
 }
 
 static void