implement net_connection_walk for win32

This commit is contained in:
Doug MacEachern 2006-07-01 19:07:15 +00:00
parent 5f8da2ce15
commit 336c22d863
1 changed files with 17 additions and 21 deletions

View File

@ -2031,10 +2031,10 @@ sigar_net_interface_stat_get(sigar_t *sigar, const char *name,
#define sigar_GetTcpTable \ #define sigar_GetTcpTable \
sigar->iphlpapi.get_tcp_table.func sigar->iphlpapi.get_tcp_table.func
static int net_conn_get_tcp(sigar_t *sigar, static int net_conn_get_tcp(sigar_net_connection_walker_t *walker)
sigar_net_connection_list_t *connlist,
int flags)
{ {
sigar_t *sigar = walker->sigar;
int flags = walker->flags;
int status; int status;
DWORD rc, size=0, i; DWORD rc, size=0, i;
PMIB_TCPTABLE tcp; PMIB_TCPTABLE tcp;
@ -2119,9 +2119,9 @@ static int net_conn_get_tcp(sigar_t *sigar,
break; break;
} }
SIGAR_NET_CONNLIST_GROW(connlist); if (walker->add_connection(walker, &conn) != SIGAR_OK) {
memcpy(&connlist->data[connlist->number++], break;
&conn, sizeof(conn)); }
} }
free(tcp); free(tcp);
@ -2137,10 +2137,10 @@ static int net_conn_get_tcp(sigar_t *sigar,
#define sigar_GetUdpTable \ #define sigar_GetUdpTable \
sigar->iphlpapi.get_udp_table.func sigar->iphlpapi.get_udp_table.func
static int net_conn_get_udp(sigar_t *sigar, static int net_conn_get_udp(sigar_net_connection_walker_t *walker)
sigar_net_connection_list_t *connlist,
int flags)
{ {
sigar_t *sigar = walker->sigar;
int flags = walker->flags;
int status; int status;
DWORD rc, size=0, i; DWORD rc, size=0, i;
PMIB_UDPTABLE udp; PMIB_UDPTABLE udp;
@ -2183,9 +2183,9 @@ static int net_conn_get_udp(sigar_t *sigar,
conn.send_queue = conn.receive_queue = SIGAR_FIELD_NOTIMPL; conn.send_queue = conn.receive_queue = SIGAR_FIELD_NOTIMPL;
SIGAR_NET_CONNLIST_GROW(connlist); if (walker->add_connection(walker, &conn) != SIGAR_OK) {
memcpy(&connlist->data[connlist->number++], break;
&conn, sizeof(conn)); }
} }
free(udp); free(udp);
@ -2193,24 +2193,20 @@ static int net_conn_get_udp(sigar_t *sigar,
} }
SIGAR_DECLARE(int) SIGAR_DECLARE(int)
sigar_net_connection_list_get(sigar_t *sigar, sigar_net_connection_walk(sigar_net_connection_walker_t *walker)
sigar_net_connection_list_t *connlist,
int flags)
{ {
int status; int status;
sigar_net_connection_list_create(connlist); if (walker->flags & SIGAR_NETCONN_TCP) {
status = net_conn_get_tcp(walker);
if (flags & SIGAR_NETCONN_TCP) {
status = net_conn_get_tcp(sigar, connlist, flags);
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
return status; return status;
} }
} }
if (flags & SIGAR_NETCONN_UDP) { if (walker->flags & SIGAR_NETCONN_UDP) {
status = net_conn_get_udp(sigar, connlist, flags); status = net_conn_get_udp(walker);
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
return status; return status;