There is two options, either use GetTcpTable2 or GetExtendedTcpTable.
The best choice seems to use GetExtendedTcpTable because it is supported beginning with XP SP2, Windows 2003 SP1 however its api is fairly complex and involves new structures to be defined.