1 /****************************************************************************** 2 * bwm-ng * 3 * * 4 * Copyright (C) 2004 Volker Gropp (vgropp@pefra.de) * 5 * * 6 * for more info read README. * 7 * * 8 * This program is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU General Public License as published by * 10 * the Free Software Foundation; either version 2 of the License, or * 11 * (at your option) any later version. * 12 * * 13 * This program is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 * GNU General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU General Public License * 19 * along with this program; if not, write to the Free Software * 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 21 * * 22 *****************************************************************************/ 23 24 #ifndef __HAVE_DEFINE_H 25 #define __HAVE_DEFINE_H 26 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include <unistd.h> 30 #include <errno.h> 31 #include <limits.h> 32 #include <signal.h> 33 #include <string.h> 34 35 #include "../config.h" 36 37 /* ugly defines to handle different compile time options */ 38 39 #if HAVE_STRUCT_IF_MSGHDR_IFM_DATA 40 #define SYSCTL 41 #endif 42 43 #if NETSTAT_LINUX || NETSTAT_BSD || NETSTAT_BSD_BYTES || NETSTAT_SOLARIS || NETSTAT_NETBSD 44 #define NETSTAT 1 45 #endif 46 47 #if HAVE_LIBSTATGRAB 48 #define LIBSTATGRAB 49 #endif 50 51 #if HAVE_LIBCURSES || HAVE_LIBNCURSES 52 #define HAVE_CURSES 53 #endif 54 55 #if HAVE_WORKING_GETIFADDRS 56 #define GETIFADDRS 57 #endif 58 59 #if HAVE_GETOPT_LONG 60 #define LONG_OPTIONS 61 #endif 62 63 #if HAVE_IOCTL 64 #include <sys/ioctl.h> 65 #ifdef SIOCGIFFLAGS 66 #define IOCTL 67 #endif 68 #endif 69 70 #ifdef HAVE_CURSES 71 #include <curses.h> 72 #ifndef ACS_VLINE 73 #define ACS_VLINE '|' 74 #endif 75 #ifndef ACS_HLINE 76 #define ACS_HLINE '-' 77 #endif 78 #endif 79 80 #ifdef LONG_OPTIONS 81 #include <getopt.h> 82 #endif 83 84 #if HAVE_GETTIMEOFDAY 85 #include <sys/time.h> 86 #include <time.h> 87 #endif 88 89 #ifdef NETSTAT 90 #if HAVE_NETSTAT_PATH 91 #define NETSTAT_PATH HAVE_NETSTAT_PATH 92 #else 93 #define NETSTAT_PATH "netstat" 94 #endif 95 #endif 96 97 #if HAVE__PROC_NET_DEV 98 #ifdef PROC_NET_DEV_PATH 99 #define PROC_NET_DEV PROC_NET_DEV_PATH 100 #else 101 #define PROC_NET_DEV "/proc/net/dev" 102 #endif 103 #endif 104 105 #if HAVE__PROC_DISKSTATS 106 #ifdef PROC_DISKSTATS_PATH 107 #define PROC_DISKSTATS PROC_DISKSTATS_PATH 108 #else 109 #define PROC_DISKSTATS "/proc/diskstats" 110 #endif 111 #ifdef PROC_PARTITIONS_PATH 112 #define PROC_PARTITIONS PROC_PARTITIONS_PATH 113 #else 114 #define PROC_PARTITIONS "/proc/partitions" 115 #endif 116 #endif 117 118 /* prepare input methods */ 119 #ifdef NETSTAT 120 #define NETSTAT_IN 1 121 #define INPUT_METHODS_NETSTAT " netstat" 122 #else 123 #define NETSTAT_IN 0 124 #define INPUT_METHODS_NETSTAT 125 #endif 126 127 #ifdef PROC_NET_DEV 128 #define PROC_IN 2 129 #define INPUT_METHODS_PROC " proc" 130 #else 131 #define PROC_IN 0 132 #define INPUT_METHODS_PROC 133 #endif 134 135 #ifdef GETIFADDRS 136 #define GETIFADDRS_IN 4 137 #define INPUT_METHODS_GETIFADDRS " getifaddrs" 138 #else 139 #define GETIFADDRS_IN 0 140 #define INPUT_METHODS_GETIFADDRS 141 #endif 142 143 #ifdef LIBSTATGRAB 144 #define LIBSTAT_IN 8 145 #define LIBSTATDISK_IN 256 146 #define INPUT_METHODS_LIBSTATGRAB " libstatgrab" 147 #define INPUT_METHODS_LIBSTATDISK " libstatdisk" 148 #else 149 #define LIBSTAT_IN 0 150 #define INPUT_METHODS_LIBSTATGRAB 151 #define LIBSTATDISK_IN 0 152 #define INPUT_METHODS_LIBSTATDISK 153 #endif 154 155 #ifdef SYSCTL 156 #define SYSCTL_IN 16 157 #define INPUT_METHODS_SYSCTL " sysctl" 158 #else 159 #define SYSCTL_IN 0 160 #define INPUT_METHODS_SYSCTL 161 #endif 162 163 #if defined(HAVE_STRUCT_DISKSTATS) || defined(HAVE_STRUCT_DISK_SYSCTL) 164 #define SYSCTLDISK_IN 1024 165 #define INPUT_METHODS_SYSCTLDISK " sysctldisk" 166 #else 167 #define SYSCTLDISK_IN 0 168 #define INPUT_METHODS_SYSCTLDISK 169 #endif 170 171 172 #if HAVE_LIBKSTAT 173 #define KSTAT_IN 32 174 #define KSTATDISK_IN 512 175 #define INPUT_METHODS_KSTAT " kstat" 176 #define INPUT_METHODS_KSTATDISK " kstatdisk" 177 #else 178 #define KSTAT_IN 0 179 #define KSTATDISK_IN 0 180 #define INPUT_METHODS_KSTAT 181 #define INPUT_METHODS_KSTATDISK 182 #endif 183 184 #ifdef WIN32 185 #define WIN32_IN 64 186 #define INPUT_METHODS_WIN32 " win32" 187 #else 188 #define WIN32_IN 0 189 #define INPUT_METHODS_WIN32 190 #endif 191 192 #ifdef PROC_DISKSTATS 193 #define DISKLINUX_IN 128 194 #define INPUT_METHODS_DISK_LINUX " disk" 195 #else 196 #define DISKLINUX_IN 0 197 #define INPUT_METHODS_DISK_LINUX 198 #endif 199 200 #if defined(HAVE_DEVSTAT_GETDEVS) || defined(HAVE_GETDEVS) 201 #define DEVSTAT_IN 2048 202 #define INPUT_METHODS_DEVSTAT " devstat" 203 #else 204 #define DEVSTAT_IN 0 205 #define INPUT_METHODS_DEVSTAT 206 #endif 207 208 #ifdef HAVE_IOSERVICE 209 #define IOSERVICE_IN 4096 210 #define INPUT_METHODS_IOSERVICE " ioservice" 211 #else 212 #define IOSERVICE_IN 0 213 #define INPUT_METHODS_IOSERVICE 214 #endif 215 216 #define INPUT_MASK (NETSTAT_IN | PROC_IN | GETIFADDRS_IN | LIBSTAT_IN | SYSCTL_IN | KSTAT_IN | KSTATDISK_IN | WIN32_IN | DISKLINUX_IN | LIBSTATDISK_IN | SYSCTLDISK_IN | DEVSTAT_IN | IOSERVICE_IN) 217 #define NET_INPUT (NETSTAT_IN | PROC_IN | GETIFADDRS_IN | LIBSTAT_IN | SYSCTL_IN | KSTAT_IN | WIN32_IN) 218 #define INPUT_METHODS INPUT_METHODS_PROC INPUT_METHODS_GETIFADDRS INPUT_METHODS_SYSCTL INPUT_METHODS_KSTAT INPUT_METHODS_NETSTAT INPUT_METHODS_WIN32 INPUT_METHODS_LIBSTATGRAB INPUT_METHODS_DISK_LINUX INPUT_METHODS_LIBSTATDISK INPUT_METHODS_KSTATDISK INPUT_METHODS_SYSCTLDISK INPUT_METHODS_DEVSTAT INPUT_METHODS_IOSERVICE 219 220 #define net_input_method(_n) (_n & NET_INPUT) 221 222 /* used for this nice spinning wheel */ 223 #define IDLE_CHARS "-\\|/" 224 225 226 /* build output methods string: curses, plain, csv, html */ 227 #ifdef HAVE_CURSES 228 #define CURSES_OUTPUT_METHODS ", curses, curses2" 229 #define CURSES_OUT 0 230 #define CURSES2_OUT 5 231 #define IDLE_CHARS2 " >--< " 232 #else 233 #define CURSES_OUTPUT_METHODS 234 #endif 235 236 #ifdef CSV 237 #define CSV_OUTPUT_METHODS ", csv" 238 #define CSV_OUT 2 239 #else 240 #define CSV_OUTPUT_METHODS 241 #endif 242 243 #ifdef HTML 244 #define HTML_OUTPUT_METHODS ", html" 245 #define HTML_OUT 3 246 #else 247 #define HTML_OUTPUT_METHODS 248 #endif 249 250 #define OUTPUT_METHODS "plain" CURSES_OUTPUT_METHODS CSV_OUTPUT_METHODS HTML_OUTPUT_METHODS 251 #define PLAIN_OUT 1 252 #define PLAIN_OUT_ONCE 4 253 254 /* build short options */ 255 #ifdef PROC_NET_DEV 256 #define PROC_SHORT_OPT "f:" 257 #else 258 #define PROC_SHORT_OPT 259 #endif 260 261 #ifdef HTML 262 #define HTML_SHORT_OPT "H:R:" 263 #else 264 #define HTML_SHORT_OPT 265 #endif 266 267 #if NETSTAT && NETSTAT_OPTION 268 #define NETSTAT_SHORT_OPT "n:" 269 #else 270 #define NETSTAT_SHORT_OPT 271 #endif 272 273 #ifdef CSV 274 #define CSV_SHORT_OPT "C:F:" 275 #else 276 #define CSV_SHORT_OPT 277 #endif 278 279 #if EXTENDED_STATS 280 #define EXTENDED_STATS_SHORT_OPT "A:T:" 281 #else 282 #define EXTENDED_STATS_SHORT_OPT 283 #endif 284 285 #define SHORT_OPTIONS ":ht:d:Va:u:I:i:o:c:D:S:N" EXTENDED_STATS_SHORT_OPT PROC_SHORT_OPT HTML_SHORT_OPT NETSTAT_SHORT_OPT CSV_SHORT_OPT 286 287 #define BYTES_OUT 1 288 #define BITS_OUT 2 289 #define PACKETS_OUT 3 290 #define ERRORS_OUT 4 291 292 #define RATE_OUT 1 293 #if EXTENDED_STATS 294 #define MAX_OUT 2 295 #define SUM_OUT 3 296 #define AVG_OUT 4 297 #define TYPE_OUT_MAX 4 298 #else 299 #define TYPE_OUT_MAX 1 300 #endif 301 302 /* default length of avg in 1/1000sec */ 303 #define AVG_LENGTH 30000 304 305 #ifndef PATH_MAX 306 #define PATH_MAX 4096 307 #endif 308 309 #define WRAP_AROUND ULONG_MAX 310 #define WRAP_32BIT 4294967295ul 311 312 #ifdef SYS_64BIT 313 #ifdef HAVE_UNSIGNED_LONG_LONG 314 315 #undef WRAP_AROUND 316 #define WRAP_AROUND 18446744073709551615ull 317 318 #endif 319 #endif 320 321 #define print_version printf("Bandwidth Monitor NG (" PACKAGE_NAME ") v" VERSION "\nCopyright (C) 2004-2007 Volker Gropp <" PACKAGE_BUGREPORT ">\n"); 322 323 #ifndef EXIT_SUCCESS 324 #define EXIT_SUCCESS 0 325 #endif 326 327 #ifndef EXIT_FAILURE 328 #define EXIT_FAILURE 1 329 #endif 330 331 #ifndef HAVE_STRLCPY 332 #define strlcpy(_a,_b,_c) strncpy((_a),(_b),(_c)); (_a)[(_c) - 1]='\0'; 333 #endif 334 335 #endif 336