X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Futils_dns.c;h=6541b897ffdd68da466472269998b3d4b893d549;hb=f8c6d793143453b064c68f92cb17e88302b8bbb9;hp=221bac4bfdcb27c9022e75b20a406946e19bc842;hpb=55ffd0b2b51d27fa7192a2db57e9a6537b18362b;p=collectd.git diff --git a/src/utils_dns.c b/src/utils_dns.c index 221bac4b..6541b897 100644 --- a/src/utils_dns.c +++ b/src/utils_dns.c @@ -35,6 +35,9 @@ #include "collectd.h" +#if HAVE_NETINET_IN_SYSTM_H +# include +#endif #if HAVE_NETINET_IN_H # include #endif @@ -71,12 +74,6 @@ # include #endif -#if HAVE_NETINET_IN_SYSTM_H -# include -#endif -#if HAVE_NETINET_IN_H -# include -#endif #if HAVE_NETINET_IP_H # include #endif @@ -110,9 +107,14 @@ # define PPP_CONTROL_VAL 0x03 /* The control byte value */ #endif -#ifdef __linux__ -#define uh_sport source -#define uh_dport dest +#if HAVE_STRUCT_UDPHDR_UH_DPORT && HAVE_STRUCT_UDPHDR_UH_SPORT +# define UDP_DEST uh_dport +# define UDP_SRC uh_dport +#elif HAVE_STRUCT_UDPHDR_DEST && HAVE_STRUCT_UDPHDR_SOURCE +# define UDP_DEST dest +# define UDP_SRC source +#else +# error "`struct udphdr' is unusable." #endif #include "utils_dns.h" @@ -409,8 +411,8 @@ handle_udp(const struct udphdr *udp, int len, const struct in6_addr *d_addr) { char buf[PCAP_SNAPLEN]; - if ((ntohs (udp->uh_dport) != 53) - && (ntohs (udp->uh_sport) != 53)) + if ((ntohs (udp->UDP_DEST) != 53) + && (ntohs (udp->UDP_SRC) != 53)) return 0; memcpy(buf, udp + 1, len - sizeof(*udp)); if (0 == handle_dns(buf, len - sizeof(*udp), s_addr, d_addr)) @@ -599,6 +601,40 @@ handle_ether(const u_char * pkt, int len) return handle_ip((struct ip *) buf, len); } +#ifdef DLT_LINUX_SLL +static int +handle_linux_sll (const u_char *pkt, int len) +{ + struct sll_header + { + uint16_t pkt_type; + uint16_t dev_type; + uint16_t addr_len; + uint8_t addr[8]; + uint16_t proto_type; + } *hdr; + uint16_t etype; + + if (len < sizeof (struct sll_header)) + return (0); + + hdr = (struct sll_header *) pkt; + pkt = (u_char *) (hdr + 1); + len -= sizeof (struct sll_header); + + etype = ntohs (hdr->proto_type); + + if ((ETHERTYPE_IP != etype) + && (ETHERTYPE_IPV6 != etype)) + return 0; + + if (ETHERTYPE_IPV6 == etype) + return (handle_ipv6 ((struct ip6_hdr *) pkt, len)); + else + return handle_ip((struct ip *) pkt, len); +} +#endif /* DLT_LINUX_SLL */ + /* public function */ void handle_pcap(u_char *udata, const struct pcap_pkthdr *hdr, const u_char *pkt) { @@ -630,6 +666,11 @@ void handle_pcap(u_char *udata, const struct pcap_pkthdr *hdr, const u_char *pkt case DLT_RAW: status = handle_raw (pkt, hdr->caplen); break; +#endif +#ifdef DLT_LINUX_SLL + case DLT_LINUX_SLL: + status = handle_linux_sll (pkt, hdr->caplen); + break; #endif case DLT_NULL: status = handle_null (pkt, hdr->caplen);