From: Roy Marples Date: Mon, 21 Jan 2008 21:19:53 +0000 (+0000) Subject: Quiet some lint warnings. X-Git-Tag: v3.2.3~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc9be8a47ffa109785d348d92fdc6c915be734c4;p=thirdparty%2Fdhcpcd.git Quiet some lint warnings. --- diff --git a/arp.c b/arp.c index acc24118..3b4ea750 100644 --- a/arp.c +++ b/arp.c @@ -77,7 +77,7 @@ static int send_arp (const interface_t *iface, int op, struct in_addr sip, const unsigned char *taddr, struct in_addr tip) { struct arphdr *arp; - int arpsize = arphdr_len2 (iface->hwlen, sizeof (struct in_addr)); + size_t arpsize = arphdr_len2 (iface->hwlen, sizeof (struct in_addr)); caddr_t tha; int retval; @@ -89,8 +89,8 @@ static int send_arp (const interface_t *iface, int op, struct in_addr sip, arp->ar_hln = iface->hwlen; arp->ar_pln = sizeof (struct in_addr); arp->ar_op = htons (op); - memcpy (ar_sha (arp), iface->hwaddr, arp->ar_hln); - memcpy (ar_spa (arp), &sip, arp->ar_pln); + memcpy (ar_sha (arp), iface->hwaddr, (size_t) arp->ar_hln); + memcpy (ar_spa (arp), &sip, (size_t) arp->ar_pln); if (taddr) { /* NetBSD can return NULL from ar_tha, which is probably wrong * but we still need to deal with it */ @@ -99,9 +99,9 @@ static int send_arp (const interface_t *iface, int op, struct in_addr sip, errno = EINVAL; return (-1); } - memcpy (tha, taddr, arp->ar_hln); + memcpy (tha, taddr, (size_t) arp->ar_hln); } - memcpy (ar_tpa (arp), &tip, arp->ar_pln); + memcpy (ar_tpa (arp), &tip, (size_t) arp->ar_pln); retval = send_packet (iface, ETHERTYPE_ARP, (unsigned char *) arp, arphdr_len (arp)); @@ -143,8 +143,8 @@ int arp_claim (interface_t *iface, struct in_addr address) for (;;) { struct timeval tv; - int bufpos = -1; - int buflen = iface->buffer_length; + size_t bufpos = 0; + size_t buflen = iface->buffer_length; fd_set rset; int bytes; int s = 0; @@ -226,7 +226,7 @@ int arp_claim (interface_t *iface, struct in_addr address) continue; memset (buffer, 0, buflen); - while (bufpos != 0) { + do { union { unsigned char *c; struct in_addr *a; @@ -270,10 +270,10 @@ int arp_claim (interface_t *iface, struct in_addr address) logger (LOG_ERR, "ARPOP_REPLY received from %s (%s)", inet_ntoa (*rp.a), - hwaddr_ntoa (rh.c, reply->ar_hln)); + hwaddr_ntoa (rh.c, (size_t) reply->ar_hln)); retval = -1; goto eexit; - } + } while (bufpos != 0); } eexit: diff --git a/client.c b/client.c index 9f704d5f..ad2a192b 100644 --- a/client.c +++ b/client.c @@ -75,7 +75,7 @@ #ifdef THERE_IS_NO_FORK # ifndef ENABLE_INFO -# error "Non MMU requires ENABLE_INFO to work" + # error "Non MMU requires ENABLE_INFO to work" # endif #endif @@ -117,12 +117,12 @@ typedef struct _state { time_t last_sent; time_t last_type; long timeout; - long nakoff; + time_t nakoff; bool daemonised; bool persistent; unsigned char *buffer; - ssize_t buffer_len; - ssize_t buffer_pos; + size_t buffer_len; + size_t buffer_pos; } state_t; static pid_t daemonise (int *pidfd) @@ -462,7 +462,7 @@ static int wait_for_packet (fd_set *rset, state_t *state, else tv.tv_sec = TIMEOUT_MINI; if (state->timeout < tv.tv_sec) - tv.tv_sec = state->timeout; + tv.tv_sec = (time_t) state->timeout; tv.tv_usec = 0; state->start = uptime (); maxfd = signal_fd_set (rset, iface->fd); @@ -516,7 +516,7 @@ static bool handle_signal (int sig, state_t *state, const options_t *options) logger (LOG_INFO, "received SIGHUP, releasing lease"); if (! IN_LINKLOCAL (ntohl (state->dhcp->address.s_addr))) { do_socket (state, SOCKET_OPEN); - state->xid = random (); + state->xid = (uint32_t) random (); if ((open_socket (state->interface, false)) >= 0) _send_message (state, DHCP_RELEASE, options); do_socket (state, SOCKET_CLOSED); @@ -632,7 +632,7 @@ static int handle_timeout (state_t *state, const options_t *options) switch (state->state) { case STATE_INIT: - state->xid = random (); + state->xid = (uint32_t) random (); do_socket (state, SOCKET_OPEN); state->timeout = options->timeout; iface->start_uptime = uptime (); @@ -662,7 +662,8 @@ static int handle_timeout (state_t *state, const options_t *options) break; } state->state = STATE_RENEWING; - state->xid = random (); + state->xid = (uint32_t) random (); + /* FALLTHROUGH */ case STATE_RENEWING: iface->start_uptime = uptime (); logger (LOG_INFO, "renewing lease of %s", inet_ntoa @@ -677,7 +678,7 @@ static int handle_timeout (state_t *state, const options_t *options) memset (&dhcp->address, 0, sizeof (struct in_addr)); do_socket (state, SOCKET_OPEN); if (state->xid == 0) - state->xid = random (); + state->xid = (uint32_t) random (); _send_message (state, DHCP_REQUEST, options); state->timeout = dhcp->leasetime - dhcp->rebindtime; state->state = STATE_REQUESTING; @@ -689,7 +690,7 @@ static int handle_timeout (state_t *state, const options_t *options) break; case STATE_RELEASED: - dhcp->leasetime = -1; + dhcp->leasetime = 0; break; } @@ -715,7 +716,7 @@ static int handle_dhcp (state_t *state, int type, const options_t *options) /* If we constantly get NAKS then we should slowly back off */ if (state->nakoff > 0) { logger (LOG_DEBUG, "sleeping for %ld seconds", - state->nakoff); + (long) state->nakoff); tv.tv_sec = state->nakoff; tv.tv_usec = 0; state->nakoff *= 2; @@ -915,7 +916,7 @@ static int handle_packet (state_t *state, const options_t *options) if (! state->buffer) state->buffer = xmalloc (iface->buffer_length); state->buffer_len = iface->buffer_length; - state->buffer_pos = -1; + state->buffer_pos = 0; /* We loop through until our buffer is empty. The benefit is that if we get >1 DHCP packet in our buffer and @@ -924,7 +925,7 @@ static int handle_packet (state_t *state, const options_t *options) memset (&message, 0, sizeof (struct dhcpmessage_t)); new_dhcp = xmalloc (sizeof (dhcp_t)); - while (state->buffer_pos != 0) { + do { if (get_packet (iface, (unsigned char *) &message, state->buffer, &state->buffer_len, &state->buffer_pos) == -1) @@ -952,7 +953,7 @@ static int handle_packet (state_t *state, const options_t *options) any more DHCP packets at this point. */ valid = true; break; - } + } while (state->buffer_pos != 0); /* No packets for us, so wait until we get one */ if (! valid) { diff --git a/common.c b/common.c index 24c4039c..14e88541 100644 --- a/common.c +++ b/common.c @@ -180,12 +180,12 @@ time_t uptime (void) void writepid (int fd, pid_t pid) { char spid[16]; - if (ftruncate (fd, 0) == -1) { + if (ftruncate (fd, (off_t) 0) == -1) { logger (LOG_ERR, "ftruncate: %s", strerror (errno)); } else { ssize_t len; snprintf (spid, sizeof (spid), "%u", pid); - len = pwrite (fd, spid, strlen (spid), 0); + len = pwrite (fd, spid, strlen (spid), (off_t) 0); if (len != (ssize_t) strlen (spid)) logger (LOG_ERR, "pwrite: %s", strerror (errno)); } @@ -199,7 +199,9 @@ void *xmalloc (size_t s) return (value); logger (LOG_ERR, "memory exhausted"); + exit (EXIT_FAILURE); + /* NOTREACHED */ } void *xrealloc (void *ptr, size_t s) @@ -211,6 +213,7 @@ void *xrealloc (void *ptr, size_t s) logger (LOG_ERR, "memory exhausted"); exit (EXIT_FAILURE); + /* NOTREACHED */ } char *xstrdup (const char *str) @@ -225,5 +228,5 @@ char *xstrdup (const char *str) logger (LOG_ERR, "memory exhausted"); exit (EXIT_FAILURE); + /* NOTREACHED */ } - diff --git a/config.h b/config.h index 3d2ff9bf..2c0991bf 100644 --- a/config.h +++ b/config.h @@ -93,32 +93,40 @@ # define NISRESTARTARGS "--nodeps", "--quiet", "conditionalrestart" # define NTPSERVICE ETCDIR "/init.d/ntpd" # define NTPRESTARTARGS "--nodeps", "--quiet", "conditionalrestart" -#elif ENABLE_BSDRC +#endif +#if ENABLE_BSDRC # define SERVICE "BSDRC" # define NISSERVICE ETCDIR "/rc.d/ypbind" # define NISRESTARTARGS "restart" # define NTPSERVICE ETCDIR "/rc.d/ntpd" # define NTPRESTARTARGS "restart" -#elif ENABLE_SLACKRC +#endif +#if ENABLE_SLACKRC # define SERVICE "SLACKRC" # define NISSERVICE ETCDIR "/rc.d/rc.ypbind" # define NISRESTARTARGS "restart" # define NTPSERVICE ETCDIR "/rc.d/rc.ntpd" # define NTPRESTARTARGS "restart" -#elif ENABLE_SERVICE +#endif +#if ENABLE_SERVICE # define SERVICE "SERVICE" # define NISSERVICE "service" # define NISRESTARTARGS "ypbind", "restart" # define NTPSERVICE "service" # define NTPRESTARTARGS "ntpd", "restart" -#elif ENABLE_SYSV +#endif +#if ENABLE_SYSV # define SERVICE "SYSV" # define NISSERVICE ETCDIR "/init.d/ypbind" # define NISRESTARTARGS "restart" # define NTPSERVICE ETCDIR "/init.d/ntpd" # define NTPRESTARTARGS "restart" -#else +#endif + +#ifndef NISSERVICE # undef ENABLE_NIS +#endif +#ifndef NTPSERVICE # undef ENABLE_NTP #endif diff --git a/configure.c b/configure.c index 54c733d1..8a655302 100644 --- a/configure.c +++ b/configure.c @@ -382,7 +382,7 @@ static int make_nis (const char *ifname, const dhcp_t *dhcp) fprintf (f, "# Generated by dhcpcd for interface %s\n", ifname); if (dhcp->nisdomain) { - setdomainname (dhcp->nisdomain, strlen (dhcp->nisdomain)); + setdomainname (dhcp->nisdomain, (int) strlen (dhcp->nisdomain)); if (dhcp->nisservers) snprintf (prefix, PREFIXSIZE, "domain %s server", @@ -752,7 +752,7 @@ int configure (const options_t *options, interface_t *iface, if (*newhostname) { logger (LOG_INFO, "setting hostname to `%s'", newhostname); - sethostname (newhostname, strlen (newhostname)); + sethostname (newhostname, (int) strlen (newhostname)); } free (newhostname); diff --git a/dhcp.c b/dhcp.c index 3fa93e84..f4b2fd82 100644 --- a/dhcp.c +++ b/dhcp.c @@ -79,7 +79,7 @@ static const char *dhcp_message (int type) } ssize_t send_message (const interface_t *iface, const dhcp_t *dhcp, - unsigned long xid, char type, + uint32_t xid, char type, const options_t *options) { struct udp_dhcp_packet *packet; @@ -87,13 +87,13 @@ ssize_t send_message (const interface_t *iface, const dhcp_t *dhcp, unsigned char *m; unsigned char *p; unsigned char *n_params = NULL; - unsigned long l; + size_t l; struct in_addr from; struct in_addr to; time_t up = uptime() - iface->start_uptime; uint32_t ul; uint16_t sz; - unsigned int message_length; + size_t message_length; ssize_t retval; if (!iface || !options || !dhcp) @@ -313,7 +313,7 @@ ssize_t send_message (const interface_t *iface, const dhcp_t *dhcp, memcpy (p, options->clientid, options->clientid_len); p += options->clientid_len; #ifdef ENABLE_DUID - } else if (iface->duid && options->clientid_len != -1) { + } else if (iface->duid && options->doduid) { *p++ = iface->duid_length + 5; *p++ = 255; /* RFC 4361 */ @@ -354,7 +354,7 @@ ssize_t send_message (const interface_t *iface, const dhcp_t *dhcp, from, to); free (message); - logger (LOG_DEBUG, "sending %s with xid 0x%lx", + logger (LOG_DEBUG, "sending %s with xid 0x%x", dhcp_message (type), xid); retval = send_packet (iface, ETHERTYPE_IP, (unsigned char *) packet, message_length + sizeof (struct ip) + @@ -452,13 +452,13 @@ static route_t *decode_CSR(const unsigned char *p, int len) ocets = (cidr + 7) / 8; if (ocets > 0) { - memcpy (&route->destination.s_addr, q, ocets); + memcpy (&route->destination.s_addr, q, (size_t) ocets); q += ocets; } /* Now enter the netmask */ if (ocets > 0) { - memset (&route->netmask.s_addr, 255, ocets - 1); + memset (&route->netmask.s_addr, 255, (size_t) ocets - 1); memset ((unsigned char *) &route->netmask.s_addr + (ocets - 1), (256 - (1 << (32 - cidr) % 8)), 1); @@ -534,7 +534,7 @@ static char *decode_sipservers (const unsigned char *data, int length) char *p; const char encoding = *data++; struct in_addr addr; - int len; + size_t len; length--; @@ -577,10 +577,11 @@ static char *decode_sipservers (const unsigned char *data, int length) /* This calculates the netmask that we should use for static routes. * This IS different from the calculation used to calculate the netmask * for an interface address. */ -static unsigned long route_netmask (unsigned long ip_in) +static uint32_t route_netmask (uint32_t ip_in) { - unsigned long p = ntohl (ip_in); - unsigned long t; + /* used to be unsigned long - check if error */ + uint32_t p = ntohl (ip_in); + uint32_t t; if (IN_CLASSA (p)) t = ~IN_CLASSA_NET; @@ -788,8 +789,8 @@ parse_start: #define GETSTR(_var) { \ MIN_LENGTH (sizeof (char)); \ if (_var) free (_var); \ - _var = xmalloc (length + 1); \ - memcpy (_var, p, length); \ + _var = xmalloc ((size_t) length + 1); \ + memcpy (_var, p, (size_t) length); \ memset (_var + length, 0, 1); \ } case DHCP_HOSTNAME: diff --git a/dhcp.h b/dhcp.h index ba2637cd..fb3a4402 100644 --- a/dhcp.h +++ b/dhcp.h @@ -139,10 +139,10 @@ typedef struct dhcp_t struct in_addr broadcast; unsigned short mtu; - unsigned int leasedfrom; - unsigned int leasetime; - unsigned int renewaltime; - unsigned int rebindtime; + uint32_t leasedfrom; + uint32_t leasetime; + uint32_t renewaltime; + uint32_t rebindtime; route_t *routes; @@ -209,7 +209,7 @@ struct udp_dhcp_packet }; ssize_t send_message (const interface_t *iface, const dhcp_t *dhcp, - unsigned long xid, char type, + uint32_t xid, char type, const options_t *options); void free_dhcp (dhcp_t *dhcp); int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message); diff --git a/dhcpcd.c b/dhcpcd.c index 2682108b..22746282 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -119,7 +119,7 @@ static int atoint (const char *s) return (-1); } - return (n); + return ((int) n); } static pid_t read_pid (const char *pidfile) @@ -182,6 +182,7 @@ int main(int argc, char **argv) options->daemonise = true; options->doinform = false; options->doipv4ll = true; + options->doduid = true; options->timeout = DEFAULT_TIMEOUT; gethostname (options->hostname, sizeof (options->hostname)); @@ -203,7 +204,6 @@ int main(int argc, char **argv) "option `%s' should set a flag", longopts[option_index].name); goto abort; - break; case 'c': options->script = optarg; break; @@ -258,12 +258,17 @@ int main(int argc, char **argv) sig = SIGHUP; break; case 'l': - options->leasetime = atoint (optarg); - if (options->leasetime <= 0) { + if (*optarg == '-') { logger (LOG_ERR, "leasetime must be a positive value"); goto abort; } + errno = 0; + options->leasetime = (uint32_t) strtol (optarg, NULL, 0); + if (errno == EINVAL || errno == ERANGE) { + logger (LOG_ERR, "`%s' out of range", optarg); + goto abort; + } break; case 'm': options->metric = atoint (optarg); @@ -298,8 +303,8 @@ int main(int argc, char **argv) goto abort; } } - /* fall through */ } + /* FALLTHROUGH */ case 'r': if (! options->doinform) options->dorequest = true; @@ -381,10 +386,11 @@ int main(int argc, char **argv) sizeof (options->clientid)); /* empty string disabled duid */ if (options->clientid_len == 0) - options->clientid_len = -1; + options->doduid = false; + } else { memset (options->clientid, 0, sizeof (options->clientid)); - options->clientid_len = -1; + options->doduid = false; } break; case 'L': @@ -640,4 +646,5 @@ abort: logger (LOG_INFO, "exiting"); exit (retval); + /* NOTREACHED */ } diff --git a/dhcpcd.h b/dhcpcd.h index d2e3aa86..e27c9288 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -56,12 +56,12 @@ typedef struct options_t { char hostname[MAXHOSTNAMELEN]; int fqdn; char classid[CLASS_ID_MAX_LEN]; - int classid_len; + size_t classid_len; char clientid[CLIENT_ID_MAX_LEN]; - int clientid_len; + size_t clientid_len; char userclass[USERCLASS_MAX_LEN]; - int userclass_len; - unsigned leasetime; + size_t userclass_len; + uint32_t leasetime; time_t timeout; int metric; @@ -77,6 +77,7 @@ typedef struct options_t { bool doinform; bool dorequest; bool doipv4ll; + bool doduid; int domscsr; struct in_addr request_address; diff --git a/duid.c b/duid.c index ebb5965b..aafc703d 100644 --- a/duid.c +++ b/duid.c @@ -111,7 +111,7 @@ void get_duid (interface_t *iface) if (! (fp = fopen (DUIDFILE, "w"))) logger (LOG_ERR, "fopen `%s': %s", DUIDFILE, strerror (errno)); else { - int i; + size_t i; for (i = 0; i < iface->duid_length; i++) x += fprintf (fp, "%.2X", iface->duid[i]); fprintf (fp, "\n"); diff --git a/info.c b/info.c index 51b4ac25..41ce1e90 100644 --- a/info.c +++ b/info.c @@ -211,7 +211,7 @@ bool write_info(const interface_t *iface, const dhcp_t *dhcp, free (clean); } #ifdef ENABLE_DUID - else if (iface->duid_length > 0 && options->clientid_len != -1) { + else if (iface->duid_length > 0 && options->doduid) { unsigned char *duid; unsigned char *p; uint32_t ul; @@ -233,7 +233,8 @@ bool write_info(const interface_t *iface, const dhcp_t *dhcp, memcpy (p, iface->duid, iface->duid_length); p += iface->duid_length; - fprintf (f, "CLIENTID='%s'\n", hwaddr_ntoa (duid, p - duid)); + fprintf (f, "CLIENTID='%s'\n", hwaddr_ntoa (duid, + (size_t) (p - duid))); free (duid); } #endif diff --git a/interface.c b/interface.c index 00474242..e39f7fa4 100644 --- a/interface.c +++ b/interface.c @@ -108,7 +108,7 @@ int inet_cidrtoaddr (int cidr, struct in_addr *addr) { memset (addr, 0, sizeof (struct in_addr)); if (ocets > 0) { - memset (&addr->s_addr, 255, ocets - 1); + memset (&addr->s_addr, 255, (size_t) ocets - 1); memset ((unsigned char *) &addr->s_addr + (ocets - 1), (256 - (1 << (32 - cidr) % 8)), 1); } @@ -116,9 +116,9 @@ int inet_cidrtoaddr (int cidr, struct in_addr *addr) { return (0); } -unsigned long get_netmask (unsigned long addr) +uint32_t get_netmask (uint32_t addr) { - unsigned long dst; + uint32_t dst; if (addr == 0) return (0); @@ -134,11 +134,11 @@ unsigned long get_netmask (unsigned long addr) return (0); } -char *hwaddr_ntoa (const unsigned char *hwaddr, int hwlen) +char *hwaddr_ntoa (const unsigned char *hwaddr, size_t hwlen) { static char buffer[(HWADDR_LEN * 3) + 1]; char *p = buffer; - int i; + size_t i; for (i = 0; i < hwlen && i < HWADDR_LEN; i++) { if (i > 0) @@ -152,7 +152,7 @@ char *hwaddr_ntoa (const unsigned char *hwaddr, int hwlen) } static int _do_interface (const char *ifname, - unsigned char *hwaddr, int *hwlen, + unsigned char *hwaddr, size_t *hwlen, struct in_addr *addr, bool flush, bool get) { @@ -173,7 +173,7 @@ static int _do_interface (const char *ifname, memset (&ifc, 0, sizeof (struct ifconf)); for (;;) { ifc.ifc_len = len; - ifc.ifc_buf = xmalloc (len); + ifc.ifc_buf = xmalloc ((size_t) len); if (ioctl (s, SIOCGIFCONF, &ifc) == -1) { if (errno != EINVAL || lastlen != 0) { logger (LOG_ERR, "ioctl SIOCGIFCONF: %s", @@ -227,7 +227,7 @@ static int _do_interface (const char *ifname, sizeof (struct sockaddr_dl)); *hwlen = sdl.sdl_alen; memcpy (hwaddr, sdl.sdl_data + sdl.sdl_nlen, - sdl.sdl_alen); + (size_t) sdl.sdl_alen); retval = 1; break; } @@ -275,7 +275,7 @@ interface_t *read_interface (const char *ifname, int metric) struct ifreq ifr; interface_t *iface = NULL; unsigned char *hwaddr = NULL; - int hwlen = 0; + size_t hwlen = 0; sa_family_t family = 0; unsigned short mtu; #ifdef __linux__ @@ -454,7 +454,7 @@ int set_mtu (const char *ifname, short int mtu) static void log_route (struct in_addr destination, struct in_addr netmask, struct in_addr gateway, - int metric, + __unused int metric, int change, int del) { char *dstd = xstrdup (inet_ntoa (destination)); @@ -463,7 +463,6 @@ static void log_route (struct in_addr destination, #define METRIC " metric %d" #else #define METRIC "" - metric = 0; #endif if (gateway.s_addr == destination.s_addr || @@ -576,7 +575,7 @@ static int do_route (const char *ifname, struct sockaddr_storage ss; } su; - int l; + size_t l; if (! ifname) return -1; @@ -614,7 +613,7 @@ static int do_route (const char *ifname, { /* Make us a link layer socket */ unsigned char *hwaddr; - int hwlen = 0; + size_t hwlen = 0; if (netmask.s_addr == INADDR_BROADCAST) rtm.hdr.rtm_flags |= RTF_HOST; @@ -625,10 +624,10 @@ static int do_route (const char *ifname, su.sdl.sdl_len = sizeof (struct sockaddr_dl); su.sdl.sdl_family = AF_LINK; su.sdl.sdl_nlen = strlen (ifname); - memcpy (&su.sdl.sdl_data, ifname, su.sdl.sdl_nlen); + memcpy (&su.sdl.sdl_data, ifname, (size_t) su.sdl.sdl_nlen); su.sdl.sdl_alen = hwlen; memcpy (((unsigned char *) &su.sdl.sdl_data) + su.sdl.sdl_nlen, - hwaddr, su.sdl.sdl_alen); + hwaddr, (size_t) su.sdl.sdl_alen); l = SA_SIZE (&(su.sa)); memcpy (bp, &su, l); @@ -960,10 +959,10 @@ static int do_route (const char *ifname, } #else -# error "Platform not supported!" -# error "We currently support BPF and Linux sockets." -# error "Other platforms may work using BPF. If yours does, please let me know" -# error "so I can add it to our list." + #error "Platform not supported!" + #error "We currently support BPF and Linux sockets." + #error "Other platforms may work using BPF. If yours does, please let me know" + #error "so I can add it to our list." #endif int add_address (const char *ifname, struct in_addr address, @@ -1011,7 +1010,7 @@ int flush_addresses (const char *ifname) return (_do_interface (ifname, NULL, NULL, NULL, true, false)); } -unsigned long get_address (const char *ifname) +in_addr_t get_address (const char *ifname) { struct in_addr address; if (_do_interface (ifname, NULL, NULL, &address, false, true) > 0) diff --git a/interface.h b/interface.h index a16387a1..378f4151 100644 --- a/interface.h +++ b/interface.h @@ -97,12 +97,12 @@ typedef struct interface_t char name[IF_NAMESIZE]; sa_family_t family; unsigned char hwaddr[HWADDR_LEN]; - int hwlen; + size_t hwlen; bool arpable; unsigned short mtu; int fd; - int buffer_length; + size_t buffer_length; #ifdef __linux__ int socket_protocol; @@ -119,26 +119,26 @@ typedef struct interface_t #ifdef ENABLE_DUID unsigned char duid[DUID_LEN]; - int duid_length; + size_t duid_length; #endif } interface_t; void free_address (address_t *addresses); void free_route (route_t *routes); -unsigned long get_netmask (unsigned long addr); -char *hwaddr_ntoa (const unsigned char *hwaddr, int hwlen); +uint32_t get_netmask (uint32_t addr); +char *hwaddr_ntoa (const unsigned char *hwaddr, size_t hwlen); interface_t *read_interface (const char *ifname, int metric); int get_mtu (const char *ifname); int set_mtu (const char *ifname, short int mtu); int add_address (const char *ifname, struct in_addr address, - struct in_addr netmask, struct in_addr broadcast); + struct in_addr netmask, struct in_addr broadcast); int del_address (const char *ifname, struct in_addr address, struct in_addr netmask); int flush_addresses (const char *ifname); -unsigned long get_address (const char *ifname); +in_addr_t get_address (const char *ifname); int has_address (const char *ifname, struct in_addr address); int add_route (const char *ifname, struct in_addr destination, diff --git a/ipv4ll.c b/ipv4ll.c index 31948b3c..9742b9a7 100644 --- a/ipv4ll.c +++ b/ipv4ll.c @@ -35,7 +35,7 @@ #ifdef ENABLE_IPV4LL #ifndef ENABLE_ARP -#error IPV4LL requires ARP + # error IPV4LL requires ARP #endif #define IPV4LL_LEASETIME 20 @@ -45,7 +45,8 @@ int ipv4ll_get_address (interface_t *iface, dhcp_t *dhcp) { for (;;) { addr.s_addr = htonl (LINKLOCAL_ADDR | - ((abs (random ()) % 0xFD00) + 0x0100)); + (((uint32_t) abs ((int) random ()) + % 0xFD00) + 0x0100)); errno = 0; if (! arp_claim (iface, addr)) break; diff --git a/logger.c b/logger.c index 341a31d4..99f845f4 100644 --- a/logger.c +++ b/logger.c @@ -96,8 +96,8 @@ void logger (int level, const char *fmt, ...) } if (level < LOG_DEBUG || level <= loglevel) { - int len = strlen (logprefix); - int fmt2len = strlen (fmt) + len + 1; + size_t len = strlen (logprefix); + size_t fmt2len = strlen (fmt) + len + 1; char *fmt2 = malloc (sizeof (char) * fmt2len); char *pf = fmt2; if (fmt2) { diff --git a/logger.h b/logger.h index 89e7e446..aa91eb86 100644 --- a/logger.h +++ b/logger.h @@ -30,6 +30,8 @@ #ifdef __GNUC__ # define _PRINTF_LIKE(_one, _two) __attribute__ ((__format__ (__printf__, _one, _two))) +#else +# define _PRINTF_LIKE(_one, _two) #endif #include diff --git a/mk/prog.mk b/mk/prog.mk index 9fdb9d8a..a7cb22eb 100644 --- a/mk/prog.mk +++ b/mk/prog.mk @@ -25,3 +25,9 @@ install: _proginstall maninstall clean: rm -f ${OBJS} ${PROG} ${CLEANFILES} + +LINTFLAGS?= -hx +LINTFLAGS+= -X 159,247,352 + +lint: ${SRCS:.c=.c} + ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} $^ ${.ALLSRC} diff --git a/socket.c b/socket.c index 8aa05539..91303ac0 100644 --- a/socket.c +++ b/socket.c @@ -86,7 +86,7 @@ static uint16_t checksum (unsigned char *addr, uint16_t len) } void make_dhcp_packet(struct udp_dhcp_packet *packet, - const unsigned char *data, int length, + const unsigned char *data, size_t length, struct in_addr source, struct in_addr dest) { struct ip *ip = &packet->ip; @@ -309,7 +309,7 @@ int open_socket (interface_t *iface, bool arp) } ssize_t send_packet (const interface_t *iface, int type, - const unsigned char *data, int len) + const unsigned char *data, size_t len) { ssize_t retval = -1; struct iovec iov[2]; @@ -338,7 +338,8 @@ ssize_t send_packet (const interface_t *iface, int type, /* BPF requires that we read the entire buffer. So we pass the buffer in the API so we can loop on >1 dhcp packet. */ ssize_t get_packet (const interface_t *iface, unsigned char *data, - unsigned char *buffer, int *buffer_len, int *buffer_pos) + unsigned char *buffer, + size_t *buffer_len, size_t *buffer_pos) { union { @@ -364,13 +365,14 @@ ssize_t get_packet (const interface_t *iface, unsigned char *data, bpf.buffer += *buffer_pos; while (bpf.packet) { - ssize_t len = -1; + size_t len = 0; union { unsigned char *buffer; struct ether_header *hw; } hdr; unsigned char *payload; + bool have_data = false; /* Ensure that the entire packet is in our buffer */ if (*buffer_pos + bpf.packet->bh_hdrlen + bpf.packet->bh_caplen @@ -385,6 +387,7 @@ ssize_t get_packet (const interface_t *iface, unsigned char *data, len = bpf.packet->bh_caplen - sizeof (struct ether_header); memcpy (data, payload, len); + have_data = true; } else { if (valid_dhcp_packet (payload) >= 0) { union @@ -397,18 +400,19 @@ ssize_t get_packet (const interface_t *iface, unsigned char *data, sizeof (struct ip) - sizeof (struct udphdr); memcpy (data, &pay.packet->dhcp, len); + have_data = true; } } /* Update the buffer_pos pointer */ bpf.buffer += BPF_WORDALIGN (bpf.packet->bh_hdrlen + bpf.packet->bh_caplen); - if (bpf.buffer - buffer < *buffer_len) + if ((unsigned) (bpf.buffer - buffer) < *buffer_len) *buffer_pos = bpf.buffer - buffer; else *buffer_pos = 0; - if (len != -1) + if (have_data) return len; if (*buffer_pos == 0) @@ -478,8 +482,8 @@ int open_socket (interface_t *iface, bool arp) return fd; } -ssize_t send_packet (const interface_t *iface, const int type, - const unsigned char *data, const int len) +ssize_t send_packet (const interface_t *iface, int type, + const unsigned char *data, size_t len) { union sockunion { struct sockaddr sa; @@ -512,7 +516,8 @@ ssize_t send_packet (const interface_t *iface, const int type, /* 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. */ ssize_t get_packet (const interface_t *iface, unsigned char *data, - unsigned char *buffer, int *buffer_len, int *buffer_pos) + unsigned char *buffer, + size_t *buffer_len, size_t *buffer_pos) { ssize_t bytes; union @@ -578,8 +583,8 @@ ssize_t get_packet (const interface_t *iface, unsigned char *data, } #else -# error "Platform not supported!" -# error "We currently support BPF and Linux sockets." -# error "Other platforms may work using BPF. If yours does, please let me know" -# error "so I can add it to our list." + #error "Platform not supported!" + #error "We currently support BPF and Linux sockets." + #error "Other platforms may work using BPF. If yours does, please let me know" + #error "so I can add it to our list." #endif diff --git a/socket.h b/socket.h index 981225e2..1ad890cd 100644 --- a/socket.h +++ b/socket.h @@ -34,12 +34,12 @@ #include "interface.h" void make_dhcp_packet(struct udp_dhcp_packet *packet, - const unsigned char *data, int length, + const unsigned char *data, size_t length, struct in_addr source, struct in_addr dest); int open_socket (interface_t *iface, bool arp); ssize_t send_packet (const interface_t *iface, int type, - const unsigned char *data, int len); + const unsigned char *data, size_t len); ssize_t get_packet (const interface_t *iface, unsigned char *data, - unsigned char *buffer, int *buffer_len, int *buffer_pos); + unsigned char *buffer, size_t *buffer_len, size_t *buffer_pos); #endif