1 /* 2 * Copyright 2003,2005,2006 Bernhard Walle <bernhard@bwalle.de> 3 * Copyright 2010 Florian Rivoal <frivoal@gmail.com> 4 * ------------------------------------------------------------------------------------------------- 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License as published by the Free 8 * Software Foundation; either version 2 of the License, or (at your option) 9 * any later version. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 * more details. 15 * 16 * You should have received a copy of the GNU General Public License along with 17 * this program; if not, write to the Free Software Foundation, Inc., 675 Mass 18 * Ave, Cambridge, MA 02139, USA. 19 * 20 * ------------------------------------------------------------------------------------------------- 21 */ 22 #ifndef NET_H 23 #define NET_H 24 25 #include "os.h" 26 #include "slurm.h" 27 28 #define MSGSIZE 1024 29 #define UP_UPDATE_INTERVAL 20 30 #define IP_UPDATE_INTERVAL 20 31 #define IP_ADDRESS_LENGTH 64 32 #define INTERFACE_NAME_LENGTH 33 33 34 #ifndef gettext_noop 35 #define gettext_noop(String) String 36 #endif 37 38 /** errorcodes */ 39 typedef enum 40 { 41 UNKNOWN_ERROR, 42 PROC_DEVICE_NOT_FOUND, 43 INTERFACE_NOT_FOUND 44 } errorcode_t; 45 46 47 /** 48 * We need this because we cannot use static variables. Using of static variables allows 49 * us not to use several instances of the plugin. 50 * I know that this change makes it a bit incompatible with wormulon, but that's the 51 * price to pay ... 52 */ 53 typedef struct 54 { 55 char old_interface[INTERFACE_NAME_LENGTH]; 56 double backup_in; 57 errorcode_t errorcode; 58 double backup_out; 59 double cur_in; 60 double cur_out; 61 struct timeval prev_time; 62 int correct_interface; /* treated as boolean */ 63 IfData ifdata; 64 char ip_address[IP_ADDRESS_LENGTH]; 65 int ip_update_count; 66 DataStats stats; 67 int up; 68 int up_update_count; 69 #if defined(__HPUX__) 70 int wait_pcks_counter; 71 nmapi_logstat* if_ptr; 72 #elif (defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)) 73 int watchif; 74 int dev_opened; 75 #elif defined(__NetBSD__) 76 int mib_name1[6]; 77 int mib_name2[6]; 78 char* buf1; 79 char* buf2; 80 int alloc1; 81 int alloc2; 82 #elif (defined(__OpenBSD__) || defined(__MicroBSD__) || defined(__APPLE__)) 83 int mib_name1[6]; 84 int mib_name2[6]; 85 char* buf1; 86 char* buf2; 87 int alloc1; 88 int alloc2; 89 #elif defined(__linux__) 90 FILE* proc_net_dev; 91 #elif defined(__Solaris__) 92 #else 93 #error "OS not supported" 94 #endif 95 96 } netdata; 97 98 99 /** 100 * Initializes the netload plugin. Used to set up inital values. This function must 101 * be called after each change of the network interface. 102 * @param device The network device, e.g. <code>ippp0</code> for ISDN on Linux. 103 * @return <code>true</code> if no error occurs, <code>false</code> otherwise. If there's 104 * an error, the error message may be set 105 */ 106 int init_netload(netdata* data, const char* device); 107 108 /** 109 * Gets the current netload. You must call init_netload() once before you use this function! 110 * @param in Input load in byte/s. 111 * @param out Output load in byte/s. 112 * @param tot Total load in byte/s. 113 */ 114 void get_current_netload(netdata* data, unsigned long *in, unsigned long *out, unsigned long *tot); 115 116 /** 117 * Returns the name of the network interface. 118 * @param data object 119 * @return The name. String resides in data and you don't have to free the string. 120 * On error, returns NULL. 121 */ 122 char* get_name(netdata* data); 123 124 /** 125 * Check to see if an interface is up. 126 * @param data object 127 * @return <code>true</code> if interface is up, <code>false</code> otherwise. 128 */ 129 int get_interface_up(netdata* data); 130 131 132 /** 133 * Returns the IP address of the network interface 134 * @param data object 135 * @return the IP address as string, NULL on error. 136 */ 137 char* get_ip_address(netdata* data); 138 139 /** 140 * Should be called to do cleanup work. 141 */ 142 void close_netload(netdata* data); 143 144 #endif /* NET_H */ 145