The following commit has been merged in the next branch: commit 927399e7d54686679f4205241bdc4107b7559a93 Author: Marek Lindner lindner_marek@yahoo.de Date: Fri Dec 10 12:38:18 2010 +0100
batctl: suppress bat-host parser warning when bat-hosts are to be ignored
Signed-off-by: Marek Lindner lindner_marek@yahoo.de
diff --git a/bat-hosts.c b/bat-hosts.c index 888b997..c952744 100644 --- a/bat-hosts.c +++ b/bat-hosts.c @@ -32,6 +32,7 @@ #include "main.h" #include "bat-hosts.h" #include "hash.h" +#include "functions.h"
static struct hashtable_t *host_hash = NULL; @@ -62,7 +63,7 @@ static int choose_mac(void *data, int32_t size) return (hash % size); }
-static void parse_hosts_file(struct hashtable_t **hash, const char path[]) +static void parse_hosts_file(struct hashtable_t **hash, const char path[], int read_opt) { FILE *fd; char *line_ptr = NULL; @@ -84,13 +85,15 @@ static void parse_hosts_file(struct hashtable_t **hash, const char path[]) continue;
if (sscanf(line_ptr, "%17[^ \t]%49s\n", mac_str, name) != 2) { - fprintf(stderr, "Warning - unrecognized bat-host definition: %s", line_ptr); + if (read_opt & USE_BAT_HOSTS) + fprintf(stderr, "Warning - unrecognized bat-host definition: %s", line_ptr); continue; }
mac_addr = ether_aton(mac_str); if (!mac_addr) { - fprintf(stderr, "Warning - invalid mac address in '%s' detected: %s\n", path, mac_str); + if (read_opt & USE_BAT_HOSTS) + fprintf(stderr, "Warning - invalid mac address in '%s' detected: %s\n", path, mac_str); continue; }
@@ -102,7 +105,8 @@ static void parse_hosts_file(struct hashtable_t **hash, const char path[]) if (strcmp(bat_host->name, name) == 0) continue;
- fprintf(stderr, "Warning - mac already known (changing name from '%s' to '%s'): %s\n", + if (read_opt & USE_BAT_HOSTS) + fprintf(stderr, "Warning - mac already known (changing name from '%s' to '%s'): %s\n", bat_host->name, name, mac_str); strncpy(bat_host->name, name, HOST_NAME_MAX_LEN - 1); continue; @@ -112,7 +116,8 @@ static void parse_hosts_file(struct hashtable_t **hash, const char path[])
/* name entry already exists - we found a new mac address for it */ if (bat_host) { - fprintf(stderr, "Warning - name already known (changing mac from '%s' to '%s'): %s\n", + if (read_opt & USE_BAT_HOSTS) + fprintf(stderr, "Warning - name already known (changing mac from '%s' to '%s'): %s\n", ether_ntoa(&bat_host->mac_addr), mac_str, name); hash_remove(*hash, bat_host); free(bat_host); @@ -121,7 +126,8 @@ static void parse_hosts_file(struct hashtable_t **hash, const char path[]) bat_host = malloc(sizeof(struct bat_host));
if (!bat_host) { - fprintf(stderr, "Error - could not allocate memory: %s\n", strerror(errno)); + if (read_opt & USE_BAT_HOSTS) + fprintf(stderr, "Error - could not allocate memory: %s\n", strerror(errno)); goto out; }
@@ -133,10 +139,10 @@ static void parse_hosts_file(struct hashtable_t **hash, const char path[]) if ((*hash)->elements * 4 > (*hash)->size) { swaphash = hash_resize((*hash), (*hash)->size * 2);
- if (swaphash == NULL) - fprintf(stderr, "Warning - couldn't resize bat hosts hash table\n"); - else + if (swaphash) *hash = swaphash; + else if (read_opt & USE_BAT_HOSTS) + fprintf(stderr, "Warning - couldn't resize bat hosts hash table\n"); } }
@@ -148,7 +154,7 @@ out: return; }
-void bat_hosts_init(void) +void bat_hosts_init(int read_opt) { unsigned int i, j, parse; char confdir[CONF_DIR_LEN]; @@ -162,7 +168,8 @@ void bat_hosts_init(void) */ normalized = malloc(locations * PATH_MAX); if (!normalized) { - printf("Warning - could not get memory for bat-hosts file parsing\n"); + if (read_opt & USE_BAT_HOSTS) + printf("Warning - could not get memory for bat-hosts file parsing\n"); return; }
@@ -170,7 +177,8 @@ void bat_hosts_init(void) host_hash = hash_new(64, compare_mac, choose_mac);
if (!host_hash) { - printf("Warning - could not create bat hosts hash table\n"); + if (read_opt & USE_BAT_HOSTS) + printf("Warning - could not create bat hosts hash table\n"); return; }
@@ -205,7 +213,7 @@ void bat_hosts_init(void) }
if (parse) - parse_hosts_file(&host_hash, normalized + (i * PATH_MAX)); + parse_hosts_file(&host_hash, normalized + (i * PATH_MAX), read_opt); }
free(normalized); diff --git a/bat-hosts.h b/bat-hosts.h index 0f019f9..fdec7df 100644 --- a/bat-hosts.h +++ b/bat-hosts.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2009-2010 B.A.T.M.A.N. contributors: * * Marek Lindner lindner_marek@yahoo.de @@ -35,7 +35,7 @@ struct bat_host { char name[HOST_NAME_MAX_LEN]; } __attribute__((packed));
-void bat_hosts_init(void); +void bat_hosts_init(int read_opt); struct bat_host *bat_hosts_find_by_name(char *name); struct bat_host *bat_hosts_find_by_mac(char *mac); void bat_hosts_free(void); diff --git a/bisect.c b/bisect.c index bdb51a8..e0bb7cb 100644 --- a/bisect.c +++ b/bisect.c @@ -1520,7 +1520,7 @@ int bisect(int argc, char **argv) goto err; }
- bat_hosts_init(); + bat_hosts_init(read_opt); num_parsed_files = 0;
if ((rt_orig_ptr) && (trace_orig_ptr)) { diff --git a/functions.c b/functions.c index 52cfe4b..ba9bfbb 100644 --- a/functions.c +++ b/functions.c @@ -129,7 +129,7 @@ int read_file(char *dir, char *fname, int read_opt, FILE *fp = NULL;
if (read_opt & USE_BAT_HOSTS) - bat_hosts_init(); + bat_hosts_init(read_opt);
if (strstr(dir, "/sys/")) { if (check_sys_dir(dir) != EXIT_SUCCESS) @@ -178,7 +178,7 @@ read: extra_char = '\0';
if (strlen(buff_ptr) == ETH_STR_LEN + 1) { - extra_char = buff_ptr[ETH_STR_LEN]; + extra_char = buff_ptr[ETH_STR_LEN]; switch (extra_char) { case ',': case ')': diff --git a/ping.c b/ping.c index ef5d2af..f794b01 100644 --- a/ping.c +++ b/ping.c @@ -124,7 +124,7 @@ int ping(char *mesh_iface, int argc, char **argv) }
dst_string = argv[found_args]; - bat_hosts_init(); + bat_hosts_init(0); bat_host = bat_hosts_find_by_name(dst_string);
if (bat_host) diff --git a/tcpdump.c b/tcpdump.c index 08a662a..4bff970 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -497,7 +497,7 @@ int tcpdump(int argc, char **argv) return EXIT_FAILURE; }
- bat_hosts_init(); + bat_hosts_init(read_opt);
/* init interfaces list */ INIT_LIST_HEAD_FIRST(dump_if_list); diff --git a/traceroute.c b/traceroute.c index f80ca4d..1d2ac1f 100644 --- a/traceroute.c +++ b/traceroute.c @@ -86,7 +86,7 @@ int traceroute(char *mesh_iface, int argc, char **argv) }
dst_string = argv[found_args]; - bat_hosts_init(); + bat_hosts_init(read_opt); bat_host = bat_hosts_find_by_name(dst_string);
if (bat_host) diff --git a/vis.c b/vis.c index 7fba1ab..217fc1c 100644 --- a/vis.c +++ b/vis.c @@ -302,7 +302,7 @@ int vis_data(char *mesh_iface, int argc, char *argv[]) }
if (with_names) - bat_hosts_init(); + bat_hosts_init(USE_BAT_HOSTS);
if (dot) return format(mesh_iface, &dot_funcs);