X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_dns.c;h=a1e4222f3cb2180fd1c692b86de0aaafccb82f17;hb=dc6f54ccc87c5ae63d29f05eca91714ade689691;hp=655c61edf0764cc9911bab2a71e6556bc83405a0;hpb=ef4a3db895a0aba7107c0f1c6c2ef2a7f128aaf8;p=collectd.git diff --git a/src/utils_dns.c b/src/utils_dns.c index 655c61ed..a1e4222f 100644 --- a/src/utils_dns.c +++ b/src/utils_dns.c @@ -1,12 +1,12 @@ /* * collectd - src/utils_dns.c - * Modifications Copyright (C) 2006 Florian octo Forster - * Copyright (C) 2002 The Measurement Factory, Inc. + * Copyright (C) 2006 Florian octo Forster + * Copyright (C) 2002 The Measurement Factory, Inc. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, @@ -30,19 +30,16 @@ * * Authors: * The Measurement Factory, Inc. - * Florian octo Forster + * Florian octo Forster */ +#define _DEFAULT_SOURCE #define _BSD_SOURCE #include "collectd.h" #include "plugin.h" #include "common.h" -#if HAVE_SYS_SOCKET_H -# include -#endif - #if HAVE_NET_IF_ARP_H # include #endif @@ -65,9 +62,6 @@ #if HAVE_NETINET_IP6_H # include #endif -#if HAVE_NETINET_IP_COMPAT_H -# include -#endif #if HAVE_NETINET_IF_ETHER_H # include #endif @@ -129,6 +123,10 @@ # error "`struct udphdr' is unusable." #endif +#if HAVE_NETINET_IP6_H && HAVE_STRUCT_IP6_EXT +# define HAVE_IPV6 1 +#endif + #include "utils_dns.h" /* @@ -158,9 +156,6 @@ typedef int (printer)(const char *, ...); /* * Global variables */ -int qtype_counts[T_MAX]; -int opcode_counts[OP_MAX]; -int qclass_counts[C_MAX]; #if HAVE_PCAP_H static pcap_t *pcap_obj = NULL; @@ -214,7 +209,7 @@ static void ignore_list_add (const struct in6_addr *addr) if (ignore_list_match (addr) != 0) return; - new = malloc (sizeof (ip_list_t)); + new = malloc (sizeof (*new)); if (new == NULL) { perror ("malloc"); @@ -288,8 +283,7 @@ void dnstop_set_callback (void (*cb) (const rfc1035_header_t *)) #define RFC1035_MAXLABELSZ 63 static int -rfc1035NameUnpack(const char *buf, size_t sz, off_t * off, char *name, size_t ns -) +rfc1035NameUnpack(const char *buf, size_t sz, off_t * off, char *name, size_t ns) { off_t no = 0; unsigned char c; @@ -297,10 +291,10 @@ rfc1035NameUnpack(const char *buf, size_t sz, off_t * off, char *name, size_t ns static int loop_detect = 0; if (loop_detect > 2) return 4; /* compression loop */ - if (ns <= 0) + if (ns == 0) return 4; /* probably compression loop */ do { - if ((*off) >= sz) + if ((*off) >= ((off_t) sz)) break; c = *(buf + (*off)); if (c > 191) { @@ -312,11 +306,11 @@ rfc1035NameUnpack(const char *buf, size_t sz, off_t * off, char *name, size_t ns s = ntohs(s); (*off) += sizeof(s); /* Sanity check */ - if ((*off) >= sz) + if ((*off) >= ((off_t) sz)) return 1; /* message too short */ ptr = s & 0x3FFF; /* Make sure the pointer is inside this message */ - if (ptr >= sz) + if (ptr >= ((off_t) sz)) return 2; /* bad compression ptr */ if (ptr < DNS_MSG_HDR_SZ) return 2; /* bad compression ptr */ @@ -329,7 +323,6 @@ rfc1035NameUnpack(const char *buf, size_t sz, off_t * off, char *name, size_t ns * "(The 10 and 01 combinations are reserved for future use.)" */ return 3; /* reserved label/compression flags */ - break; } else { (*off)++; len = (size_t) c; @@ -350,7 +343,7 @@ rfc1035NameUnpack(const char *buf, size_t sz, off_t * off, char *name, size_t ns if (no > 0) *(name + no - 1) = '\0'; /* make sure we didn't allow someone to overflow the name buffer */ - assert(no <= ns); + assert(no <= ((off_t) ns)); return 0; } @@ -420,11 +413,6 @@ handle_dns(const char *buf, int len) qh.length = (uint16_t) len; - /* gather stats */ - qtype_counts[qh.qtype]++; - qclass_counts[qh.qclass]++; - opcode_counts[qh.opcode]++; - if (Callback != NULL) Callback (&qh); @@ -444,7 +432,7 @@ handle_udp(const struct udphdr *udp, int len) return 1; } -#if HAVE_NETINET_IP6_H +#if HAVE_IPV6 static int handle_ipv6 (struct ip6_hdr *ipv6, int len) { @@ -513,16 +501,16 @@ handle_ipv6 (struct ip6_hdr *ipv6, int len) return (1); /* Success */ } /* int handle_ipv6 */ -/* #endif HAVE_NETINET_IP6_H */ +/* #endif HAVE_IPV6 */ -#else /* if !HAVE_NETINET_IP6_H */ +#else /* if !HAVE_IPV6 */ static int handle_ipv6 (__attribute__((unused)) void *pkg, __attribute__((unused)) int len) { return (0); } -#endif /* !HAVE_NETINET_IP6_H */ +#endif /* !HAVE_IPV6 */ static int handle_ip(const struct ip *ip, int len) @@ -840,9 +828,7 @@ const char *qtype_str(int t) default: ssnprintf (buf, sizeof (buf), "#%i", t); return (buf); - }; /* switch (t) */ - /* NOTREACHED */ - return (NULL); + } /* switch (t) */ } const char *opcode_str (int o) @@ -851,24 +837,18 @@ const char *opcode_str (int o) switch (o) { case 0: return "Query"; - break; case 1: return "Iquery"; - break; case 2: return "Status"; - break; case 4: return "Notify"; - break; case 5: return "Update"; - break; default: ssnprintf(buf, sizeof (buf), "Opcode%d", o); return buf; } - /* NOTREACHED */ } const char *rcode_str (int rcode) @@ -912,8 +892,6 @@ const char *rcode_str (int rcode) ssnprintf (buf, sizeof (buf), "RCode%i", rcode); return (buf); } - /* Never reached */ - return (NULL); } /* const char *rcode_str (int rcode) */ #if 0