Project

General

Profile

Bug #167 » errors_to_stderr.patch

M W, 12/04/2012 12:22 PM

View differences:

bisect_iv.c
37 37

  
38 38
static void bisect_iv_usage(void)
39 39
{
40
	printf("Usage: batctl bisect_iv [parameters] <file1> <file2> .. <fileN>\n");
41
	printf("parameters:\n");
42
	printf(" \t -h print this help\n");
43
	printf(" \t -l run a loop detection of given mac address or bat-host (default)\n");
44
	printf(" \t -n don't convert addresses to bat-host names\n");
45
	printf(" \t -o only display orig events that affect given mac address or bat-host\n");
46
	printf(" \t -r print routing tables of given mac address or bat-host\n");
47
	printf(" \t -s seqno range to limit the output\n");
48
	printf(" \t -t trace seqnos of given mac address or bat-host\n");
40
	fprintf(stderr, "Usage: batctl bisect_iv [parameters] <file1> <file2> .. <fileN>\n");
41
	fprintf(stderr, "parameters:\n");
42
	fprintf(stderr, " \t -h print this help\n");
43
	fprintf(stderr, " \t -l run a loop detection of given mac address or bat-host (default)\n");
44
	fprintf(stderr, " \t -n don't convert addresses to bat-host names\n");
45
	fprintf(stderr, " \t -o only display orig events that affect given mac address or bat-host\n");
46
	fprintf(stderr, " \t -r print routing tables of given mac address or bat-host\n");
47
	fprintf(stderr, " \t -s seqno range to limit the output\n");
48
	fprintf(stderr, " \t -t trace seqnos of given mac address or bat-host\n");
49 49
}
50 50

  
51 51
static int compare_name(void *data1, void *data2)
......
1425 1425
	orig_mac = ether_aton(orig_name_tmp);
1426 1426

  
1427 1427
	if (!orig_mac) {
1428
		printf("Error - the originator is not a mac address or bat-host name: %s\n", orig_name);
1428
		fprintf(stderr, "Error - the originator is not a mac address or bat-host name: %s\n", orig_name);
1429 1429
		goto err;
1430 1430
	}
1431 1431

  
......
1509 1509
	}
1510 1510

  
1511 1511
	if (argc <= found_args + 1) {
1512
		printf("Error - need at least 2 log files to compare\n");
1512
		fprintf(stderr, "Error - need at least 2 log files to compare\n");
1513 1513
		bisect_iv_usage();
1514 1514
		goto err;
1515 1515
	}
......
1517 1517
	node_hash = hash_new(64, compare_name, choose_name);
1518 1518

  
1519 1519
	if (!node_hash) {
1520
		printf("Error - could not create node hash table\n");
1520
		fprintf(stderr, "Error - could not create node hash table\n");
1521 1521
		goto err;
1522 1522
	}
1523 1523

  
......
1525 1525
	num_parsed_files = 0;
