Merge branch 'collectd-4.10' into collectd-5.0
[collectd.git] / src / utils_dns.c
index 66798e2..cfa4a5c 100644 (file)
@@ -358,10 +358,10 @@ handle_dns(const char *buf, int len)
     uint16_t us;
     off_t offset;
     char *t;
-    int x;
+    int status;
 
     /* The DNS header is 12 bytes long */
-    if (len < 12)
+    if (len < DNS_MSG_HDR_SZ)
        return 0;
 
     memcpy(&us, buf + 0, 2);
@@ -392,11 +392,15 @@ handle_dns(const char *buf, int len)
     memcpy(&us, buf + 10, 2);
     qh.arcount = ntohs(us);
 
-    offset = 12;
+    offset = DNS_MSG_HDR_SZ;
     memset(qh.qname, '\0', MAX_QNAME_SZ);
-    x = rfc1035NameUnpack(buf, len, &offset, qh.qname, MAX_QNAME_SZ);
-    if (0 != x)
+    status = rfc1035NameUnpack(buf, len, &offset, qh.qname, MAX_QNAME_SZ);
+    if (status != 0)
+    {
+       INFO ("utils_dns: handle_dns: rfc1035NameUnpack failed "
+               "with status %i.", status);
        return 0;
+    }
     if ('\0' == qh.qname[0])
        sstrncpy (qh.qname, ".", sizeof (qh.qname));
     while ((t = strchr(qh.qname, '\n')))
@@ -437,6 +441,7 @@ handle_udp(const struct udphdr *udp, int len)
     return 1;
 }
 
+#if HAVE_NETINET_IP6_H
 static int
 handle_ipv6 (struct ip6_hdr *ipv6, int len)
 {
@@ -445,7 +450,6 @@ handle_ipv6 (struct ip6_hdr *ipv6, int len)
     int nexthdr;
 
     struct in6_addr s_addr;
-    struct in6_addr d_addr;
     uint16_t payload_len;
 
     if (0 > len)
@@ -454,7 +458,6 @@ handle_ipv6 (struct ip6_hdr *ipv6, int len)
     offset = sizeof (struct ip6_hdr);
     nexthdr = ipv6->ip6_nxt;
     s_addr = ipv6->ip6_src;
-    d_addr = ipv6->ip6_dst;
     payload_len = ntohs (ipv6->ip6_plen);
 
     if (ignore_list_match (&s_addr))
@@ -508,6 +511,16 @@ handle_ipv6 (struct ip6_hdr *ipv6, int len)
 
     return (1); /* Success */
 } /* int handle_ipv6 */
+/* #endif HAVE_NETINET_IP6_H */
+
+#else /* if !HAVE_NETINET_IP6_H */
+static int
+handle_ipv6 (__attribute__((unused)) void *pkg,
+       __attribute__((unused)) int len)
+{
+    return (0);
+}
+#endif /* !HAVE_NETINET_IP6_H */
 
 static int
 handle_ip(const struct ip *ip, int len)
@@ -518,7 +531,7 @@ handle_ip(const struct ip *ip, int len)
     struct in6_addr d_addr;
 
     if (ip->ip_v == 6)
-       return (handle_ipv6 ((struct ip6_hdr *) ip, len));
+       return (handle_ipv6 ((void *) ip, len));
 
     in6_addr_from_buffer (&s_addr, &ip->ip_src.s_addr, sizeof (ip->ip_src.s_addr), AF_INET);
     in6_addr_from_buffer (&d_addr, &ip->ip_dst.s_addr, sizeof (ip->ip_dst.s_addr), AF_INET);
@@ -616,7 +629,7 @@ handle_ether(const u_char * pkt, int len)
        return 0;
     memcpy(buf, pkt, len);
     if (ETHERTYPE_IPV6 == etype)
-       return (handle_ipv6 ((struct ip6_hdr *) buf, len));
+       return (handle_ipv6 ((void *) buf, len));
     else
        return handle_ip((struct ip *) buf, len);
 }
@@ -649,7 +662,7 @@ handle_linux_sll (const u_char *pkt, int len)
        return 0;
 
     if (ETHERTYPE_IPV6 == etype)
-       return (handle_ipv6 ((struct ip6_hdr *) pkt, len));
+       return (handle_ipv6 ((void *) pkt, len));
     else
        return handle_ip((struct ip *) pkt, len);
 }
@@ -660,10 +673,6 @@ void handle_pcap(u_char *udata, const struct pcap_pkthdr *hdr, const u_char *pkt
 {
     int status;
 
-    DEBUG ("handle_pcap (udata = %p, hdr = %p, pkt = %p): hdr->caplen = %i\n",
-                   (void *) udata, (void *) hdr, (void *) pkt,
-                   hdr->caplen);
-
     if (hdr->caplen < ETHER_HDR_LEN)
        return;
 
@@ -697,7 +706,7 @@ void handle_pcap(u_char *udata, const struct pcap_pkthdr *hdr, const u_char *pkt
            break;
 
        default:
-           ERROR ("handle_pcap: unsupported data link type %d\n",
+           ERROR ("handle_pcap: unsupported data link type %d",
                    pcap_datalink(pcap_obj));
            status = 0;
            break;