# 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
#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>
#include <unistd.h>
#include "common.h"
+#include "arp.h"
#include "interface.h"
#include "logger.h"
#include "socket.h"
#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)
{
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)",
#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
#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"
return 0;
}
-unsigned long random_xid (void)
+static unsigned long random_xid (void)
{
static int initialized;
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);
dhcp->rebindtime);
}
- if (dhcp->leasetime == -1)
+ if (dhcp->leasetime == (unsigned) -1)
logger (LOG_INFO, "leased %s for infinity",
inet_ntoa (dhcp->address));
else
#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 */
#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>
#include <unistd.h>
#include "common.h"
+#include "configure.h"
#include "dhcp.h"
#include "interface.h"
#include "dhcpcd.h"
static char *cleanmetas (char *cstr)
{
if (! cstr)
- return "";
+ return NULL;
register char *c = 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;
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? */
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;
return 0;
}
-static void restore_resolv(char *ifname)
+static void restore_resolv(const char *ifname)
{
struct stat buf;
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
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;
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;
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;
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;
#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
* 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>
#include <string.h>
#include "common.h"
+#include "dhcpcd.h"
#include "dhcp.h"
#include "interface.h"
#include "logger.h"
#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",
.\" $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
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;
#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>
}
#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;
}
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",
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;
/* 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)
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);
}
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;
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
{
#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);
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;
#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>
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!",
[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",
{
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);
}
#include <unistd.h>
#include "logger.h"
+#include "signals.h"
static int signal_pipe[2];
/* 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>
#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. */
}
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;
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;
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);
/* 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;
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;
#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