From 58b28832058af45b58eaa6abbb60139f986c8e10 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 17 Feb 2008 23:10:56 +0000 Subject: [PATCH] OpenBSD 4.0 sigar_tcp_get impl --- src/os/darwin/darwin_sigar.c | 30 ++++++++++++++++++++++++------ src/os/darwin/sigar_os.h | 3 +++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 96564688..d71364d8 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -81,6 +81,18 @@ #include #include +#ifndef DARWIN +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif + #define NMIB(mib) (sizeof(mib)/sizeof(mib[0])) #ifdef __FreeBSD__ @@ -147,6 +159,9 @@ static int get_koffsets(sigar_t *sigar) struct nlist klist[] = { { "_cp_time" }, { "_cnt" }, +#if !defined(TCPCTL_STATS) && defined(__OpenBSD__) + { "_tcpstat" }, +#endif { NULL } }; @@ -2280,12 +2295,6 @@ int sigar_net_interface_stat_get(sigar_t *sigar, const char *name, } #ifndef __OpenBSD__ -#include -#include -#include -#include -#include - static int net_connection_get(sigar_net_connection_walker_t *walker, int proto) { int flags = walker->flags; @@ -2470,12 +2479,21 @@ sigar_tcp_get(sigar_t *sigar, sigar_tcp_t *tcp) { struct tcpstat mib; +#if !defined(TCPCTL_STATS) && defined(__OpenBSD__) + int status = + kread(sigar, &mib, sizeof(mib), + sigar->koffsets[KOFFSET_TCPSTAT]); + if (status != SIGAR_OK) { + return status; + } +#else int var[4] = { CTL_NET, PF_INET, IPPROTO_TCP, TCPCTL_STATS }; size_t len = sizeof(mib); if (sysctl(var, NMIB(var), &mib, &len, NULL, 0) < 0) { return errno; } +#endif tcp->active_opens = mib.tcps_connattempt; tcp->passive_opens = mib.tcps_accepts; diff --git a/src/os/darwin/sigar_os.h b/src/os/darwin/sigar_os.h index 1c2e15ab..29989b73 100644 --- a/src/os/darwin/sigar_os.h +++ b/src/os/darwin/sigar_os.h @@ -31,6 +31,9 @@ enum { KOFFSET_CPUINFO, KOFFSET_VMMETER, +#if defined(__OpenBSD__) + KOFFSET_TCPSTAT, +#endif KOFFSET_MAX };