func netStatTcpCount(laddres net.IP, lNet *net.IPNet, lport int, raddres net.IP, rNet *net.IPNet, rport int,
//go:build linux || (windows && amd64)
// +build linux windows,amd64
** Copyright (C) 2001-2023 Zabbix SIA
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"github.com/sokurenko/go-netstat/netstat"
// exportNetTcpSocketCount - returns number of TCP sockets that match parameters.
func (p *Plugin) exportNetTcpSocketCount(params []string) (result int, err error) {
return 0, errors.New(errorTooManyParams)
if len(params) > 0 && len(params[0]) > 0 {
if ip := net.ParseIP(params[0]); ip != nil {
} else if _, lNet, err = net.ParseCIDR(params[0]); err != nil {
return 0, errors.New(errorInvalidFirstParam)
if len(params) > 1 && len(params[1]) > 0 {
if port, err := strconv.ParseUint(params[1], 10, 16); err != nil {
if lport, err = net.LookupPort("tcp", params[1]); err != nil {
if lport, err = net.LookupPort("tcp6", params[1]); err != nil {
return 0, errors.New(errorInvalidSecondParam)