Skip to content

Commit

Permalink
Merge pull request #32 from vgropp/new-netstat-#5
Browse files Browse the repository at this point in the history
feat: add support for newer (2016+) linux netstat #5
  • Loading branch information
vgropp authored Jan 10, 2021
2 parents e8b0976 + 358739f commit b965470
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
30 changes: 30 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,26 @@ else
fi
])

AC_ARG_WITH([netstatlinuxnew],AS_HELP_STRING([--with-netstatlinuxnew],[enable linux newer versions ie 2016+ like netstat -i (ARG=PATH)]),[
if [ test $withval != "no" ]; then
if [ test $withval != "yes" ]; then
echo "GNU net-tools like version forced: $withval"
AC_DEFINE_UNQUOTED([HAVE_NETSTAT_PATH],[$withval],[set path to netstat])
else
echo "GNU net-tools like version forced"
fi
AC_DEFINE_UNQUOTED([NETSTAT_LINUX_NEW],[1],[use GNU net-tools netstat new versions])
if [ test $NETSTAT_ADDED -eq 0 ]; then
INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT"
NETSTAT_ADDED=1
fi
NETSTAT_DEFINED="1"
else
NETSTAT_DEFINED="1"
echo "disable netstat: GNU net-tools like new versions"
fi
])


AC_ARG_WITH([netstatsolaris],AS_HELP_STRING([--with-netstatsolaris],[enable solaris like netstat -i (ARG=PATH)]),[
if [ test $withval != "no" ]; then
Expand Down Expand Up @@ -727,6 +747,15 @@ if [ test "${EGREP}" ]; then
AC_CHECK_PROGS([NETSTAT_CMD],[netstat])
if [ test "${NETSTAT_CMD}" ]; then
AC_MSG_CHECKING([for netstat version])
net_test=`${NETSTAT_CMD} -ia 2>/dev/null | ${EGREP} "Iface +MTU +RX-OK +RX-ERR +RX-DRP +RX-OVR +TX-OK +TX-ERR +TX-DRP +TX-OVR +Flg"`
if [ test "${net_test}" ]; then
AC_MSG_RESULT([GNU net-tools like newer version found])
AC_DEFINE_UNQUOTED([NETSTAT_LINUX_NEW],[1],[use GNU net-tools netstat newer versions])
if [ test $NETSTAT_ADDED -eq 0 ]; then
INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT"
NETSTAT_ADDED=1
fi
else
net_test=`${NETSTAT_CMD} -ia 2>/dev/null | ${EGREP} "Iface +MTU +Met +RX-OK +RX-ERR +RX-DRP +RX-OVR +TX-OK +TX-ERR +TX-DRP +TX-OVR +Flg"`
if [ test "${net_test}" ]; then
AC_MSG_RESULT([GNU net-tools like version found])
Expand Down Expand Up @@ -792,6 +821,7 @@ echo "*********************************************
fi
fi
fi
fi
fi
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define SYSCTL
#endif

#if NETSTAT_LINUX || NETSTAT_BSD || NETSTAT_BSD_BYTES || NETSTAT_SOLARIS || NETSTAT_NETBSD
#if NETSTAT_LINUX_NEW || NETSTAT_LINUX || NETSTAT_BSD || NETSTAT_BSD_BYTES || NETSTAT_SOLARIS || NETSTAT_NETBSD
#define NETSTAT 1
#endif

Expand Down
7 changes: 5 additions & 2 deletions src/input/netstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void get_iface_stats_netstat (char verbose) {
" -b"
#endif
#endif
#if NETSTAT_LINUX
#if NETSTAT_LINUX || NETSTAT_LINUX_NEW
show_all_if ? NETSTAT_PATH " -ia" : NETSTAT_PATH " -i"
#endif
#if NETSTAT_SOLARIS
Expand All @@ -95,7 +95,7 @@ void get_iface_stats_netstat (char verbose) {
str_buf=(char *)malloc(MAX_LINE_BUFFER);
#endif
buffer=(char *)malloc(MAX_LINE_BUFFER);
#ifdef NETSTAT_LINUX
#if NETSTAT_LINUX || NETSTAT_LINUX_NEW
/* we skip first 2 lines if not bsd at any mode */
if ((fgets(buffer,MAX_LINE_BUFFER,f) == NULL ) || (fgets(buffer,MAX_LINE_BUFFER,f) == NULL ))
deinit(1, "read of netstat failed: %s\n",strerror(errno));
Expand All @@ -112,6 +112,9 @@ void get_iface_stats_netstat (char verbose) {
#ifdef NETSTAT_LINUX
sscanf(buffer,"%s%*i%*i%llu%llu%*i%*i%llu%llu",name,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out);
#endif
#ifdef NETSTAT_LINUX_NEW
sscanf(buffer,"%s%*i%llu%llu%*i%*i%llu%llu",name,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out);
#endif
#if NETSTAT_BSD_BYTES
if (count_tokens(buffer)>10) /* including address */
sscanf(buffer,"%s%*i%*s%*s%llu%llu%llu%llu%llu%llu",name,&tmp_if_stats.packets.in,&tmp_if_stats.errors.in,&tmp_if_stats.bytes.in,&tmp_if_stats.packets.out,&tmp_if_stats.errors.out,&tmp_if_stats.bytes.out);
Expand Down

0 comments on commit b965470

Please sign in to comment.