1526 1526

  
1527 1527
	if ((rt_orig_ptr) && (trace_orig_ptr)) {
1528
		printf("Error - the 'print routing table' option can't be used together with the the 'trace seqno' option\n");
1528
		fprintf(stderr, "Error - the 'print routing table' option can't be used together with the the 'trace seqno' option\n");
1529 1529
		goto err;
1530 1530
	} else if ((loop_orig_ptr) && (trace_orig_ptr)) {
1531
		printf("Error - the 'loop detection' option can't be used together with the the 'trace seqno' option\n");
1531
		fprintf(stderr, "Error - the 'loop detection' option can't be used together with the the 'trace seqno' option\n");
1532 1532
		goto err;
1533 1533
	} else if ((loop_orig_ptr) && (rt_orig_ptr)) {
1534
		printf("Error - the 'loop detection' option can't be used together with the the 'print routing table' option\n");
1534
		fprintf(stderr, "Error - the 'loop detection' option can't be used together with the the 'print routing table' option\n");
1535 1535
		goto err;
1536 1536
	} else if (rt_orig_ptr) {
1537 1537
		res = get_orig_addr(rt_orig_ptr, orig);
......
1555 1555
		seqno_max = seqno_min;
1556 1556

  
1557 1557
	if (seqno_min > seqno_max) {
1558
		printf("Error - the sequence range minimum (%lli) should be smaller than the maximum (%lli)\n",
1558
		fprintf(stderr, "Error - the sequence range minimum (%lli) should be smaller than the maximum (%lli)\n",
1559 1559
		       seqno_min, seqno_max);
1560 1560
		goto err;
1561 1561
	}
......
1577 1577
	}
1578 1578

  
1579 1579
	if (num_parsed_files < 2) {
1580
		printf("Error - need at least 2 log files to compare\n");
1580
		fprintf(stderr, "Error - need at least 2 log files to compare\n");
1581 1581
		goto err;
1582 1582
	}
1583 1583

  
debug.c
80 80

  
81 81
void debug_table_usage(int debug_table)
82 82
{
83
	printf("Usage: batctl [options] %s|%s [parameters]\n",
83
	fprintf(stderr, "Usage: batctl [options] %s|%s [parameters]\n",
84 84
	       batctl_debug_tables[debug_table].opt_long, batctl_debug_tables[debug_table].opt_short);
85
	printf("parameters:\n");
86
	printf(" \t -h print this help\n");
87
	printf(" \t -n don't replace mac addresses with bat-host names\n");
88
	printf(" \t -H don't show the header\n");
89
	printf(" \t -w [interval] watch mode - refresh the table continuously\n");
85
	fprintf(stderr, "parameters:\n");
86
	fprintf(stderr, " \t -h print this help\n");
87
	fprintf(stderr, " \t -n don't replace mac addresses with bat-host names\n");
88
	fprintf(stderr, " \t -H don't show the header\n");
89
	fprintf(stderr, " \t -w [interval] watch mode - refresh the table continuously\n");
90 90

  
91 91
	if (debug_table == BATCTL_TABLE_ORIGINATORS)
92
		printf(" \t -t timeout interval - don't print originators not seen for x.y seconds \n");
92
		fprintf(stderr, " \t -t timeout interval - don't print originators not seen for x.y seconds \n");
93 93
}
94 94

  
95 95
int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
......
117 117
			}
118 118

  
119 119
			if (!sscanf(optarg, "%f", &watch_interval)) {
120
				printf("Error - provided argument of '-%c' is not a number\n", optchar);
120
				fprintf(stderr, "Error - provided argument of '-%c' is not a number\n", optchar);
121 121
				return EXIT_FAILURE;
122 122
			}
123 123
			break;
124 124
		case 't':
125 125
			if (debug_table != BATCTL_TABLE_ORIGINATORS) {
126
				printf("Error - unrecognised option '-%c'\n", optchar);
126
				fprintf(stderr, "Error - unrecognised option '-%c'\n", optchar);
127 127
				debug_table_usage(debug_table);
128 128
				return EXIT_FAILURE;
129 129
			}
130 130

  
131 131
			read_opt |= NO_OLD_ORIGS;
132 132
			if (!sscanf(optarg, "%f", &orig_timeout)) {
133
				printf("Error - provided argument of '-%c' is not a number\n", optchar);
133
				fprintf(stderr, "Error - provided argument of '-%c' is not a number\n", optchar);
134 134
				return EXIT_FAILURE;
135 135
			}
136 136
			break;
......
139 139
			break;
140 140
		case '?':
141 141
			if (optopt == 't')
142
				printf("Error - option '-t' needs a number as argument\n");
142
				fprintf(stderr, "Error - option '-t' needs a number as argument\n");
143 143

  
144 144
			else if (optopt == 'w') {
145 145
				read_opt |= CLR_CONT_READ;
146 146
				break;
147 147
			}
148 148
			else
149
				printf("Error - unrecognised option: '-%c'\n", optopt);
149
				fprintf(stderr, "Error - unrecognised option: '-%c'\n", optopt);
150 150

  
151 151
			return EXIT_FAILURE;
152 152
		default:
......
157 157

  
158 158
	debugfs_mnt = debugfs_mount(NULL);
159 159
	if (!debugfs_mnt) {
160
		printf("Error - can't mount or find debugfs\n");
160
		fprintf(stderr, "Error - can't mount or find debugfs\n");
161 161
		return EXIT_FAILURE;
162 162
	}
163 163

  
......
169 169

  
170 170
static void log_usage(void)
171 171
{
172
	printf("Usage: batctl [options] log [parameters]\n");
173
	printf("parameters:\n");
174
	printf(" \t -h print this help\n");
175
	printf(" \t -n don't replace mac addresses with bat-host names\n");
172
	fprintf(stderr, "Usage: batctl [options] log [parameters]\n");
173
	fprintf(stderr, "parameters:\n");
174
	fprintf(stderr, " \t -h print this help\n");
175
	fprintf(stderr, " \t -n don't replace mac addresses with bat-host names\n");
176 176
}
177 177

  
178 178
int log_print(char *mesh_iface, int argc, char **argv)
......
197 197

  
198 198
	debugfs_mnt = debugfs_mount(NULL);
199 199
	if (!debugfs_mnt) {
200
		printf("Error - can't mount or find debugfs\n");
200
		fprintf(stderr, "Error - can't mount or find debugfs\n");
201 201
		return EXIT_FAILURE;
202 202
	}
203 203

  
debugfs.c
85 85
	/* give up and parse /proc/mounts */
86 86
	fp = fopen("/proc/mounts", "r");
87 87
	if (fp == NULL) {
88
		printf("Error - can't open /proc/mounts for read: %s\n",
88
		fprintf(stderr, "Error - can't open /proc/mounts for read: %s\n",
89 89
		       strerror(errno));
90 90
		return NULL;
91 91
	}
functions.c
130 130

  
131 131
	if (strstr(dir, "/sys/")) {
132 132
		if (stat("/sys/", &st) != 0) {
133
			printf("Error - the folder '/sys/' was not found on the system\n");
134
			printf("Please make sure that the sys filesystem is properly mounted\n");
133
			fprintf(stderr, "Error - the folder '/sys/' was not found on the system\n");
134
			fprintf(stderr, "Please make sure that the sys filesystem is properly mounted\n");
135 135
			return;
136 136
		}
137 137
	}
138 138

  
139 139
	if (!file_exists(module_ver_path)) {
140
		printf("Error - batman-adv module has not been loaded\n");
140
		fprintf(stderr, "Error - batman-adv module has not been loaded\n");
141 141
		return;
142 142
	}
143 143

  
144 144
	if (!file_exists(dir)) {
145
		printf("Error - mesh has not been enabled yet\n");
146
		printf("Activate your mesh by adding interfaces to batman-adv\n");
145
		fprintf(stderr, "Error - mesh has not been enabled yet\n");
146
		fprintf(stderr, "Activate your mesh by adding interfaces to batman-adv\n");
147 147
		return;
148 148
	}
149 149

  
......
154 154
		break;
155 155
	}
156 156

  
157
	printf("Error - can't open file '%s': %s\n", full_path, strerror(errno));
157
	fprintf(stderr, "Error - can't open file '%s': %s\n", full_path, strerror(errno));
158 158
	if (*ptr) {
159
		printf("The option you called seems not to be compiled into your batman-adv kernel module.\n");
160
		printf("Consult the README if you wish to learn more about compiling options into batman-adv.\n");
159
		fprintf(stderr, "The option you called seems not to be compiled into your batman-adv kernel module.\n");
160
		fprintf(stderr, "Consult the README if you wish to learn more about compiling options into batman-adv.\n");
161 161
	}
162 162
}
163 163

  
......
318 318
		write_len = write(fd, arg1, strlen(arg1) + 1);
