ProcPort udp support

This commit is contained in:
Doug MacEachern 2005-03-20 03:20:28 +00:00
parent 2fb7a2fab3
commit 2582ada2b9
2 changed files with 61 additions and 28 deletions

View File

@ -84,6 +84,9 @@ typedef DWORD (CALLBACK *LPGETUDPTABLE)(PMIB_UDPTABLE, PDWORD, BOOL);
typedef DWORD (CALLBACK *LPGETTCPEXTABLE)(PMIB_TCPEXTABLE *, BOOL, HANDLE, typedef DWORD (CALLBACK *LPGETTCPEXTABLE)(PMIB_TCPEXTABLE *, BOOL, HANDLE,
DWORD, DWORD); DWORD, DWORD);
typedef DWORD (CALLBACK *LPGETUDPEXTABLE)(PMIB_UDPEXTABLE *, BOOL, HANDLE,
DWORD, DWORD);
typedef DWORD (CALLBACK *LPSYSINFO)(DWORD, PVOID, ULONG, PULONG); typedef DWORD (CALLBACK *LPSYSINFO)(DWORD, PVOID, ULONG, PULONG);
/* no longer in the standard header files */ /* no longer in the standard header files */
@ -124,6 +127,7 @@ struct sigar_t {
LPGETTCPTABLE get_tcp_table; LPGETTCPTABLE get_tcp_table;
LPGETTCPEXTABLE get_tcpx_table; LPGETTCPEXTABLE get_tcpx_table;
LPGETUDPTABLE get_udp_table; LPGETUDPTABLE get_udp_table;
LPGETUDPEXTABLE get_udpx_table;
LPSYSINFO get_ntsys_info; LPSYSINFO get_ntsys_info;
sigar_win32_pinfo_t pinfo; sigar_win32_pinfo_t pinfo;
WORD ws_version; WORD ws_version;

View File

@ -209,6 +209,10 @@ int sigar_os_open(sigar_t **sigar)
"TcpExTableFromStack"); "TcpExTableFromStack");
(*sigar)->get_udp_table = (*sigar)->get_udp_table =
(LPGETUDPTABLE)GetProcAddress(h, "GetUdpTable"); (LPGETUDPTABLE)GetProcAddress(h, "GetUdpTable");
(*sigar)->get_udpx_table =
(LPGETUDPEXTABLE)GetProcAddress(h,
"AllocateAndGet"
"UdpExTableFromStack");
(*sigar)->ip_handle = h; (*sigar)->ip_handle = h;
} }
else { else {
@ -2156,18 +2160,15 @@ SIGAR_DECLARE(int) sigar_proc_port_get(sigar_t *sigar,
unsigned long port, unsigned long port,
sigar_pid_t *pid) sigar_pid_t *pid)
{ {
int status;
DWORD rc, i; DWORD rc, i;
if (protocol == SIGAR_NETCONN_TCP) {
PMIB_TCPEXTABLE tcp; PMIB_TCPEXTABLE tcp;
if (!sigar->get_tcpx_table) { if (!sigar->get_tcpx_table) {
return SIGAR_ENOTIMPL; return SIGAR_ENOTIMPL;
} }
if (protocol != SIGAR_NETCONN_TCP) {
return SIGAR_ENOTIMPL; /* XXX UDP */
}
rc = sigar->get_tcpx_table(&tcp, FALSE, GetProcessHeap(), rc = sigar->get_tcpx_table(&tcp, FALSE, GetProcessHeap(),
2, 2); 2, 2);
@ -2188,6 +2189,34 @@ SIGAR_DECLARE(int) sigar_proc_port_get(sigar_t *sigar,
return SIGAR_OK; return SIGAR_OK;
} }
}
else if (protocol == SIGAR_NETCONN_UDP) {
PMIB_UDPEXTABLE udp;
if (!sigar->get_udpx_table) {
return SIGAR_ENOTIMPL;
}
rc = sigar->get_udpx_table(&udp, FALSE, GetProcessHeap(),
2, 2);
if (rc) {
return GetLastError();
}
for (i=0; i<udp->dwNumEntries; i++) {
if (htons((WORD)udp->table[i].dwLocalPort) != port) {
continue;
}
*pid = udp->table[i].dwProcessId;
return SIGAR_OK;
}
}
else {
return SIGAR_ENOTIMPL;
}
return ENOENT; return ENOENT;
} }