// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>

using namespace std;

#include <windows.h>

// I have a compiler setup problem - this is a hack
#define PMIB_ICMP_EX void*

#include <iphlpapi.h>

int main()
{
   char buf[100000];
   DWORD len = sizeof(buf);
   GetTcpTable((MIB_TCPTABLE *)buf,&len,1);
   MIB_TCPTABLE *table = (MIB_TCPTABLE *)buf;
   MIB_TCPROW *row = table->table;
   for(int i=0;i<table->dwNumEntries;i++)
   {
       cout << ntohs((short)row[i].dwLocalPort) << endl;
   }
   return 0;
}