319 319

  
320 320
	if (write_len < 0) {
321
		printf("Error - can't write to file '%s': %s\n", full_path, strerror(errno));
321
		fprintf(stderr, "Error - can't write to file '%s': %s\n", full_path, strerror(errno));
322 322
		goto out;
323 323
	}
324 324

  
ioctl.c
50 50
	ifr->ifr_data = (caddr_t)&drvinfo;
51 51
	err = ioctl(fd, SIOCETHTOOL, ifr);
52 52
	if (err < 0) {
53
		printf("Error - can't open driver information: %s\n", strerror(errno));
53
		fprintf(stderr, "Error - can't open driver information: %s\n", strerror(errno));
54 54
		goto out;
55 55
	}
56 56

  
......
64 64
	strings = calloc(1, sz_str + sizeof(struct ethtool_gstrings));
65 65
	stats = calloc(1, sz_stats + sizeof(struct ethtool_stats));
66 66
	if (!strings || !stats) {
67
		printf("Error - out of memory\n");
67
		fprintf(stderr, "Error - out of memory\n");
68 68
		goto out;
69 69
	}
70 70

  
......
74 74
	ifr->ifr_data = (caddr_t)strings;
75 75
	err = ioctl(fd, SIOCETHTOOL, ifr);
76 76
	if (err < 0) {
77
		printf("Error - can't get stats strings information: %s\n", strerror(errno));
77
		fprintf(stderr, "Error - can't get stats strings information: %s\n", strerror(errno));
78 78
		goto out;
79 79
	}
80 80

  
......
83 83
	ifr->ifr_data = (caddr_t) stats;
84 84
	err = ioctl(fd, SIOCETHTOOL, ifr);
85 85
	if (err < 0) {
86
		printf("Error - can't get stats information: %s\n", strerror(errno));
86
		fprintf(stderr, "Error - can't get stats information: %s\n", strerror(errno));
87 87
		goto out;
88 88
	}
89 89

  
......
111 111

  
112 112
	fd = socket(AF_INET, SOCK_DGRAM, 0);
113 113
	if (fd < 0) {
114
		printf("Error - can't open socket: %s\n", strerror(errno));
114
		fprintf(stderr, "Error - can't open socket: %s\n", strerror(errno));
115 115
		goto out;
116 116
	}
