Ticket #382: Updated ICE from draft-ietf-mmusic-ice-14 to ice-18 specification, and also done some other tweaks as well

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1450 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/ip_helper_win32.c b/pjlib/src/pj/ip_helper_win32.c
index 69ff16a..1a937d7 100644
--- a/pjlib/src/pj/ip_helper_win32.c
+++ b/pjlib/src/pj/ip_helper_win32.c
@@ -34,16 +34,22 @@
 #include <pj/errno.h>
 #include <pj/string.h>
 
+#ifndef PJ_IP_HELPER_IGNORE_LOOPBACK_IF
+#   define PJ_IP_HELPER_IGNORE_LOOPBACK_IF	1
+#endif
+
 typedef DWORD (WINAPI *PFN_GetIpAddrTable)(PMIB_IPADDRTABLE pIpAddrTable, 
 					   PULONG pdwSize, 
 					   BOOL bOrder);
 typedef DWORD (WINAPI *PFN_GetIpForwardTable)(PMIB_IPFORWARDTABLE pIpForwardTable,
 					      PULONG pdwSize, 
 					      BOOL bOrder);
+typedef DWORD (WINAPI *PFN_GetIfEntry)(PMIB_IFROW pIfRow);
 
 static HANDLE s_hDLL;
 static PFN_GetIpAddrTable s_pfnGetIpAddrTable;
 static PFN_GetIpForwardTable s_pfnGetIpForwardTable;
+static PFN_GetIfEntry s_pfnGetIfEntry;
 
 static void unload_iphlp_module(void)
 {
@@ -85,6 +91,23 @@
 }
 
 
+#if PJ_IP_HELPER_IGNORE_LOOPBACK_IF
+static DWORD MyGetIfEntry(MIB_IFROW *pIfRow)
+{
+    if(NULL == s_pfnGetIfEntry) {
+	s_pfnGetIfEntry = (PFN_GetIfEntry) 
+	    GetIpHlpApiProc(PJ_T("GetIfEntry"));
+    }
+    
+    if(NULL != s_pfnGetIfEntry) {
+	return s_pfnGetIfEntry(pIfRow);
+    }
+    
+    return ERROR_NOT_SUPPORTED;
+}
+#endif
+
+
 static DWORD MyGetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, 
 				 PULONG pdwSize, 
 				 BOOL bOrder)
@@ -134,9 +157,23 @@
     count = (pTab->dwNumEntries < *p_cnt) ? pTab->dwNumEntries : *p_cnt;
     *p_cnt = 0;
     for (i=0; i<count; ++i) {
+	MIB_IFROW ifRow;
+
 	/* Some Windows returns 0.0.0.0! */
 	if (pTab->table[i].dwAddr == 0)
 	    continue;
+
+#if PJ_IP_HELPER_IGNORE_LOOPBACK_IF
+	/* Investigate the type of this interface */
+	pj_bzero(&ifRow, sizeof(ifRow));
+	ifRow.dwIndex = pTab->table[i].dwIndex;
+	if (MyGetIfEntry(&ifRow) != 0)
+	    continue;
+
+	if (ifRow.dwType == MIB_IF_TYPE_LOOPBACK)
+	    continue;
+#endif
+
 	ifs[*p_cnt].s_addr = pTab->table[i].dwAddr;
 	(*p_cnt)++;
     }