]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add loads of debugging CFLAGS so we can remove all compiler warnings
authorRoy Marples <roy@marples.name>
Thu, 14 Dec 2006 23:17:27 +0000 (23:17 +0000)
committerRoy Marples <roy@marples.name>
Thu, 14 Dec 2006 23:17:27 +0000 (23:17 +0000)
17 files changed:
Makefile
arp.c
arp.h
client.c
common.c
configure.c
configure.h
dhcp.c
dhcpcd.8
dhcpcd.c
dhcpcd.h
interface.c
interface.h
logger.c
signals.c
socket.c
socket.h

index 0a2cc47f2f008c50b6b403b4ee53a547252b9ecb..e856bc426a8efc5d99678fff64e0656b5583d9e9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,15 @@
 # Should work for both GNU make and BSD make
 
-VERSION = 3.0.6
+VERSION = 3.0.7_pre1
 
 INSTALL ?= install
-CFLAGS ?= -Wall -O2 -pedantic -std=gnu99
+CFLAGS = -O2 -pedantic -std=gnu99 \
+    -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
+    -Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \
+    -Wbad-function-cast -Wnested-externs -Wcomment -Winline \
+    -Wchar-subscripts -Wcast-align -Wno-format-nonliteral  \
+    -Wsequence-point -Wextra
+# -Wdeclaration-after-statement 
 
 DESTDIR =
 SBINDIR = $(DESTDIR)/sbin
diff --git a/arp.c b/arp.c
index 5afa3aed2c1c7c1c31c55cd2a4fd725f6a55890a..0cf9ea0db7559d8649a158cf78f823536bef1995 100644 (file)
--- a/arp.c
+++ b/arp.c
 
 #define _BSD_SOURCE
 
+#include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/select.h>
 #include <sys/socket.h>
-#include <sys/types.h>
 #include <netinet/in_systm.h>
 #ifdef __linux
 #include <netinet/ether.h>
@@ -40,6 +40,7 @@
 #include <unistd.h>
 
 #include "common.h"
+#include "arp.h"
 #include "interface.h"
 #include "logger.h"
 #include "socket.h"
@@ -58,7 +59,7 @@
 #define arphdr_len(ap) (arphdr_len2 ((ap)->ar_hln, (ap)->ar_pln))
 #endif
 
