summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpdw <>2014-01-05 20:02:51 +0000
committerpdw <>2014-01-05 20:02:51 +0000
commit836733ba143c8dd4032934297460cccf46d3c018 (patch)
tree0cc3ff12a5abab6a62248ce6adcb1d5a365c6a5b
parenta7b8639fc91b95a36ccab85eac2c5e328695887f (diff)
downloadiftop-836733ba143c8dd4032934297460cccf46d3c018.zip
Fixes for a bunch of compiler warnings.
-rw-r--r--addr_hash.c1
-rw-r--r--addrs_ioctl.c23
-rw-r--r--cfgfile.c4
-rw-r--r--cfgfile.h2
-rw-r--r--iftop.c8
-rw-r--r--options.c73
-rw-r--r--options.h2
-rw-r--r--tui.c1
-rw-r--r--ui.c2
-rw-r--r--ui_common.c1
10 files changed, 22 insertions, 95 deletions
diff --git a/addr_hash.c b/addr_hash.c
index 70e5ff1..f5c002c 100644
--- a/addr_hash.c
+++ b/addr_hash.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "addr_hash.h"
#include "hash.h"
#include "iftop.h"
diff --git a/addrs_ioctl.c b/addrs_ioctl.c
index 3c1a0ac..870c83b 100644
--- a/addrs_ioctl.c
+++ b/addrs_ioctl.c
@@ -90,28 +90,23 @@ get_addrs_ioctl(char *interface, char if_hw_addr[], struct in_addr *if_ip_addr,
sysctlparam[5] = if_nametoindex(interface);
if (sysctlparam[5] == 0) {
fprintf(stderr, "Error getting hardware address for interface: %s\n", interface);
- goto ENDHWADDR;
}
- if (sysctl(sysctlparam, 6, NULL, &needed, NULL, 0) < 0) {
+ else if (sysctl(sysctlparam, 6, NULL, &needed, NULL, 0) < 0) {
fprintf(stderr, "Error getting hardware address for interface: %s\n", interface);
- goto ENDHWADDR;
}
- if ((buf = malloc(needed)) == NULL) {
+ else if ((buf = malloc(needed)) == NULL) {
fprintf(stderr, "Error getting hardware address for interface: %s\n", interface);
- goto ENDHWADDR;
}
- if (sysctl(sysctlparam, 6, buf, &needed, NULL, 0) < 0) {
+ else if (sysctl(sysctlparam, 6, buf, &needed, NULL, 0) < 0) {
fprintf(stderr, "Error getting hardware address for interface: %s\n", interface);
free(buf);
- goto ENDHWADDR;
}
- msghdr = (struct if_msghdr *) buf;
- memcpy(if_hw_addr, LLADDR((struct sockaddr_dl *)(buf + sizeof(struct if_msghdr) - sizeof(struct if_data) + sizeof(struct if_data))), 6);
- free(buf);
- got_hw_addr = 1;
-
- ENDHWADDR:
- 1; /* compiler whines if there is a label at the end of a block...*/
+ else {
+ msghdr = (struct if_msghdr *) buf;
+ memcpy(if_hw_addr, LLADDR((struct sockaddr_dl *)(buf + sizeof(struct if_msghdr) - sizeof(struct if_data) + sizeof(struct if_data))), 6);
+ free(buf);
+ got_hw_addr = 1;
+ }
}
#else
fprintf(stderr, "Cannot obtain hardware address on this platform\n");
diff --git a/cfgfile.c b/cfgfile.c
index ad1edc8..fa50c9e 100644
--- a/cfgfile.c
+++ b/cfgfile.c
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <stdlib.h>
#include "stringmap.h"
#include "iftop.h"
@@ -169,7 +170,6 @@ int config_get_int(const char *directive, int *value) {
* failure, or 0 if no value was found. */
int config_get_float(const char *directive, float *value) {
stringmap S;
- item *I;
char *s, *t;
if (!value) return -1;
@@ -245,7 +245,5 @@ void config_set_string(const char *directive, const char* s) {
}
int read_config(char *file, int whinge_on_error) {
- void* o;
-
return read_config_file(file, whinge_on_error);
}
diff --git a/cfgfile.h b/cfgfile.h
index 38532ad..11ba475 100644
--- a/cfgfile.h
+++ b/cfgfile.h
@@ -20,6 +20,8 @@ int config_get_bool(const char *directive);
int config_get_int(const char *directive, int *value);
int config_get_float(const char *directive, float *value);
int config_init();
+void config_set_string(const char *directive, const char* s);
+int config_get_enum(const char *directive, config_enumeration_type *enumeration, int *value);
diff --git a/iftop.c b/iftop.c
index e58fbb4..42fca2f 100644
--- a/iftop.c
+++ b/iftop.c
@@ -49,12 +49,13 @@
#include "ethertype.h"
#include "cfgfile.h"
#include "ppp.h"
+#include "addrs_ioctl.h"
#include <netinet/ip6.h>
/* ethernet address of interface. */
int have_hw_addr = 0;
-unsigned char if_hw_addr[6];
+char if_hw_addr[6];
/* IP address of interface */
int have_ip_addr = 0;
@@ -498,9 +499,9 @@ static void handle_llc_packet(const struct llc* llc, int dir) {
if(llc->ssap == LLCSAP_SNAP && llc->dsap == LLCSAP_SNAP
&& llc->llcui == LLC_UI) {
u_int32_t orgcode;
- register u_short et;
+ u_int16_t et;
orgcode = EXTRACT_24BITS(&llc->llc_orgcode[0]);
- et = EXTRACT_16BITS(&llc->llc_ethertype[0]);
+ et = (llc->llc_ethertype[0] << 8) + llc->llc_ethertype[1];
switch(orgcode) {
case OUI_ENCAP_ETHER:
case OUI_CISCO_90:
@@ -679,7 +680,6 @@ char *set_filter_code(const char *filter) {
void packet_init() {
char errbuf[PCAP_ERRBUF_SIZE];
char *m;
- int s;
int i;
int dlt;
int result;
diff --git a/options.c b/options.c
index d067cbc..66a1494 100644
--- a/options.c
+++ b/options.c
@@ -173,79 +173,6 @@ void options_set_defaults() {
}
-static void die(char *msg) {
- fprintf(stderr, "%s", msg);
- exit(1);
-}
-
-static void set_max_bandwidth(char* arg) {
- char* units;
- long long mult = 1;
- long long value;
- units = arg + strspn(arg, "0123456789");
- if(strlen(units) > 1) {
- die("Invalid units\n");
- }
- if(strlen(units) == 1) {
- if(*units == 'k' || *units == 'K') {
- mult = 1024;
- }
- else if(*units == 'm' || *units == 'M') {
- mult = 1024 * 1024;
- }
- else if(*units == 'g' || *units == 'G') {
- mult = 1024 * 1024 * 1024;
- }
- }
- *units = '\0';
- if(sscanf(arg, "%lld", &value) != 1) {
- die("Error reading max bandwidth\n");
- }
- options.max_bandwidth = value * mult;
-}
-
-static void set_net_filter(char* arg) {
- char* mask;
-
- mask = strchr(arg, '/');
- if (mask == NULL) {
- die("Could not parse net/mask\n");
- }
- *mask = '\0';
- mask++;
- if (inet_aton(arg, &options.netfilternet) == 0)
- die("Invalid network address\n");
- /* Accept a netmask like /24 or /255.255.255.0. */
- if (mask[strspn(mask, "0123456789")] == '\0') {
- /* Whole string is numeric */
- int n;
- n = atoi(mask);
- if (n > 32) {
- die("Invalid netmask");
- }
- else {
- if(n == 32) {
- /* This needs to be special cased, although I don't fully
- * understand why -pdw
- */
- options.netfiltermask.s_addr = htonl(0xffffffffl);
- }
- else {
- u_int32_t mm = 0xffffffffl;
- mm >>= n;
- options.netfiltermask.s_addr = htonl(~mm);
- }
- }
- }
- else if (inet_aton(mask, &options.netfiltermask) == 0) {
- die("Invalid netmask\n");
- }
- options.netfilternet.s_addr = options.netfilternet.s_addr & options.netfiltermask.s_addr;
-
- options.netfilter = 1;
-
-}
-
/* usage:
* Print usage information. */
static void usage(FILE *fp) {
diff --git a/options.h b/options.h
index 86620d9..8526254 100644
--- a/options.h
+++ b/options.h
@@ -96,5 +96,7 @@ typedef struct {
void options_set_defaults();
void options_read(int argc, char **argv);
+void options_read_args(int argc, char **argv);
+void options_make();
#endif /* __OPTIONS_H_ */
diff --git a/tui.c b/tui.c
index 896451e..31d4109 100644
--- a/tui.c
+++ b/tui.c
@@ -13,6 +13,7 @@
#include <string.h>
#include <stdio.h>
#include <signal.h>
+#include <stdlib.h>
#include <unistd.h>
#if defined(HAVE_TERMIOS_H)
diff --git a/ui.c b/ui.c
index b85d63e..1ec458e 100644
--- a/ui.c
+++ b/ui.c
@@ -177,7 +177,7 @@ static void draw_bar_scale(int* y) {
void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t linedisplay, int bytes) {
char buf[10];
- float n;
+ float n = 0;
switch(linedisplay) {
case OPTION_LINEDISPLAY_TWO_LINE:
draw_line_total(sent, recv, y, x, OPTION_LINEDISPLAY_ONE_LINE_SENT, bytes);
diff --git a/ui_common.c b/ui_common.c
index 803448e..8cb1e22 100644
--- a/ui_common.c
+++ b/ui_common.c
@@ -6,6 +6,7 @@
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#include "addr_hash.h"
#include "serv_hash.h"