fix net_connection filters

This commit is contained in:
Doug MacEachern 2005-05-07 06:00:55 +00:00
parent 8ff8a5a02e
commit e451aa4da6
1 changed files with 18 additions and 11 deletions

View File

@ -2005,6 +2005,12 @@ static void ip_format(char *buffer, int buflen, UINT addr)
((ip) & 0xFF)); ((ip) & 0xFF));
} }
#define IS_TCP_SERVER(state, flags) \
((flags & SIGAR_NETCONN_SERVER) && (state == MIB_TCP_STATE_LISTEN))
#define IS_TCP_CLIENT(state, flags) \
((flags & SIGAR_NETCONN_CLIENT) && (state != MIB_TCP_STATE_LISTEN))
static int net_conn_get_tcp(sigar_t *sigar, static int net_conn_get_tcp(sigar_t *sigar,
sigar_net_connection_list_t *connlist, sigar_net_connection_list_t *connlist,
int flags) int flags)
@ -2029,15 +2035,10 @@ static int net_conn_get_tcp(sigar_t *sigar,
sigar_net_connection_t conn; sigar_net_connection_t conn;
DWORD state = tcp->table[i].dwState; DWORD state = tcp->table[i].dwState;
if (flags & SIGAR_NETCONN_SERVER) { if (!(IS_TCP_SERVER(state, flags) ||
if (state != MIB_TCP_STATE_LISTEN) { IS_TCP_CLIENT(state, flags)))
continue; {
} continue;
}
else if (flags & SIGAR_NETCONN_CLIENT) {
if (state == MIB_TCP_STATE_LISTEN) {
continue;
}
} }
conn.local_port = htons((WORD)tcp->table[i].dwLocalPort); conn.local_port = htons((WORD)tcp->table[i].dwLocalPort);
@ -2104,6 +2105,12 @@ static int net_conn_get_tcp(sigar_t *sigar,
return SIGAR_OK; return SIGAR_OK;
} }
#define IS_UDP_SERVER(conn, flags) \
((flags & SIGAR_NETCONN_SERVER) && !conn.remote_port)
#define IS_UDP_CLIENT(state, flags) \
((flags & SIGAR_NETCONN_CLIENT) && conn.remote_port)
static int net_conn_get_udp(sigar_t *sigar, static int net_conn_get_udp(sigar_t *sigar,
sigar_net_connection_list_t *connlist, sigar_net_connection_list_t *connlist,
int flags) int flags)
@ -2127,8 +2134,8 @@ static int net_conn_get_udp(sigar_t *sigar,
for (i = 0; i < udp->dwNumEntries; i++) { for (i = 0; i < udp->dwNumEntries; i++) {
sigar_net_connection_t conn; sigar_net_connection_t conn;
if (!((conn.remote_port && (flags & SIGAR_NETCONN_CLIENT)) || if (!(IS_UDP_SERVER(conn, flags) ||
(!conn.remote_port && (flags & SIGAR_NETCONN_SERVER)))) IS_UDP_CLIENT(conn, flags)))
{ {
continue; continue;
} }