-int main(int argc, char *argv[])
-{
- PMIB_TCPTABLE tcpTable;
- PMIB_UDPTABLE udpTable;
- DWORD error, dwSize;
- DWORD i, flags;
-
- // Get options
- if (!GetOptions(argc, argv, &flags)) {
- return -1;
- } else {
- // Get the table of TCP endpoints
- dwSize = 0;
- error = GetTcpTable(NULL, &dwSize, TRUE);
- if (error != ERROR_INSUFFICIENT_BUFFER) {
- printf("Failed to snapshot TCP endpoints.\n");
- PrintError(error);
- return -1;
- }
- tcpTable = (PMIB_TCPTABLE)malloc(dwSize);
- error = GetTcpTable(tcpTable, &dwSize, TRUE );
- if (error) {
- printf("Failed to snapshot TCP endpoints table.\n");
- PrintError(error);
- return -1;
- }
-
- // Get the table of UDP endpoints
- dwSize = 0;
- error = GetUdpTable(NULL, &dwSize, TRUE);
- if (error != ERROR_INSUFFICIENT_BUFFER) {
- printf("Failed to snapshot UDP endpoints.\n");
- PrintError(error);
- return -1;
- }
- udpTable = (PMIB_UDPTABLE)malloc(dwSize);
- error = GetUdpTable(udpTable, &dwSize, TRUE);
- if (error) {
- printf("Failed to snapshot UDP endpoints table.\n");
- PrintError(error);
- return -1;
- }
-
- // Dump the TCP table
- for (i = 0; i < tcpTable->dwNumEntries; i++) {
- if (flags & FLAG_SHOW_ALL_ENDPOINTS ||
- tcpTable->table[i].dwState == MIB_TCP_STATE_ESTAB) {
- sprintf(localaddr, "%s:%s",
- GetIpHostName(flags, TRUE, tcpTable->table[i].dwLocalAddr, localname, HOSTNAMELEN),
- GetPortName(flags, tcpTable->table[i].dwLocalPort, "tcp", localport, PORTNAMELEN));
- sprintf(remoteaddr, "%s:%s",
- GetIpHostName(flags, FALSE, tcpTable->table[i].dwRemoteAddr, remotename, HOSTNAMELEN),
- tcpTable->table[i].dwRemoteAddr ?
- GetPortName(flags, tcpTable->table[i].dwRemotePort, "tcp", remoteport, PORTNAMELEN):
- "0");
- printf("%4s\tState: %s\n", "[TCP]", TcpState[tcpTable->table[i].dwState]);
- printf(" Local: %s\n Remote: %s\n", localaddr, remoteaddr);
- }
- }
- // Dump the UDP table
- if (flags & FLAG_SHOW_ALL_ENDPOINTS) {
- for (i = 0; i < udpTable->dwNumEntries; i++) {
- sprintf(localaddr, "%s:%s",
- GetIpHostName(flags, TRUE, udpTable->table[i].dwLocalAddr, localname, HOSTNAMELEN),
- GetPortName(flags, udpTable->table[i].dwLocalPort, "tcp", localport, PORTNAMELEN));
- printf("%4s", "[UDP]");
- printf(" Local: %s\n Remote: %s\n", localaddr, "*.*.*.*:*");
- }
- }
- }
- printf("\n");
- return 0;
-}
-
-#else