Skip to content

Commit b965470

Browse files
authored
Merge pull request #32 from vgropp/new-netstat-#5
feat: add support for newer (2016+) linux netstat #5
2 parents e8b0976 + 358739f commit b965470

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

configure.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,26 @@ else
676676
fi
677677
])
678678

679+
AC_ARG_WITH([netstatlinuxnew],AS_HELP_STRING([--with-netstatlinuxnew],[enable linux newer versions ie 2016+ like netstat -i (ARG=PATH)]),[
680+
if [ test $withval != "no" ]; then
681+
if [ test $withval != "yes" ]; then
682+
echo "GNU net-tools like version forced: $withval"
683+
AC_DEFINE_UNQUOTED([HAVE_NETSTAT_PATH],[$withval],[set path to netstat])
684+
else
685+
echo "GNU net-tools like version forced"
686+
fi
687+
AC_DEFINE_UNQUOTED([NETSTAT_LINUX_NEW],[1],[use GNU net-tools netstat new versions])
688+
if [ test $NETSTAT_ADDED -eq 0 ]; then
689+
INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT"
690+
NETSTAT_ADDED=1
691+
fi
692+
NETSTAT_DEFINED="1"
693+
else
694+
NETSTAT_DEFINED="1"
695+
echo "disable netstat: GNU net-tools like new versions"
696+
fi
697+
])
698+
679699

680700
AC_ARG_WITH([netstatsolaris],AS_HELP_STRING([--with-netstatsolaris],[enable solaris like netstat -i (ARG=PATH)]),[
681701
if [ test $withval != "no" ]; then
@@ -727,6 +747,15 @@ if [ test "${EGREP}" ]; then
727747
AC_CHECK_PROGS([NETSTAT_CMD],[netstat])
728748
if [ test "${NETSTAT_CMD}" ]; then
729749
AC_MSG_CHECKING([for netstat version])
750+
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"`
751+
if [ test "${net_test}" ]; then
752+
AC_MSG_RESULT([GNU net-tools like newer version found])
753+
AC_DEFINE_UNQUOTED([NETSTAT_LINUX_NEW],[1],[use GNU net-tools netstat newer versions])
754+
if [ test $NETSTAT_ADDED -eq 0 ]; then
755+
INPUT_SYSTEM="$INPUT_SYSTEM netstat.$OBJEXT"
756+
NETSTAT_ADDED=1
757+
fi
758+
else
730759
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"`
731760
if [ test "${net_test}" ]; then
732761
AC_MSG_RESULT([GNU net-tools like version found])
@@ -792,6 +821,7 @@ echo "*********************************************
792821
fi
793822
fi
794823
fi
824+
fi
795825
fi
796826
fi
797827
fi

src/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define SYSCTL
4040
#endif
4141

42-
#if NETSTAT_LINUX || NETSTAT_BSD || NETSTAT_BSD_BYTES || NETSTAT_SOLARIS || NETSTAT_NETBSD
42+
#if NETSTAT_LINUX_NEW || NETSTAT_LINUX || NETSTAT_BSD || NETSTAT_BSD_BYTES || NETSTAT_SOLARIS || NETSTAT_NETBSD
4343
#define NETSTAT 1
4444
#endif
4545

src/input/netstat.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void get_iface_stats_netstat (char verbose) {
7676
" -b"
7777
#endif
7878
#endif
79-
#if NETSTAT_LINUX
79+
#if NETSTAT_LINUX || NETSTAT_LINUX_NEW
8080
show_all_if ? NETSTAT_PATH " -ia" : NETSTAT_PATH " -i"
8181
#endif
8282
#if NETSTAT_SOLARIS
@@ -95,7 +95,7 @@ void get_iface_stats_netstat (char verbose) {
9595
str_buf=(char *)malloc(MAX_LINE_BUFFER);
9696
#endif
9797
buffer=(char *)malloc(MAX_LINE_BUFFER);
98-
#ifdef NETSTAT_LINUX
98+
#if NETSTAT_LINUX || NETSTAT_LINUX_NEW
9999
/* we skip first 2 lines if not bsd at any mode */
100100
if ((fgets(buffer,MAX_LINE_BUFFER,f) == NULL ) || (fgets(buffer,MAX_LINE_BUFFER,f) == NULL ))
101101
deinit(1, "read of netstat failed: %s\n",strerror(errno));
@@ -112,6 +112,9 @@ void get_iface_stats_netstat (char verbose) {
112112
#ifdef NETSTAT_LINUX
113113
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);
114114
#endif
115+
#ifdef NETSTAT_LINUX_NEW
116+
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);
117+
#endif
115118
#if NETSTAT_BSD_BYTES
116119
if (count_tokens(buffer)>10) /* including address */
117120
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);

0 commit comments

Comments
 (0)