-int arp_check (interface_t *iface, struct in_addr address)
+int arp_check (interface_t *iface, const struct in_addr address)
 {
   if (! iface->arpable)
     {
@@ -138,7 +139,7 @@ int arp_check (interface_t *iface, struct in_addr address)
 
          if (ah->ar_hln != ETHER_ADDR_LEN)
            continue;
-         if (bytes < sizeof (*ah) + 2 * (4 + ah->ar_hln))
+         if ((unsigned) bytes < sizeof (*ah) + 2 * (4 + ah->ar_hln))
            continue;
 
          logger (LOG_ERR, "ARPOP_REPLY received from %s (%s)",
diff --git a/arp.h b/arp.h
index 4dfd007d1f15bea7a6f59e4b99bd4c2ea158816f..098227792470bd5afa9a513016744c1877de26ce 100644 (file)
--- a/arp.h
+++ b/arp.h
@@ -24,6 +24,6 @@
 
 #include "interface.h"
 
-int arp_check (interface_t *iface, struct in_addr address);
+int arp_check (interface_t *iface, const struct in_addr address);
 
 #endif
index c84c63d9ccd3200dce5f1906d5a164ddde30d1c0..7137cea0c71c152f5ac147ce660c14349d902ba0 100644 (file)
--- a/client.c
+++ b/client.c
@@ -34,8 +34,9 @@
 #include <time.h>
 #include <unistd.h>
 
-#include "arp.h"
 #include "common.h"
+#include "arp.h"
+#include "client.h"
 #include "configure.h"
 #include "dhcp.h"
 #include "dhcpcd.h"
@@ -94,7 +95,7 @@ static int daemonise (char *pidfile)
   return 0;
 }
 
-unsigned long random_xid (void)
+static unsigned long random_xid (void)
 {
   static int initialized;
 
@@ -174,7 +175,7 @@ int dhcp_run (options_t *options)
       if (timeout > 0 || (options->timeout == 0 &&
                          (state != STATE_INIT || xid)))
        {
-         if (options->timeout == 0 || dhcp->leasetime == -1)
+         if (options->timeout == 0 || dhcp->leasetime == (unsigned) -1)
            {
              logger (LOG_DEBUG, "waiting on select for infinity");
              maxfd = signal_fd_set (&rset, iface->fd);
@@ -507,7 +508,7 @@ int dhcp_run (options_t *options)
                              dhcp->rebindtime);
                    }
 
-                 if (dhcp->leasetime == -1)
+                 if (dhcp->leasetime == (unsigned) -1)
                    logger (LOG_INFO, "leased %s for infinity",
                            inet_ntoa (dhcp->address));
                  else
index 9288def4af5145bab6aef4909a40834453d825ae..e1f5f5136513f0383edc78d3cb356b67829c174c 100644 (file)
--- a/common.c
+++ b/common.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "common.h"
 #include "logger.h"
 
 /* This requires us to link to rt on glibc, so we use sysinfo instead */
index 14a4132a8f8a4791cbb96983f570e47070cbe526..63e0a461c5375086993a5e2c14886d5b7a80be2a 100644 (file)
 
 #include <arpa/inet.h>
 
+#include <netinet/in.h>
 #ifdef __linux__
 #include <netinet/ether.h>
 #endif
-#include <netinet/in.h>
 #include <string.h>
 #include <errno.h>
 #include <netdb.h>
@@ -38,6 +38,7 @@
 #include <unistd.h>
 
 #include "common.h"
+#include "configure.h"
 #include "dhcp.h"
 #include "interface.h"
 #include "dhcpcd.h"
@@ -48,7 +49,7 @@
 static char *cleanmetas (char *cstr)
 {
   if (! cstr)
-    return "";
+    return NULL;
   
   register char *c = cstr;
 
@@ -60,7 +61,8 @@ static char *cleanmetas (char *cstr)
   return cstr;
 }
 
-void exec_script (char *script, char *infofile, char *arg)
+static void exec_script (const char *script, const char *infofile,
+                        const char *arg)
 {
   if (! script || ! infofile || ! arg)
     return;
@@ -73,12 +75,8 @@ void exec_script (char *script, char *infofile, char *arg)
       return;
     }
   
-  char *argc[4];
-
-  argc[0] = script;
-  argc[1] = infofile;
-  argc[2] = arg;
-  argc[3] = NULL;
+  char *const argc[4] =
+    { (char *) script, (char *) infofile, (char *) arg, NULL };
   logger (LOG_DEBUG, "exec \"%s %s %s\"", script, infofile, arg);
   
   /* We don't wait for the user script to finish - do we trust it? */
@@ -96,7 +94,7 @@ void exec_script (char *script, char *infofile, char *arg)
     logger (LOG_ERR, "fork: %s", strerror (errno));
 }
 
-static int make_resolv (char *ifname, dhcp_t *dhcp)
+static int make_resolv (const char *ifname, const dhcp_t *dhcp)
 {
   FILE *f;
   struct stat buf;
@@ -144,7 +142,7 @@ static int make_resolv (char *ifname, dhcp_t *dhcp)
   return 0;
 }
 
-static void restore_resolv(char *ifname)
+static void restore_resolv(const char *ifname)
 {
   struct stat buf;
 
@@ -153,12 +151,7 @@ static void restore_resolv(char *ifname)
 
   logger (LOG_DEBUG, "removing information from resolvconf");
 
-  char *argc[4];
-
-  argc[0] = RESOLVCONF;
-  argc[1] = "-d";
-  argc[2] = ifname;
-  argc[3] = NULL;
+  char *const argc[4] = { (char *) RESOLVCONF, (char *) "-d", (char *) ifname, NULL };
 
   /* Don't wait around here as we should only be called when
      dhcpcd is closing down and something may do a kill -9
@@ -177,7 +170,7 @@ static void restore_resolv(char *ifname)
     logger (LOG_ERR, "fork: %s", strerror (errno));
 }
 
-static int make_ntp (char *ifname, dhcp_t *dhcp)
+static int make_ntp (const char *ifname, const dhcp_t *dhcp)
 {
   FILE *f;
   address_t *address;
@@ -206,7 +199,7 @@ static int make_ntp (char *ifname, dhcp_t *dhcp)
   return 0;
 }
 
-static int make_nis (char *ifname, dhcp_t *dhcp)
+static int make_nis (const char *ifname, const dhcp_t *dhcp)
 {
   FILE *f;
   address_t *address;
@@ -240,7 +233,7 @@ static int make_nis (char *ifname, dhcp_t *dhcp)
   return 0;
 }
 
-static int write_info(interface_t *iface, dhcp_t *dhcp)
+static int write_info(const interface_t *iface, const dhcp_t *dhcp)
 {
   FILE *f;
   route_t *route;
@@ -346,7 +339,8 @@ static int write_info(interface_t *iface, dhcp_t *dhcp)
   return 0;
 }
 
-int configure (options_t *options, interface_t *iface, dhcp_t *dhcp)
+int configure (const options_t *options, interface_t *iface,
+              const dhcp_t *dhcp)
 {
   route_t *route = NULL;
   route_t *new_route = NULL;
index ce8514bd6bcb54ab216db22a6f89c6e4889e0769..59b7003db2ff15feec362e8cfeff50900091cc4b 100644 (file)
@@ -26,6 +26,7 @@
 #include "interface.h"
 #include "dhcp.h"
 
-int configure (options_t *options, interface_t *iface, dhcp_t *dhcp);
+int configure (const options_t *options, interface_t *iface,
+              const dhcp_t *dhcp);
 
 #endif
diff --git a/dhcp.c b/dhcp.c
index 87aa93b1d3b09d83387265db5f9598f3a783bb01..1f3eb8c3ad84bbab8b5f786d82ce6a9ee6e10a34 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -19,8 +19,8 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 
 #include <netinet/in.h>
 #include <net/if_arp.h>
@@ -32,6 +32,7 @@
 #include <string.h>
 
 #include "common.h"
+#include "dhcpcd.h"
 #include "dhcp.h"
 #include "interface.h"
 #include "logger.h"
@@ -39,7 +40,7 @@
 
 #define BROADCAST_FLAG 0x8000
 
-static char *dhcp_message[] = {
+static const char *dhcp_message[] = {
   [DHCP_DISCOVER]      = "DHCP_DISCOVER",
   [DHCP_OFFER]         = "DHCP_OFFER",
   [DHCP_REQUEST]       = "DHCP_REQUEST",
index 07aae5c137cedb98229f323a027ba2c6fc37d55a..a53a18a9f762ffad6555ad6f9afbce4ea611241f 100644 (file)
--- a/dhcpcd.8
+++ b/dhcpcd.8
@@ -1,6 +1,6 @@
 .\" $Id$
 .\"
-.TH dhcpcd 8 "06 December 2006" "dhcpcd 3.0"
+.TH DHCPCD 8 "06 December 2006" "dhcpcd 3.0"
 
 .SH NAME
 dhcpcd \- DHCP client daemon
index 150dd8185d49f95398a541852604dabf40a7982b..f46d5903ee781e1fa28ef0e82b9c3fac49a8f719 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -110,7 +110,7 @@ int main(int argc, char **argv)
   openlog (PACKAGE, LOG_PID, LOG_LOCAL0);
 
   memset (&options, 0, sizeof (options_t));
-  options.script = DEFAULT_SCRIPT;
+  options.script = (char *) DEFAULT_SCRIPT;
   snprintf (options.classid, CLASS_ID_MAX_LEN, "%s %s", PACKAGE, VERSION); 
 
   options.doarp = false;
index 13c80d4222989deb4c438cdd80124167e290b001..6c68d50e5807b67a9b3c3e5b1d2a668bda4559b7 100644 (file)
--- a/dhcpcd.h
+++ b/dhcpcd.h
 #ifndef DHCPCD_H
 #define DHCPCD_H
 
+#include <sys/param.h>
 #include <sys/socket.h>
-#ifdef __linux__
-#include <linux/limits.h>
-#endif
 #include <net/if.h>
 #include <netinet/in.h>
 #include <limits.h>
index 6e5aa27630a05ece5b895509b18d5a767c8e68e3..224ccca053ac8df3d0f5c4e78b57af1dffc23faf 100644 (file)
@@ -148,9 +148,11 @@ interface_t *read_interface (const char *ifname, int metric)
     }
 
 #ifdef __linux__
+  /* Do something with the metric parameter to satisfy the compiler warning */
+  metric = 0;
   if (ioctl (s, SIOCGIFHWADDR, &ifr) <0)
     {
-      logger (LOG_ERR, "ioctl SIOCGIFHWADDR: %s", strerror(errno));
+      logger (LOG_ERR, "ioctl SIOCGIFHWADDR: %s", strerror (errno));
       close (s);
       return NULL;
     }
@@ -262,6 +264,9 @@ static int do_route (const char *ifname,
   if (! ifname)
     return -1;
 
+  /* Do something with metric to satisfy compiler warnings */
+  metric = 0;
+
   char *destd = strdup (inet_ntoa (destination));
   char *gend = strdup (inet_ntoa (netmask));
   logger (LOG_INFO, "%s route to %s (%s) via %s",
@@ -344,7 +349,7 @@ static int send_netlink(struct nlmsghdr *hdr)
       return -1;
     }
 
-  int mypid = getpid ();
+  pid_t mypid = getpid ();
   struct sockaddr_nl nl;
   memset (&nl, 0, sizeof (struct sockaddr_nl));
   nl.nl_family = AF_NETLINK;
@@ -369,7 +374,7 @@ static int send_netlink(struct nlmsghdr *hdr)
 
   /* Request a reply */
   hdr->nlmsg_flags |= NLM_F_ACK;
-  static int seq;
+  static unsigned int seq;
   hdr->nlmsg_seq = ++seq;
 
   if (sendmsg (s, &msg, 0) < 0)
@@ -408,7 +413,7 @@ static int send_netlink(struct nlmsghdr *hdr)
          goto eexit;
        }
 
-      for (h = (struct nlmsghdr *) buffer; bytes >= sizeof (*h); )
+      for (h = (struct nlmsghdr *) buffer; bytes >= (signed) sizeof (*h); )
        {
          int len = h->nlmsg_len;
          int l = len - sizeof (*h);
@@ -423,7 +428,7 @@ static int send_netlink(struct nlmsghdr *hdr)
            }
 
          if (nl.nl_pid != 0 ||
-             h->nlmsg_pid != mypid ||
+             (pid_t) h->nlmsg_pid != mypid ||
              h->nlmsg_seq != seq)
            /* Message isn't for us, so skip it */
            goto next;
@@ -432,7 +437,7 @@ static int send_netlink(struct nlmsghdr *hdr)
          if (h->nlmsg_type == NLMSG_ERROR)
            {
              struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA (h);
-             if (l < sizeof (struct nlmsgerr))
+             if ((unsigned) l < sizeof (struct nlmsgerr))
                logger (LOG_ERR, "truncated error message");
              else
                {
@@ -477,7 +482,7 @@ eexit:
 #define NLMSG_TAIL(nmsg) \
  ((struct rtattr *) (((unsigned char *) (nmsg)) \
                     + NLMSG_ALIGN((nmsg)->nlmsg_len)))
-static int add_attr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,
+static int add_attr_l(struct nlmsghdr *n, unsigned int maxlen, int type, const void *data,
                      int alen)
 {
   int len = RTA_LENGTH(alen);
@@ -498,7 +503,7 @@ static int add_attr_l(struct nlmsghdr *n, int maxlen, int type, const void *data
   return 0;
 }
 
-static int add_attr_32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
+static int add_attr_32(struct nlmsghdr *n, unsigned int maxlen, int type, uint32_t data)
 {
   int len = RTA_LENGTH (sizeof (uint32_t));
   struct rtattr *rta;
index 8b855459f44c0c0eb836aafc1b33305184e4892f..0ba4b89208cea66cf10cfc4b35a8a7a7f87bfd1c 100644 (file)
 #define INTERFACE_H
 
 #include <sys/types.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 #include <net/if.h>
-#include <netinet/if_ether.h>
 #include <netinet/in.h>
+#include <netinet/if_ether.h>
 #include <limits.h>
 #include <stdbool.h>
 
index e2760e101b6dba36ee43967010d169bcccbe10b2..d9e3700fc542cb6caa18b468a23fc3e41e796b07 100644 (file)
--- a/logger.c
+++ b/logger.c
@@ -31,7 +31,7 @@
 static int loglevel = LOG_WARNING;
 static char logprefix[12] = {0};
 
-static char *syslog_level_msg[] = {
+static const char *syslog_level_msg[] = {
   [LOG_EMERG]          = "EMERGENCY!",
   [LOG_ALERT]          = "ALERT!",
   [LOG_CRIT]           = "Critical!",
@@ -42,7 +42,7 @@ static char *syslog_level_msg[] = {
   [LOG_DEBUG + 1]      = NULL
 };
 
-static char *syslog_level[] = {
+static const char *syslog_level[] = {
   [LOG_EMERG]          = "LOG_EMERG",
   [LOG_ALERT]          = "LOG_ALERT",
   [LOG_CRIT]           = "LOG_CRIT",
@@ -99,10 +99,10 @@ void logger(int level, const char *fmt, ...)
     {
       int len = strlen (logprefix);
       char *fmt2 = xmalloc (strlen (fmt) + len + 1);
-      char *p = fmt2;
-      memcpy (p, logprefix, len);
-      p += len;
-      strcpy (p, fmt);
+      char *pf = fmt2;
+      memcpy (pf, logprefix, len);
+      pf += len;
+      strcpy (pf, fmt);
       vsyslog (level, fmt2, p2);
       free (fmt2);
     }
index b565b8d2e6a7c756214346d5e12281cea5416817..9e441e0f7e22d90c1d9657eab526a7acaa9c86bf 100644 (file)
--- a/signals.c
+++ b/signals.c
@@ -28,6 +28,7 @@
 #include <unistd.h>
 
 #include "logger.h"
+#include "signals.h"
 
 static int signal_pipe[2];
 
index fb5864d3648df5deb33ff33c011015c7d590db48..d789638aad346a0657004ef6773fd0c190433a91 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -22,9 +22,9 @@
 /* We use BSD structure so our code is more portable */
 #define _BSD_SOURCE
 
+#include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <sys/types.h>
 #include <sys/uio.h>
 #include <arpa/inet.h>
 #include <netinet/in_systm.h>
@@ -43,6 +43,7 @@
 #include "dhcp.h"
 #include "interface.h"
 #include "logger.h"
+#include "socket.h"
 
 /* A suitably large buffer for all transactions.
    BPF buffer size is set by the kernel, so no define. */
@@ -76,7 +77,7 @@ static uint16_t checksum (unsigned char *addr, uint16_t len)
 }
 
 void make_dhcp_packet(struct udp_dhcp_packet *packet,
-                     unsigned char *data, unsigned int length,
+                     unsigned char *data, int length,
                      struct in_addr source, struct in_addr dest)
 {
   struct ip *ip = &packet->ip;
@@ -293,8 +294,7 @@ int open_socket (interface_t *iface, bool arp)
   return fd;
 }
 
-int send_packet (interface_t *iface, int type, unsigned char *data,
-                unsigned int len)
+int send_packet (interface_t *iface, int type, unsigned char *data, int len)
 {
   /* We only support ethernet atm */
   struct ether_header hw;
@@ -348,7 +348,8 @@ int get_packet (interface_t *iface, unsigned char *data,
   while (packet)
     {
       /* Ensure that the entire packet is in our buffer */
-      if (*buffer_pos + packet->bh_hdrlen + packet->bh_caplen > *buffer_len)
+      if (*buffer_pos + packet->bh_hdrlen + packet->bh_caplen
+          > (unsigned) *buffer_len)
         break;
 
       hw = (struct ether_header *) ((char *) packet + packet->bh_hdrlen);
@@ -464,7 +465,7 @@ int send_packet (interface_t *iface, int type, unsigned char *data, int len)
 
 /* Linux has no need for the buffer as we can read as much as we want.
    We only have the buffer listed to keep the same API. */
-size_t get_packet (interface_t *iface, unsigned char *data,
+int get_packet (interface_t *iface, unsigned char *data,
                   unsigned char *buffer, int *buffer_len, int *buffer_pos)
 {
   long bytes;
@@ -492,7 +493,7 @@ size_t get_packet (interface_t *iface, unsigned char *data,
       return bytes;
     }
 
-  if (bytes < (sizeof (struct ip) + sizeof (struct udphdr)))
+  if ((unsigned) bytes < (sizeof (struct ip) + sizeof (struct udphdr)))
     {
       logger (LOG_DEBUG, "message too short, ignoring");
       return -1;
index a35f5b563f6bfc469973f206a3d1744e8438e928..db3058aac2e31c59683c21888f3d3f261c196892 100644 (file)
--- a/socket.h
+++ b/socket.h
 #include "interface.h"
 
 void make_dhcp_packet(struct udp_dhcp_packet *packet,
-                     unsigned char *data, unsigned int length,
+                     unsigned char *data, int length,
                      struct in_addr source, struct in_addr dest);
 
 int open_socket (interface_t *iface, bool arp);
-int send_packet (interface_t *iface, int type, unsigned char *data, unsigned int len);
+int send_packet (interface_t *iface, int type, unsigned char *data, int len);
 int get_packet (interface_t *iface, unsigned char *data,
                unsigned char *buffer, int *buffer_len, int *buffer_pos);
 #endif