acct_init_localnet(const char *spec)
{
char **tokens;
- int num_tokens, isnum, j, ret;
+ unsigned int num_tokens;
+ int isnum, j, ret;
int pfxlen, octets, remainder;
struct addr localnet, localmask;
localmask.family = localnet.family;
/* Compute the prefix length. */
- pfxlen = strtonum(tokens[1], 1,
- (localnet.family == IPv6) ? 128 : 32, NULL);
+ pfxlen = (int)strtonum(tokens[1], 1,
+ (localnet.family == IPv6) ? 128 : 32, NULL);
+
if (pfxlen == 0)
errx(1, "invalid network prefix length \"%s\"", tokens[1]);
for (j = 0; j < octets; ++j)
p[j] = 0xff;
- frac = 0xff << (8 - remainder);
+ frac = (uint8_t)(0xff << (8 - remainder));
if (frac)
p[j] = frac; /* Have contribution for next position. */
}
* num_chunks = 2, chunks = { "one", "two", NULL }
*/
char **
-split(const char delimiter, const char *str, int *num_chunks)
+split(const char delimiter, const char *str, unsigned int *num_chunks)
{
- int num = 0;
+ unsigned int num = 0;
char **chunks = NULL;
size_t left, right = 0;
verbosef("parent waiting");
if (close(lifeline[1]) == -1)
warn("close lifeline in parent");
- read(lifeline[0], tmp, sizeof(tmp));
+ if (read(lifeline[0], tmp, sizeof(tmp)) != 0) /* expecting EOF */
+ err(1, "lifeline read() failed");
verbosef("parent done reading, calling waitpid");
w = waitpid(f, &status, WNOHANG);
verbosef("waitpid ret %d, status is %d", w, status);
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
-size_t strlcpy(dst, src, siz)
- char *dst;
- const char *src;
- size_t siz;
+size_t
+strlcpy(char * restrict dst, const char * restrict src, const size_t siz)
{
char *d = dst;
const char *s = src;
;
}
- return(s - src - 1); /* count does not include NUL */
+ return (size_t)(s - src - 1); /* count does not include NUL */
}
#endif
* If retval >= siz, truncation occurred.
*/
size_t
-strlcat(dst, src, siz)
- char *dst;
- const char *src;
- size_t siz;
+strlcat(char * restrict dst, const char * restrict src, const size_t siz)
{
char *d = dst;
const char *s = src;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
- dlen = d - dst;
+ dlen = (size_t)(d - dst);
n = siz - dlen;
if (n == 0)
}
*d = '\0';
- return(dlen + (s - src)); /* count does not include NUL */
+ return (dlen + (size_t)(s - src)); /* count does not include NUL */
}
#endif
char *split_string(const char *src, const size_t left, const size_t right);
void strntoupper(char *str, const size_t length);
int str_starts_with(const char *haystack, const char *needle);
-char**split(const char delimiter, const char *str, int *num_chunks);
+char**split(const char delimiter, const char *str, unsigned int *num_chunks);
char *qs_get(const char *qs, const char *key);
void daemonize_start(void);
static void cb_capfile(const char *arg) { capfile = arg; }
int want_snaplen = -1;
-static void cb_snaplen(const char *arg) { want_snaplen = parsenum(arg, 0); }
+static void cb_snaplen(const char *arg)
+{ want_snaplen = (int)parsenum(arg, 0); }
int want_pppoe = 0;
static void cb_pppoe(const char *arg _unused_) { want_pppoe = 1; }
static void cb_no_lastseen(const char *arg _unused_) { want_lastseen = 0; }
unsigned short bindport = 667;
-static void cb_port(const char *arg) { bindport = parsenum(arg, 65536); }
+static void cb_port(const char *arg)
+{ bindport = (unsigned short)parsenum(arg, 65536); }
const char *bindaddr = NULL;
static void cb_bindaddr(const char *arg)
int wait_secs = -1;
static void cb_wait_secs(const char *arg)
-{ wait_secs = parsenum(arg, 0); }
+{ wait_secs = (int)parsenum(arg, 0); }
int want_hexdump = 0;
static void cb_hexdump(const char *arg _unused_) { want_hexdump = 1; }
#ifdef __GNUC__
# define _unused_ __attribute__((__unused__))
# define _noreturn_ __attribute__((__noreturn__))
+# define _printflike_(fmtarg, firstvararg) \
+ __attribute__((__format__ (__printf__, fmtarg, firstvararg) ))
#else
# define _unused_
# define _noreturn_
+# define _printflike_(fmtarg, firstvararg)
#endif
#if __GNUC__ == 2
# endif
#endif
+#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
+#define restrict __restrict
+#endif
+
#ifndef max
# define max(a,b) ((a) > (b) ? (a) : (b))
#endif
int
getsnaplen(const struct linkhdr *lh)
{
- assert(lh != NULL);
- /* TODO MEA Investigate why the supplementary value 20 is needed on GNU/Linux. */
- return (20 + lh->hdrlen + IPV6_HDR_LEN + max(TCP_HDR_LEN, UDP_HDR_LEN));
+ return (int)(lh->hdrlen + IPV6_HDR_LEN + max(TCP_HDR_LEN, UDP_HDR_LEN));
}
/* Decoding functions. */
#include <string.h>
#include <unistd.h>
-static void dns_main(void); /* this is what the child process runs */
+static void dns_main(void) _noreturn_; /* the child process runs this */
#define CHILD 0 /* child process uses this socket */
#define PARENT 1
#include <unistd.h>
#include <unistd.h>
+static void to_syslog(const char *type, const int want_err,
+ const char *format, va_list va) _printflike_(3, 0);
+
static void
to_syslog(const char *type, const int want_err,
const char *format, va_list va)
#include "darkstat.h"
-void err(const int code, const char *format, ...) _noreturn_;
-void errx(const int code, const char *format, ...) _noreturn_;
+void err(const int code, const char *format, ...)
+ _noreturn_ _printflike_(2, 3);
+void errx(const int code, const char *format, ...)
+ _noreturn_ _printflike_(2, 3);
-void warn(const char *format, ...);
-void warnx(const char *format, ...);
+void warn(const char *format, ...) _printflike_(1, 2);
+void warnx(const char *format, ...) _printflike_(1, 2);
extern int want_verbose, want_syslog;
-void verbosef(const char *format, ...);
+void verbosef(const char *format, ...) _printflike_(1, 2);
void dverbosef(const char *format _unused_, ...);
/* vim:set ts=3 sw=3 tw=78 expandtab: */
struct str *
html_hosts(const char *uri, const char *query)
{
- int i, num_elems;
+ unsigned int i, num_elems;
char **elem = split('/', uri, &num_elems);
struct str *buf = NULL;
* Format hashtable into HTML.
*/
static void
-format_table(struct str *buf, struct hashtable *ht, int start,
+format_table(struct str *buf, struct hashtable *ht, unsigned int start,
const enum sort_dir sort, const int full)
{
const struct bucket **table;
- uint32_t i, pos, end;
+ unsigned int i, pos, end;
int alt = 0;
if ((ht == NULL) || (ht->count == 0)) {
sortstr = qs_sort;
if (sortstr == NULL) sortstr = "total";
if (start > 0) {
- int prev = max(start - MAX_ENTRIES, 0);
+ int prev = start - MAX_ENTRIES;
+ if (prev < 0)
+ prev = 0;
str_appendf(buf, "<a href=\"?start=%d&sort=%s\">" PREV "</a>",
prev, sortstr);
} else