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.

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