117 117

  
main.c
48 48
{
49 49
	int i, opt_indent;
50 50

  
51
	printf("Usage: batctl [options] command|debug table [parameters]\n");
52
	printf("options:\n");
53
	printf(" \t-m mesh interface (default 'bat0')\n");
54
	printf(" \t-h print this help (or 'batctl <command|debug table> -h' for the parameter help)\n");
55
	printf(" \t-v print version\n");
56
	printf("\n");
57

  
58
	printf("commands:\n");
59
	printf(" \tinterface|if               [add|del iface(s)]\tdisplay or modify the interface settings\n");
51
	fprintf(stderr, "Usage: batctl [options] command|debug table [parameters]\n");
52
	fprintf(stderr, "options:\n");
53
	fprintf(stderr, " \t-m mesh interface (default 'bat0')\n");
54
	fprintf(stderr, " \t-h print this help (or 'batctl <command|debug table> -h' for the parameter help)\n");
55
	fprintf(stderr, " \t-v print version\n");
56
	fprintf(stderr, "\n");
57

  
58
	fprintf(stderr, "commands:\n");
59
	fprintf(stderr, " \tinterface|if               [add|del iface(s)]\tdisplay or modify the interface settings\n");
60 60
	for (i = 0; i < BATCTL_SETTINGS_NUM; i++) {
61
		printf(" \t%s|%s", batctl_settings[i].opt_long, batctl_settings[i].opt_short);
61
		fprintf(stderr, " \t%s|%s", batctl_settings[i].opt_long, batctl_settings[i].opt_short);
62 62
		opt_indent = strlen(batctl_settings[i].opt_long) + strlen(batctl_settings[i].opt_short);
63 63

  
64 64
		if (batctl_settings[i].params == sysfs_param_enable)
65
			printf("%*s                display or modify %s setting\n",
65
			fprintf(stderr, "%*s                display or modify %s setting\n",
66 66
			       31 - opt_indent, "[0|1]", batctl_settings[i].opt_long);
67 67
		else if (batctl_settings[i].params == sysfs_param_server)
68
			printf("%*s      display or modify %s setting\n",
68
			fprintf(stderr, "%*s      display or modify %s setting\n",
69 69
			       41 - opt_indent, "[client|server]", batctl_settings[i].opt_long);
70 70
		else
71
			printf("                                display or modify %s setting\n",
71
			fprintf(stderr, "                                display or modify %s setting\n",
72 72
			       batctl_settings[i].opt_long);
73 73
	}
74
	printf(" \tloglevel|ll                [level]           \tdisplay or modify the log level\n");
75
	printf(" \tlog|l                                        \tread the log produced by the kernel module\n");
76
	printf(" \tgw_mode|gw                 [mode]            \tdisplay or modify the gateway mode\n");
77
	printf(" \tvis_data|vd                [dot|JSON]        \tdisplay the VIS data in dot or JSON format\n");
78
	printf("\n");
74
	fprintf(stderr, " \tloglevel|ll                [level]           \tdisplay or modify the log level\n");
75
	fprintf(stderr, " \tlog|l                                        \tread the log produced by the kernel module\n");
76
	fprintf(stderr, " \tgw_mode|gw                 [mode]            \tdisplay or modify the gateway mode\n");
77
	fprintf(stderr, " \tvis_data|vd                [dot|JSON]        \tdisplay the VIS data in dot or JSON format\n");
78
	fprintf(stderr, "\n");
79 79

  
80
	printf("debug tables:                                   \tdisplay the corresponding debug table\n");
80
	fprintf(stderr, "debug tables:                                   \tdisplay the corresponding debug table\n");
81 81
	for (i = 0; i < BATCTL_TABLE_NUM; i++)
82
		printf(" \t%s|%s\n", batctl_debug_tables[i].opt_long, batctl_debug_tables[i].opt_short);
83

  
84
	printf("\n");
85
	printf(" \tstatistics|s                                 \tprint mesh statistics\n");
86
	printf(" \tping|p                     <destination>     \tping another batman adv host via layer 2\n");
87
	printf(" \ttraceroute|tr              <destination>     \ttraceroute another batman adv host via layer 2\n");
88
	printf(" \ttcpdump|td                 <interface>       \ttcpdump layer 2 traffic on the given interface\n");
89
	printf(" \ttranslate|t                <destination>     \ttranslate a destination to the originator responsible for it\n");
82
		fprintf(stderr, " \t%s|%s\n", batctl_debug_tables[i].opt_long, batctl_debug_tables[i].opt_short);
83

  
84
	fprintf(stderr, "\n");
85
	fprintf(stderr, " \tstatistics|s                                 \tprint mesh statistics\n");
86
	fprintf(stderr, " \tping|p                     <destination>     \tping another batman adv host via layer 2\n");
87
	fprintf(stderr, " \ttraceroute|tr              <destination>     \ttraceroute another batman adv host via layer 2\n");
88
	fprintf(stderr, " \ttcpdump|td                 <interface>       \ttcpdump layer 2 traffic on the given interface\n");
89
	fprintf(stderr, " \ttranslate|t                <destination>     \ttranslate a destination to the originator responsible for it\n");
90 90
#ifdef BATCTL_BISECT
91
	printf(" \tbisect_iv                  <file1> .. <fileN>\tanalyze given batman iv log files for routing stability\n");
91
	fprintf(stderr, " \tbisect_iv                  <file1> .. <fileN>\tanalyze given batman iv log files for routing stability\n");
92 92
#endif
93 93
}
94 94

  
......
99 99

  
100 100
	if ((argc > 1) && (strcmp(argv[1], "-m") == 0)) {
101 101
		if (argc < 3) {
102
			printf("Error - the option '-m' needs a parameter\n");
102
			fprintf(stderr, "Error - the option '-m' needs a parameter\n");
103 103
			goto err;
104 104
		}
105 105

  
......
110 110
	}
111 111

  
112 112
	if (argc < 2) {
113
		printf("Error - no command specified\n");
113
		fprintf(stderr, "Error - no command specified\n");
114 114
		goto err;
115 115
	}
116 116

  
117
	if (strcmp(argv[1], "-h") == 0)
118
		goto err;
117
	if (strcmp(argv[1], "-h") == 0) {
118
		print_usage();
119
		exit(EXIT_SUCCESS);
120
	}
119 121

  
120 122
	if (strcmp(argv[1], "-v") == 0) {
121 123
		printf("batctl %s [batman-adv: ", SOURCE_VERSION);
......
206 208
			goto out;
207 209
		}
208 210

  
209
		printf("Error - no valid command or debug table specified: %s\n", argv[1]);
211
		fprintf(stderr, "Error - no valid command or debug table specified: %s\n", argv[1]);
210 212
		print_usage();
211 213
	}
212 214

  
ping.c
44 44

  
45 45
void ping_usage(void)
46 46
{
47
	printf("Usage: batctl [options] ping [parameters] mac|bat-host|host_name|IPv4_address \n");
48
	printf("parameters:\n");
49
	printf(" \t -c ping packet count \n");
50
	printf(" \t -h print this help\n");
51
	printf(" \t -i interval in seconds\n");
52
	printf(" \t -t timeout in seconds\n");
53
	printf(" \t -R record route\n");
54
	printf(" \t -T don't try to translate mac to originator address\n");
47
	fprintf(stderr, "Usage: batctl [options] ping [parameters] mac|bat-host|host_name|IPv4_address \n");
48
	fprintf(stderr, "parameters:\n");
49
	fprintf(stderr, " \t -c ping packet count \n");
50
	fprintf(stderr, " \t -h print this help\n");
51
	fprintf(stderr, " \t -i interval in seconds\n");
52
	fprintf(stderr, " \t -t timeout in seconds\n");
53
	fprintf(stderr, " \t -R record route\n");
54
	fprintf(stderr, " \t -T don't try to translate mac to originator address\n");
55 55
}
56 56

  
57 57
void sig_handler(int sig)
......
124 124
	}
125 125

  
126 126
	if (argc <= found_args) {
127
		printf("Error - target mac address or bat-host name not specified\n");
127
		fprintf(stderr, "Error - target mac address or bat-host name not specified\n");
128 128
		ping_usage();
129 129
		return EXIT_FAILURE;
130 130
	}
......
140 140
		dst_mac = resolve_mac(dst_string);
141 141

  
142 142
		if (!dst_mac) {
143
			printf("Error - mac address of the ping destination could not be resolved and is not a bat-host name: %s\n", dst_string);
143
			fprintf(stderr, "Error - mac address of the ping destination could not be resolved and is not a bat-host name: %s\n", dst_string);
144 144
			goto out;
145 145
		}
146 146
	}
