You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
9.0 KiB

  1. From: Matthieu Baerts <matthieu.baerts@tessares.net>
  2. Subject: [PATCH] ifstat: v1.1-8.1 from Debian
  3. Extracted from:
  4. http://deb.debian.org/debian/pool/main/i/ifstat/ifstat_1.1-8.1.diff.gz
  5. Author:
  6. - Goswin von Brederlow <goswin-v-b@web.de>
  7. ChangeLog:
  8. * snmp.c: fix 2 pointer targets differ in signedness warnings
  9. * Adding upport for 64bit /proc/net/dev counters.
  10. * Clean up compiler warnings.
  11. Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
  12. ---
  13. data.c | 4 +-
  14. drivers.c | 36 ++++++++--------
  15. ifstat.c | 5 ++-
  16. ifstat.h | 6 +--
  17. snmp.c | 12 +++---
  18. diff --git a/data.c b/data.c
  19. index e29149b..9af27bf 100644
  20. --- a/data.c
  21. +++ b/data.c
  22. @@ -103,8 +103,8 @@ void ifstat_free_interface(struct ifstat_data *data) {
  23. }
  24. void ifstat_set_interface_stats(struct ifstat_data *data,
  25. - unsigned long bytesin,
  26. - unsigned long bytesout) {
  27. + unsigned long long bytesin,
  28. + unsigned long long bytesout) {
  29. if (data->bout > bytesout || data->bin > bytesin) {
  30. if (!ifstat_quiet)
  31. ifstat_error("warning: rollover for interface %s, reinitialising.", data->name);
  32. diff --git a/drivers.c b/drivers.c
  33. index d5ac501..2861fff 100644
  34. --- a/drivers.c
  35. +++ b/drivers.c
  36. @@ -140,6 +140,7 @@ char *strchr (), *strrchr ();
  37. static void examine_interface(struct ifstat_list *ifs, char *name,
  38. int ifflags, int iftype) {
  39. + (void)iftype;
  40. #ifdef IFF_LOOPBACK
  41. if ((ifflags & IFF_LOOPBACK) && !(ifs->flags & IFSTAT_LOOPBACK))
  42. return;
  43. @@ -242,6 +243,7 @@ static int ioctl_map_scan(int sd, struct ifreq *ifr, void *data) {
  44. static int ioctl_scan_interfaces(struct ifstat_driver *driver,
  45. struct ifstat_list *ifs) {
  46. int sd;
  47. + (void)driver;
  48. if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
  49. ifstat_perror("socket");
  50. @@ -256,7 +258,7 @@ static int ioctl_scan_interfaces(struct ifstat_driver *driver,
  51. #endif
  52. #ifdef USE_KSTAT
  53. -static int get_kstat_long(kstat_t *ksp, char *name, unsigned long *value) {
  54. +static int get_kstat_long(kstat_t *ksp, char *name, unsigned long long *value) {
  55. kstat_named_t *data;
  56. if ((data = kstat_data_lookup(ksp, name)) == NULL)
  57. @@ -277,7 +279,7 @@ static int get_kstat_long(kstat_t *ksp, char *name, unsigned long *value) {
  58. *value = data->value.ui64;
  59. break;
  60. #else
  61. - case KSTAT_DATA_LONGLONG:
  62. + case KSTAT_DATA_LONG LONGLONG:
  63. *value = data->value.ll;
  64. break;
  65. case KSTAT_DATA_ULONGLONG:
  66. @@ -311,7 +313,7 @@ static int kstat_open_driver(struct ifstat_driver *driver,
  67. static int kstat_get_stats(struct ifstat_driver *driver,
  68. struct ifstat_list *ifs) {
  69. - unsigned long bytesin, bytesout;
  70. + unsigned long long bytesin, bytesout;
  71. struct ifstat_data *cur;
  72. kstat_ctl_t *kc = driver->data;
  73. kstat_t *ksp;
  74. @@ -802,7 +804,7 @@ static int proc_get_stats(struct ifstat_driver *driver,
  75. char buf[1024];
  76. FILE *f;
  77. char *iface, *stats;
  78. - unsigned long bytesin, bytesout;
  79. + unsigned long long bytesin, bytesout;
  80. struct ifstat_data *cur;
  81. struct proc_driver_data *data = driver->data;
  82. char *file;
  83. @@ -839,7 +841,7 @@ static int proc_get_stats(struct ifstat_driver *driver,
  84. iface++;
  85. if (*iface == '\0')
  86. continue;
  87. - if (sscanf(stats, "%lu %*u %*u %*u %*u %*u %*u %*u %lu %*u", &bytesin, &bytesout) != 2)
  88. + if (sscanf(stats, "%llu %*u %*u %*u %*u %*u %*u %*u %llu %*u", &bytesin, &bytesout) != 2)
  89. continue;
  90. if ((cur = ifstat_get_interface(ifs, iface)) != NULL)
  91. @@ -1326,9 +1328,9 @@ static int win32_get_stats(struct ifstat_driver *driver,
  92. for (i = 0; i < iftable->dwNumEntries; i++) {
  93. if ((cur = ifstat_get_interface(ifs, iftable->table[i].bDescr)) != NULL)
  94. ifstat_set_interface_stats(cur,
  95. - (unsigned long)
  96. + (unsigned long long)
  97. iftable->table[i].dwInOctets,
  98. - (unsigned long)
  99. + (unsigned long long)
  100. iftable->table[i].dwOutOctets);
  101. }
  102. return 1;
  103. @@ -1346,40 +1348,40 @@ void win32_close_driver(struct ifstat_driver *driver) {
  104. static struct ifstat_driver drivers[] = {
  105. #ifdef USE_KSTAT
  106. { "kstat", &kstat_open_driver, &ioctl_scan_interfaces, &kstat_get_stats,
  107. - &kstat_close_driver },
  108. + &kstat_close_driver, NULL },
  109. #endif
  110. #ifdef USE_IFMIB
  111. - { "ifmib", NULL, &ifmib_scan_interfaces, &ifmib_get_stats, NULL },
  112. + { "ifmib", NULL, &ifmib_scan_interfaces, &ifmib_get_stats, NULL, NULL },
  113. #endif
  114. #ifdef USE_IFDATA
  115. { "ifdata", &ifdata_open_driver, &ifdata_scan_interfaces,
  116. - &ifdata_get_stats, &ifdata_close_driver },
  117. + &ifdata_get_stats, &ifdata_close_driver, NULL },
  118. #endif
  119. #ifdef USE_ROUTE
  120. { "route", &route_open_driver, &route_scan_interfaces,
  121. - &route_get_stats, &route_close_driver },
  122. + &route_get_stats, &route_close_driver, NULL },
  123. #endif
  124. #ifdef USE_KVM
  125. { "kvm", &kvm_open_driver, &kvm_scan_interfaces, &kvm_get_stats,
  126. - &kvm_close_driver },
  127. + &kvm_close_driver, NULL },
  128. #endif
  129. #ifdef USE_PROC
  130. { "proc", &proc_open_driver, &ioctl_scan_interfaces, &proc_get_stats,
  131. - &proc_close_driver },
  132. + &proc_close_driver, NULL },
  133. #endif
  134. #ifdef USE_DLPI
  135. { "dlpi", &dlpi_open_driver, &dlpi_scan_interfaces, &dlpi_get_stats,
  136. - &dlpi_close_driver },
  137. + &dlpi_close_driver, NULL },
  138. #endif
  139. #ifdef USE_WIN32
  140. { "win32", &win32_open_driver, &win32_scan_interfaces,
  141. - &win32_get_stats, &win32_close_driver },
  142. + &win32_get_stats, &win32_close_driver, NULL },
  143. #endif
  144. #ifdef USE_SNMP
  145. { "snmp", &snmp_open_driver, &snmp_scan_interfaces, &snmp_get_stats,
  146. - &snmp_close_driver },
  147. + &snmp_close_driver, NULL },
  148. #endif
  149. - { NULL } };
  150. + { NULL, NULL, NULL, NULL, NULL, NULL } };
  151. int ifstat_get_driver(char *name, struct ifstat_driver *driver) {
  152. int num = 0;
  153. diff --git a/ifstat.c b/ifstat.c
  154. index 942aa94..0521e71 100644
  155. --- a/ifstat.c
  156. +++ b/ifstat.c
  157. @@ -215,7 +215,8 @@ static RETSIGTYPE update_termsize(int sig) {
  158. int _sigcont = 0;
  159. #ifdef SIGCONT
  160. static RETSIGTYPE sigcont(int sig) {
  161. - _sigcont = 1;
  162. + (void)sig;
  163. + _sigcont = 1;
  164. RESIGNAL(SIGCONT, &sigcont);
  165. }
  166. #endif
  167. @@ -234,7 +235,7 @@ static RETSIGTYPE sigcont(int sig) {
  168. #define NUM "12345.12"
  169. #define NA " n/a"
  170. -#define WIDTH (sizeof(NUM) - 1) * 2 + (sizeof(SPACE) - 1)
  171. +#define WIDTH ((ssize_t)sizeof(NUM) - 1) * 2 + ((ssize_t)sizeof(SPACE) - 1)
  172. #define LEN(options, namelen) (((options) & OPT_FIXEDWIDTH || (namelen) < WIDTH) ? WIDTH : (namelen))
  173. #define FMT(n) (((n) < 1e+5) ? "%8.2f" : (((n) < 1e+6) ? "%.1f" : "%.2e"))
  174. diff --git a/ifstat.h b/ifstat.h
  175. index b63a3fb..dff38b6 100644
  176. --- a/ifstat.h
  177. +++ b/ifstat.h
  178. @@ -35,7 +35,7 @@
  179. struct ifstat_data {
  180. char *name;
  181. int namelen;
  182. - unsigned long obout, obin, bout, bin;
  183. + unsigned long long obout, obin, bout, bin;
  184. int flags, index;
  185. struct ifstat_data *next;
  186. };
  187. @@ -72,8 +72,8 @@ void ifstat_add_interface(struct ifstat_list *ifs, char *ifname, int flags);
  188. void ifstat_free_interface(struct ifstat_data *data);
  189. void ifstat_set_interface_stats(struct ifstat_data *data,
  190. - unsigned long bytesin,
  191. - unsigned long bytesout);
  192. + unsigned long long bytesin,
  193. + unsigned long long bytesout);
  194. void ifstat_set_interface_index(struct ifstat_data *data,
  195. int index);
  196. diff --git a/snmp.c b/snmp.c
  197. index 2457001..5dd8a0a 100644
  198. --- a/snmp.c
  199. +++ b/snmp.c
  200. @@ -91,7 +91,7 @@ static int snmp_get_ifcount(struct snmp_session *ss) {
  201. static int snmp_get_nextif(struct snmp_session *ss, int index) {
  202. oid ifindex[] = { 1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 0 };
  203. - int len = sizeof(ifindex) / sizeof(oid);
  204. + unsigned int len = sizeof(ifindex) / sizeof(oid);
  205. struct snmp_pdu *pdu;
  206. struct snmp_pdu *response = NULL;
  207. struct variable_list *vars;
  208. @@ -139,7 +139,7 @@ static int snmp_get_nextif(struct snmp_session *ss, int index) {
  209. struct ifsnmp {
  210. char name[S_IFNAMEMAX];
  211. - unsigned long bout, bin;
  212. + unsigned long long bout, bin;
  213. int flags, index;
  214. };
  215. @@ -248,7 +248,7 @@ static int snmp_get_ifinfos(struct snmp_session *ss, int nifaces,
  216. if (memcmp(ifinfo, vars->name, sizeof(ifinfo) - 2 * sizeof(oid)) != 0)
  217. continue;
  218. for(i = 0; i < nifaces; i++) {
  219. - if (ifsnmp[i].index == vars->name[10])
  220. + if ((signed long long)ifsnmp[i].index == (signed long long)vars->name[10])
  221. break;
  222. }
  223. @@ -258,11 +258,11 @@ static int snmp_get_ifinfos(struct snmp_session *ss, int nifaces,
  224. switch (vars->name[9]) {
  225. case ifDescr:
  226. if (vars->type == ASN_OCTET_STR) {
  227. - int count = vars->val_len;
  228. + unsigned int count = vars->val_len;
  229. if (count >= sizeof(ifsnmp[i].name))
  230. count = sizeof(ifsnmp[i].name) - 1;
  231. - strncpy(ifsnmp[i].name, vars->val.string, count);
  232. + strncpy(ifsnmp[i].name, (char *)vars->val.string, count);
  233. ifsnmp[i].name[count] = '\0';
  234. }
  235. break;
  236. @@ -361,7 +361,7 @@ int snmp_open_driver(struct ifstat_driver *driver, char *options) {
  237. snmp_sess_init(&session);
  238. session.peername = host;
  239. session.version = SNMP_VERSION_1;
  240. - session.community = community;
  241. + session.community = (unsigned char *)community;
  242. session.community_len = strlen(community);
  243. if ((data->session = snmp_open(&session)) == NULL) {