......
154 154

  
155 155
	debugfs_mnt = debugfs_mount(NULL);
156 156
	if (!debugfs_mnt) {
157
		printf("Error - can't mount or find debugfs\n");
157
		fprintf(stderr, "Error - can't mount or find debugfs\n");
158 158
		goto out;
159 159
	}
160 160

  
......
163 163
	ping_fd = open(icmp_socket, O_RDWR);
164 164

  
165 165
	if (ping_fd < 0) {
166
		printf("Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n",
166
		fprintf(stderr, "Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n",
167 167
				icmp_socket, strerror(errno));
168 168
		printf("Check whether the module is loaded and active.\n");
169 169
		goto out;
......
203 203
		icmp_packet_out.seqno = htons(++seq_counter);
204 204

  
205 205
		if (write(ping_fd, (char *)&icmp_packet_out, packet_len) < 0) {
206
			printf("Error - can't write to batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
206
			fprintf(stderr, "Error - can't write to batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
207 207
			goto sleep;
208 208
		}
209 209

  
......
231 231
		read_len = read(ping_fd, (char *)&icmp_packet_in, packet_len);
232 232

  
233 233
		if (read_len < 0) {
234
			printf("Error - can't read from batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
234
			fprintf(stderr, "Error - can't read from batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
235 235
			goto sleep;
236 236
		}
237 237

  
......
298 298
			printf("From %s: Time to live exceeded (icmp_seq %hu)\n", dst_string, ntohs(icmp_packet_in.seqno));
299 299
			break;
300 300
		case BATADV_PARAMETER_PROBLEM:
301
			printf("Error - the batman adv kernel module version (%d) differs from ours (%d)\n",
301
			fprintf(stderr, "Error - the batman adv kernel module version (%d) differs from ours (%d)\n",
302 302
					icmp_packet_in.header.version, BATADV_COMPAT_VERSION);
303 303
			printf("Please make sure to use compatible versions!\n");
304 304
			goto out;
sys.c
103 103

  
104 104
static void interface_usage(void)
105 105
{
106
	printf("Usage: batctl [options] interface [parameters] [add|del iface(s)]\n");
107
	printf("parameters:\n");
108
	printf(" \t -h print this help\n");
106
	fprintf(stderr, "Usage: batctl [options] interface [parameters] [add|del iface(s)]\n");
107
	fprintf(stderr, "parameters:\n");
108
	fprintf(stderr, " \t -h print this help\n");
109 109
}
110 110

  
111 111
static int print_interfaces(char *mesh_iface)
......
116 116
	int res;
117 117

  
118 118
	if (!file_exists(module_ver_path)) {
119
		printf("Error - batman-adv module has not been loaded\n");
119
		fprintf(stderr, "Error - batman-adv module has not been loaded\n");
120 120
		goto err;
121 121
	}
122 122

  
123 123
	path_buff = malloc(PATH_BUFF_LEN);
124 124
	if (!path_buff) {
125
		printf("Error - could not allocate path buffer: out of memory ?\n");
125
		fprintf(stderr, "Error - could not allocate path buffer: out of memory ?\n");
126 126
		goto err;
127 127
	}
128 128

  
129 129
	iface_base_dir = opendir(SYS_IFACE_PATH);
130 130
	if (!iface_base_dir) {
131
		printf("Error - the directory '%s' could not be read: %s\n",
131
		fprintf(stderr, "Error - the directory '%s' could not be read: %s\n",
132 132
		       SYS_IFACE_PATH, strerror(errno));
133
		printf("Is the batman-adv module loaded and sysfs mounted ?\n");
133
		fprintf(stderr, "Is the batman-adv module loaded and sysfs mounted ?\n");
134 134
		goto err_buff;
135 135
	}
136 136

  
......
157 157
		path_buff[PATH_BUFF_LEN - 1] = '\0';
158 158
		res = read_file("", path_buff, USE_READ_BUFF | SILENCE_ERRORS, 0, 0, 0);
159 159
		if (res != EXIT_SUCCESS) {
160
			printf("<error reading status>\n");
160
			fprintf(stderr, "<error reading status>\n");
161 161
			continue;
162 162
		}
163 163

  
......
199 199

  
200 200
	if ((strcmp(argv[1], "add") != 0) && (strcmp(argv[1], "a") != 0) &&
201 201
	    (strcmp(argv[1], "del") != 0) && (strcmp(argv[1], "d") != 0)) {
202
		printf("Error - unknown argument specified: %s\n", argv[1]);
202
		fprintf(stderr, "Error - unknown argument specified: %s\n", argv[1]);
203 203
		interface_usage();
204 204
		goto err;
205 205
	}
206 206

  
207 207
	if (argc == 2) {
208
		printf("Error - missing interface name(s) after '%s'\n", argv[1]);
208
		fprintf(stderr, "Error - missing interface name(s) after '%s'\n", argv[1]);
209 209
		interface_usage();
210 210
		goto err;
211 211
	}
212 212

  
213 213
	path_buff = malloc(PATH_BUFF_LEN);
214 214
	if (!path_buff) {
215
		printf("Error - could not allocate path buffer: out of memory ?\n");
215
		fprintf(stderr, "Error - could not allocate path buffer: out of memory ?\n");
216 216
		goto err;
217 217
	}
218 218

  
......
225 225
			path_buff[PATH_BUFF_LEN - 1] = '\0';
226 226

  
227 227
			if (!file_exists(path_buff)) {
228
				printf("Error - interface does not exist: %s\n", argv[i]);
228
				fprintf(stderr, "Error - interface does not exist: %s\n", argv[i]);
229 229
				continue;
230 230
			}
231 231

  
232 232
			if (!file_exists(module_ver_path)) {
233
				printf("Error - batman-adv module has not been loaded\n");
233
				fprintf(stderr, "Error - batman-adv module has not been loaded\n");
234 234
				goto err;
235 235
			}
236 236

  
237
			printf("Error - interface type not supported by batman-adv: %s\n", argv[i]);
237
			fprintf(stderr, "Error - interface type not supported by batman-adv: %s\n", argv[i]);
238 238
			continue;
239 239
		}
240 240

  
......
258 258

  
259 259
static void log_level_usage(void)
260 260
{
261
	printf("Usage: batctl [options] loglevel [parameters] [level[ level[ level]]...]\n");
262
	printf("parameters:\n");
263
	printf(" \t -h print this help\n");
264
	printf("levels:\n");
265
	printf(" \t none    Debug logging is disabled\n");
266
	printf(" \t all     Print messages from all below\n");
267
	printf(" \t batman  Messages related to routing / flooding / broadcasting\n");
268
	printf(" \t routes  Messages related to route added / changed / deleted\n");
269
	printf(" \t tt      Messages related to translation table operations\n");
270
	printf(" \t bla     Messages related to bridge loop avoidance\n");
271
	printf(" \t dat     Messages related to arp snooping and distributed arp table\n");
261
	fprintf(stderr, "Usage: batctl [options] loglevel [parameters] [level[ level[ level]]...]\n");
262
	fprintf(stderr, "parameters:\n");
263
	fprintf(stderr, " \t -h print this help\n");
264
	fprintf(stderr, "levels:\n");
265
	fprintf(stderr, " \t none    Debug logging is disabled\n");
266
	fprintf(stderr, " \t all     Print messages from all below\n");
267
	fprintf(stderr, " \t batman  Messages related to routing / flooding / broadcasting\n");
268
	fprintf(stderr, " \t routes  Messages related to route added / changed / deleted\n");
269
	fprintf(stderr, " \t tt      Messages related to translation table operations\n");
270
	fprintf(stderr, " \t bla     Messages related to bridge loop avoidance\n");
271
	fprintf(stderr, " \t dat     Messages related to arp snooping and distributed arp table\n");
272 272
}
273 273

  
274 274
int handle_loglevel(char *mesh_iface, int argc, char **argv)
......
352 352

  
353 353
static void settings_usage(int setting)
354 354
{
355
	printf("Usage: batctl [options] %s|%s [parameters]",
355
	fprintf(stderr, "Usage: batctl [options] %s|%s [parameters]",
356 356
	       (char *)batctl_settings[setting].opt_long, (char *)batctl_settings[setting].opt_short);
357 357

  
358 358
	if (batctl_settings[setting].params == sysfs_param_enable)
359
		printf(" [0|1]\n");
359
		fprintf(stderr, " [0|1]\n");
360 360
	else if (batctl_settings[setting].params == sysfs_param_server)
361
		printf(" [client|server]\n");
361
		fprintf(stderr, " [client|server]\n");
362 362
	else
363
		printf("\n");
363
		fprintf(stderr, "\n");
364 364

  
365
	printf("parameters:\n");
366
	printf(" \t -h print this help\n");
365
	fprintf(stderr, "parameters:\n");
366
	fprintf(stderr, " \t -h print this help\n");
367 367
}
368 368

  
369 369
int handle_sys_setting(char *mesh_iface, int setting, int argc, char **argv)
......
404 404
		ptr++;
405 405
	}
406 406

  
407
	printf("Error - the supplied argument is invalid: %s\n", argv[1]);
408
	printf("The following values are allowed:\n");
407
	fprintf(stderr, "Error - the supplied argument is invalid: %s\n", argv[1]);
408
	fprintf(stderr, "The following values are allowed:\n");
409 409

  
410 410
	ptr = batctl_settings[setting].params;
411 411
	while (*ptr) {
412
		printf(" * %s\n", *ptr);
412
		fprintf(stderr, " * %s\n", *ptr);
413 413
		ptr++;
414 414
	}
415 415

  
......
426 426

  
427 427
static void gw_mode_usage(void)
428 428
{
429
	printf("Usage: batctl [options] gw_mode [mode] [sel_class|bandwidth]\n");
430
	printf("options:\n");
431
	printf(" \t -h print this help\n");
429
	fprintf(stderr, "Usage: batctl [options] gw_mode [mode] [sel_class|bandwidth]\n");
430
	fprintf(stderr, "options:\n");
431
	fprintf(stderr, " \t -h print this help\n");
432 432
}
433 433

  
434 434
int handle_gw_setting(char *mesh_iface, int argc, char **argv)
......
533 533
	goto out;
534 534

  
535 535
opt_err:
536
	printf("Error - the supplied argument is invalid: %s\n", argv[1]);
537
	printf("The following values are allowed:\n");
536
	fprintf(stderr, "Error - the supplied argument is invalid: %s\n", argv[1]);
537
	fprintf(stderr, "The following values are allowed:\n");
538 538

  
539 539
	ptr = sysfs_param_server;
540 540
	while (*ptr) {
541
		printf(" * %s\n", *ptr);
541
		fprintf(stderr, " * %s\n", *ptr);
542 542
		ptr++;
543 543
	}
544 544

  
tcpdump.c
62 62

  
63 63
static void tcpdump_usage(void)
64 64
{
65
	printf("Usage: batctl tcpdump [parameters] interface [interface]\n");
66
	printf("parameters:\n");
67
	printf(" \t -c compat filter - only display packets matching own compat version (%i)\n", BATADV_COMPAT_VERSION);
68
	printf(" \t -h print this help\n");
69
	printf(" \t -n don't convert addresses to bat-host names\n");
70
	printf(" \t -p dump specific packet type\n");
71
	printf(" \t -x dump all packet types except specified\n");
72
	printf("packet types:\n");
73
	printf(" \t\t%3d - batman ogm packets\n", DUMP_TYPE_BATOGM);
74
	printf(" \t\t%3d - batman icmp packets\n", DUMP_TYPE_BATICMP);
75
	printf(" \t\t%3d - batman unicast packets\n", DUMP_TYPE_BATUCAST);
76
	printf(" \t\t%3d - batman broadcast packets\n", DUMP_TYPE_BATBCAST);
77
	printf(" \t\t%3d - batman vis packets\n", DUMP_TYPE_BATVIS);
78
	printf(" \t\t%3d - batman fragmented packets\n", DUMP_TYPE_BATFRAG);
79
	printf(" \t\t%3d - batman tt / roaming packets\n", DUMP_TYPE_BATTT);
80
	printf(" \t\t%3d - non batman packets\n", DUMP_TYPE_NONBAT);
81
	printf(" \t\t%3d - batman ogm & non batman packets\n", DUMP_TYPE_BATOGM | DUMP_TYPE_NONBAT);
65
	fprintf(stderr, "Usage: batctl tcpdump [parameters] interface [interface]\n");
66
	fprintf(stderr, "parameters:\n");
67
	fprintf(stderr, " \t -c compat filter - only display packets matching own compat version (%i)\n", BATADV_COMPAT_VERSION);
68
	fprintf(stderr, " \t -h print this help\n");
69
	fprintf(stderr, " \t -n don't convert addresses to bat-host names\n");
70
	fprintf(stderr, " \t -p dump specific packet type\n");
71
	fprintf(stderr, " \t -x dump all packet types except specified\n");
72
	fprintf(stderr, "packet types:\n");
73
	fprintf(stderr, " \t\t%3d - batman ogm packets\n", DUMP_TYPE_BATOGM);
74
	fprintf(stderr, " \t\t%3d - batman icmp packets\n", DUMP_TYPE_BATICMP);
75
	fprintf(stderr, " \t\t%3d - batman unicast packets\n", DUMP_TYPE_BATUCAST);
76
	fprintf(stderr, " \t\t%3d - batman broadcast packets\n", DUMP_TYPE_BATBCAST);
77
	fprintf(stderr, " \t\t%3d - batman vis packets\n", DUMP_TYPE_BATVIS);
78
	fprintf(stderr, " \t\t%3d - batman fragmented packets\n", DUMP_TYPE_BATFRAG);
79
	fprintf(stderr, " \t\t%3d - batman tt / roaming packets\n", DUMP_TYPE_BATTT);
80
	fprintf(stderr, " \t\t%3d - non batman packets\n", DUMP_TYPE_NONBAT);
81
	fprintf(stderr, " \t\t%3d - batman ogm & non batman packets\n", DUMP_TYPE_BATOGM | DUMP_TYPE_NONBAT);
82 82
}
83 83

  
84 84
static int print_time(void)
traceroute.c
43 43

  
44 44
void traceroute_usage(void)
45 45
{
46
	printf("Usage: batctl [options] traceroute [parameters] mac|bat-host|host_name|IPv4_address \n");
47
	printf("parameters:\n");
48
	printf(" \t -h print this help\n");
49
	printf(" \t -n don't convert addresses to bat-host names\n");
50
	printf(" \t -T don't try to translate mac to originator address\n");
46
	fprintf(stderr, "Usage: batctl [options] traceroute [parameters] mac|bat-host|host_name|IPv4_address \n");
47
	fprintf(stderr, "parameters:\n");
48
	fprintf(stderr, " \t -h print this help\n");
49
	fprintf(stderr, " \t -n don't convert addresses to bat-host names\n");
50
	fprintf(stderr, " \t -T don't try to translate mac to originator address\n");
51 51
}
52 52

  
53 53
int traceroute(char *mesh_iface, int argc, char **argv)
......
86 86
	}
87 87

  
88 88
	if (argc <= found_args) {
89
		printf("Error - target mac address or bat-host name not specified\n");
89
		fprintf(stderr, "Error - target mac address or bat-host name not specified\n");
90 90
		traceroute_usage();
91 91
		return EXIT_FAILURE;
92 92
	}
......
102 102
		dst_mac = resolve_mac(dst_string);
103 103

  
104 104
		if (!dst_mac) {
105
			printf("Error - mac address of the ping destination could not be resolved and is not a bat-host name: %s\n", dst_string);
105
			fprintf(stderr, "Error - mac address of the ping destination could not be resolved and is not a bat-host name: %s\n", dst_string);
106 106
			goto out;
107 107
		}
108 108
	}
......
114 114

  
115 115
	debugfs_mnt = debugfs_mount(NULL);
116 116
	if (!debugfs_mnt) {
117
		printf("Error - can't mount or find debugfs\n");
117
		fprintf(stderr, "Error - can't mount or find debugfs\n");
118 118
		goto out;
119 119
	}
120 120

  
......
123 123
	trace_fd = open(icmp_socket, O_RDWR);
124 124

  
125 125
	if (trace_fd < 0) {
126
		printf("Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n",
126
		fprintf(stderr, "Error - can't open a connection to the batman adv kernel module via the socket '%s': %s\n",
127 127
				icmp_socket, strerror(errno));
128
		printf("Check whether the module is loaded and active.\n");
128
		fprintf(stderr, "Check whether the module is loaded and active.\n");
129 129
		goto out;
130 130
	}
131 131

  
......
148 148
			time_delta[i] = 0.0;
149 149

  
150 150
			if (write(trace_fd, (char *)&icmp_packet_out, sizeof(icmp_packet_out)) < 0) {
151
				printf("Error - can't write to batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
151
				fprintf(stderr, "Error - can't write to batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
152 152
				continue;
153 153
			}
154 154

  
......
169 169
			read_len = read(trace_fd, (char *)&icmp_packet_in, sizeof(icmp_packet_in));
170 170

  
171 171
			if (read_len < 0) {
172
				printf("Error - can't read from batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
172
				fprintf(stderr, "Error - can't read from batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno));
173 173
				continue;
174 174
			}
175 175

  
......
202 202
				printf("%s: Destination Host Unreachable\n", dst_string);
203 203
				goto out;
204 204
			case BATADV_PARAMETER_PROBLEM:
205
				printf("Error - the batman adv kernel module version (%d) differs from ours (%d)\n",
205
				fprintf(stderr, "Error - the batman adv kernel module version (%d) differs from ours (%d)\n",
206 206
						icmp_packet_in.header.version, BATADV_COMPAT_VERSION);
207
				printf("Please make sure to use compatible versions!\n");
207
				fprintf(stderr, "Please make sure to use compatible versions!\n");
208 208
				goto out;
209 209
			default:
210 210
				printf("Unknown message type %d len %zd received\n", icmp_packet_in.msg_type, read_len);
translate.c
31 31

  
32 32
static void translate_usage(void)
33 33
{
34
	printf("Usage: batctl [options] translate mac|bat-host|host_name|IPv4_address\n");
34
	fprintf(stderr, "Usage: batctl [options] translate mac|bat-host|host_name|IPv4_address\n");
35 35
}
36 36

  
37 37
int translate(char *mesh_iface, int argc, char **argv)
vis.c
58 58

  
59 59
static void usage(void)
60 60
{
61
	printf("batctl vis_data dot {-h}{--no-TT|-T} {--no-2nd|-2} {--numbers|-n}\n");
62
	printf("or\n");
63
	printf("batctl vis_data json {-h}{--no-TT|-T} {--no-2nd|-2} {--numbers|-n}\n");
61
	fprintf(stderr, "batctl vis_data dot {-h}{--no-TT|-T} {--no-2nd|-2} {--numbers|-n}\n");
62
	fprintf(stderr, "or\n");
63
	fprintf(stderr, "batctl vis_data json {-h}{--no-TT|-T} {--no-2nd|-2} {--numbers|-n}\n");
64 64
}
65 65

  
66 66
static void dot_print_tq(char *orig, char *from, const long tq)
......
171 171

  
172 172
	debugfs_mnt = debugfs_mount(NULL);
173 173
	if (!debugfs_mnt) {
174
		printf("Error - can't mount or find debugfs\n");
174
		fprintf(stderr, "Error - can't mount or find debugfs\n");
175 175
		return NULL;
176 176
	}
177 177

  
(2-2/2)