Index: /pjproject/trunk/pjlib/include/pj/ip_helper.h
===================================================================
--- /pjproject/trunk/pjlib/include/pj/ip_helper.h	(revision 6044)
+++ /pjproject/trunk/pjlib/include/pj/ip_helper.h	(revision 6045)
@@ -27,4 +27,5 @@
 
 #include <pj/sock.h>
+#include <pj/string.h>
 
 PJ_BEGIN_DECL
@@ -53,4 +54,41 @@
 } pj_ip_route_entry;
 
+/**
+ * This structure describes options for pj_enum_ip_interface2().
+ */
+typedef struct pj_enum_ip_option
+{
+    /**
+     * Family of the address to be retrieved. Application may specify
+     * pj_AF_UNSPEC() to retrieve all addresses, or pj_AF_INET() or
+     * pj_AF_INET6() to retrieve interfaces with specific address family.
+     *
+     * Default: pj_AF_UNSPEC().
+     */
+    int			af;
+
+    /**
+     * IPv6 addresses can have a DEPRECATED flag, if this flag is set, any
+     * DEPRECATED IPv6 address will be omitted. Currently this is only
+     * available for Linux, on other platforms, if this flag is set,
+     * pj_enum_ip_interface2() will return PJ_ENOTSUP.
+     *
+     * Default: PJ_FALSE.
+     */
+    pj_bool_t		omit_deprecated_ipv6;
+
+} pj_enum_ip_option;
+
+
+/**
+ * Get default values of IP enumeration option.
+ *
+ * @param opt	    The IP enumeration option.
+ */
+PJ_INLINE(void) pj_enum_ip_option_default(pj_enum_ip_option *opt)
+{
+    pj_bzero(opt, sizeof(*opt));
+}
+
 
 /**
@@ -76,4 +114,22 @@
 
 /**
+ * Enumerate the local IP interfaces currently active in the host with
+ * capability to filter DEPRECATED IPv6 addresses (currently only for Linux).
+ *
+ * @param opt	    The option, default option will be used if NULL.
+ * @param count	    On input, specify the number of entries. On output,
+ *		    it will be filled with the actual number of entries.
+ * @param ifs	    Array of socket (with flags) addresses, which address part
+ *		    will be filled with the interface address. The address
+ *		    family part will be initialized with the address
+ *		    family of the IP address.
+ *
+ * @return	    PJ_SUCCESS on success, or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_enum_ip_interface2(const pj_enum_ip_option *opt,
+					   unsigned *count,
+					   pj_sockaddr ifs[]);
+
+/**
  * Enumerate the IP routing table for this host.
  *
Index: /pjproject/trunk/pjlib/src/pj/ip_helper_generic.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/ip_helper_generic.c	(revision 6044)
+++ /pjproject/trunk/pjlib/src/pj/ip_helper_generic.c	(revision 6045)
@@ -26,4 +26,15 @@
 #include <pj/sock.h>
 
+
+#if defined(PJ_LINUX) && PJ_LINUX!=0
+/* The following headers are used to get DEPRECATED addresses */
+#include <arpa/inet.h>
+#include <asm/types.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
+
 /* Set to 1 to enable tracing */
 #if 0
@@ -408,2 +419,150 @@
 }
 
+static pj_status_t get_ipv6_deprecated(unsigned *count, pj_sockaddr addr[])
+{
+#if defined(PJ_LINUX) && PJ_LINUX!=0
+    struct {
+        struct nlmsghdr        nlmsg_info;
+        struct ifaddrmsg    ifaddrmsg_info;
+    } netlink_req;
+
+    long pagesize = sysconf(_SC_PAGESIZE);
+    if (!pagesize)
+        pagesize = 4096; /* Assume pagesize is 4096 if sysconf() failed */
+
+    int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+    if (fd < 0)
+	return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
+
+    bzero(&netlink_req, sizeof(netlink_req));
+
+    netlink_req.nlmsg_info.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+    netlink_req.nlmsg_info.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
+    netlink_req.nlmsg_info.nlmsg_type = RTM_GETADDR;
+    netlink_req.nlmsg_info.nlmsg_pid = getpid();
+    netlink_req.ifaddrmsg_info.ifa_family = AF_INET6;
+
+    int rtn = send(fd, &netlink_req, netlink_req.nlmsg_info.nlmsg_len, 0);
+    if (rtn < 0)
+	return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
+
+    char read_buffer[pagesize];
+    size_t idx = 0;
+
+    while(1) {
+	bzero(read_buffer, pagesize);
+	int read_size = recv(fd, read_buffer, pagesize, 0);
+	if (read_size < 0)
+	    return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
+
+	struct nlmsghdr *nlmsg_ptr = (struct nlmsghdr *) read_buffer;
+	int nlmsg_len = read_size;
+
+	if (nlmsg_len < sizeof (struct nlmsghdr))
+	    return PJ_ETOOSMALL;
+
+	if (nlmsg_ptr->nlmsg_type == NLMSG_DONE)
+	    break;
+
+	for(; NLMSG_OK(nlmsg_ptr, nlmsg_len);
+	    nlmsg_ptr = NLMSG_NEXT(nlmsg_ptr, nlmsg_len))
+	{
+	    struct ifaddrmsg *ifaddrmsg_ptr;
+	    struct rtattr *rtattr_ptr;
+	    int ifaddrmsg_len;
+
+	    ifaddrmsg_ptr = (struct ifaddrmsg*)NLMSG_DATA(nlmsg_ptr);
+
+	    if (ifaddrmsg_ptr->ifa_flags & IFA_F_DEPRECATED ||
+		ifaddrmsg_ptr->ifa_flags & IFA_F_TENTATIVE)
+	    {
+		rtattr_ptr = (struct rtattr*)IFA_RTA(ifaddrmsg_ptr);
+		ifaddrmsg_len = IFA_PAYLOAD(nlmsg_ptr);
+
+		for(;RTA_OK(rtattr_ptr, ifaddrmsg_len);
+		    rtattr_ptr = RTA_NEXT(rtattr_ptr, ifaddrmsg_len))
+		{
+		    switch(rtattr_ptr->rta_type) {
+		    case IFA_ADDRESS:
+			// Check if addr can contains more data
+			if (idx >= *count)
+			    break;
+			// Store deprecated IP
+			char deprecatedAddr[PJ_INET6_ADDRSTRLEN];
+			inet_ntop(ifaddrmsg_ptr->ifa_family,
+				  RTA_DATA(rtattr_ptr),
+				  deprecatedAddr,
+				  sizeof(deprecatedAddr));
+			pj_str_t pj_addr_str;
+			pj_cstr(&pj_addr_str, deprecatedAddr);
+			pj_sockaddr_init(pj_AF_INET6(), &addr[idx],
+					 &pj_addr_str, 0);
+			++idx;
+		    default:
+			break;
+		    }
+		}
+	    }
+	}
+    }
+
+    close(fd);
+    *count = idx;
+
+    return PJ_SUCCESS;
+#else
+    *count = 0;
+    return PJ_ENOTSUP;
+#endif
+}
+
+
+/*
+ * Enumerate the local IP interface currently active in the host.
+ */
+PJ_DEF(pj_status_t) pj_enum_ip_interface2( const pj_enum_ip_option *opt,
+					   unsigned *p_cnt,
+					   pj_sockaddr ifs[])
+{
+    pj_enum_ip_option opt_;
+
+    if (opt)
+	opt_ = *opt;
+    else
+	pj_enum_ip_option_default(&opt_);
+
+    if (opt_.af != pj_AF_INET() && opt_.omit_deprecated_ipv6) {
+	pj_sockaddr addrs[*p_cnt];
+	pj_sockaddr deprecatedAddrs[*p_cnt];
+	unsigned deprecatedCount = *p_cnt;
+	unsigned cnt = 0;
+	pj_status_t status;
+
+	status = get_ipv6_deprecated(&deprecatedCount, deprecatedAddrs);
+	if (status != PJ_SUCCESS)
+	    return status;
+
+	status = pj_enum_ip_interface(opt_.af, p_cnt, addrs);
+	if (status != PJ_SUCCESS)
+	    return status;
+
+	for (int i = 0; i < *p_cnt; ++i) {
+	    ifs[cnt++] = addrs[i];
+
+	    if (addrs[i].addr.sa_family != pj_AF_INET6())
+		continue;
+
+	    for (int j = 0; j < deprecatedCount; ++j) {
+		if (pj_sockaddr_cmp(&addrs[i], &deprecatedAddrs[j]) == 0) {
+		    cnt--;
+		    break;
+		}
+	    }
+	}
+
+	*p_cnt = cnt;
+	return *p_cnt ? PJ_SUCCESS : PJ_ENOTFOUND;
+    }
+
+    return pj_enum_ip_interface(opt_.af, p_cnt, ifs);
+}
Index: /pjproject/trunk/pjlib/src/pj/ip_helper_symbian.cpp
===================================================================
--- /pjproject/trunk/pjlib/src/pj/ip_helper_symbian.cpp	(revision 6044)
+++ /pjproject/trunk/pjlib/src/pj/ip_helper_symbian.cpp	(revision 6045)
@@ -139,4 +139,24 @@
 
 /*
+ * Enumerate the local IP interface currently active in the host.
+ */
+PJ_DEF(pj_status_t) pj_enum_ip_interface2( const pj_enum_ip_option *opt,
+					   unsigned *count,
+					   pj_sockaddr ifs[])
+{
+    pj_enum_ip_option opt_;
+
+    if (opt && opt->omit_deprecated_ipv6)
+	return PJ_ENOTSUP;
+
+    if (opt)
+	opt_ = *opt;
+    else
+	pj_enum_ip_option_default(&opt_);
+
+    return pj_enum_ip_interface(opt_.af, count, ifs);
+}
+
+/*
  * Enumerate the IP routing table for this host.
  */
Index: /pjproject/trunk/pjlib/src/pj/ip_helper_win32.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/ip_helper_win32.c	(revision 6044)
+++ /pjproject/trunk/pjlib/src/pj/ip_helper_win32.c	(revision 6045)
@@ -380,4 +380,26 @@
 }
 
+
+/*
+ * Enumerate the local IP interface currently active in the host.
+ */
+PJ_DEF(pj_status_t) pj_enum_ip_interface2( const pj_enum_ip_option *opt,
+					   unsigned *p_cnt,
+					   pj_sockaddr ifs[])
+{
+    pj_enum_ip_option opt_;
+
+    if (opt && opt->omit_deprecated_ipv6)
+	return PJ_ENOTSUP;
+
+    if (opt)
+	opt_ = *opt;
+    else
+	pj_enum_ip_option_default(&opt_);
+
+    return pj_enum_ip_interface(opt_.af, p_cnt, ifs);
+}
+
+
 /*
  * Enumerate the IP routing table for this host.
Index: /pjproject/trunk/pjlib/src/pj/ip_helper_winphone8.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/ip_helper_winphone8.c	(revision 6044)
+++ /pjproject/trunk/pjlib/src/pj/ip_helper_winphone8.c	(revision 6045)
@@ -42,4 +42,24 @@
 
 /*
+ * Enumerate the local IP interface currently active in the host.
+ */
+PJ_DEF(pj_status_t) pj_enum_ip_interface2( const pj_enum_ip_option *opt,
+					   unsigned *p_cnt,
+					   pj_sockaddr ifs[])
+{
+    PJ_UNUSED_ARG(opt);
+    PJ_UNUSED_ARG(ifs);
+
+    PJ_ASSERT_RETURN(p_cnt, PJ_EINVAL);
+
+    *p_cnt = 0;
+
+    return PJ_ENOTSUP;
+}
+
+
+
+
+/*
  * Enumerate the IP routing table for this host.
  */
Index: /pjproject/trunk/pjnath/src/pjnath/stun_sock.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/stun_sock.c	(revision 6044)
+++ /pjproject/trunk/pjnath/src/pjnath/stun_sock.c	(revision 6045)
@@ -683,5 +683,6 @@
     } else {
 	pj_sockaddr def_addr;
-	pj_uint16_t port = pj_sockaddr_get_port(&info->bound_addr); 
+	pj_uint16_t port = pj_sockaddr_get_port(&info->bound_addr);
+	pj_enum_ip_option enum_opt;
 	unsigned i;
 
@@ -698,7 +699,17 @@
 	
 	/* Enum all IP interfaces in the host */
+	pj_enum_ip_option_default(&enum_opt);
+	enum_opt.af = stun_sock->af;
+	enum_opt.omit_deprecated_ipv6 = PJ_TRUE;
 	info->alias_cnt = PJ_ARRAY_SIZE(info->aliases);
-	status = pj_enum_ip_interface(stun_sock->af, &info->alias_cnt, 
-				      info->aliases);
+	status = pj_enum_ip_interface2(&enum_opt, &info->alias_cnt, 
+				       info->aliases);
+	if (status == PJ_ENOTSUP) {
+	    /* Try again without omitting deprecated IPv6 addresses */
+	    enum_opt.omit_deprecated_ipv6 = PJ_FALSE;
+	    status = pj_enum_ip_interface2(&enum_opt, &info->alias_cnt, 
+					   info->aliases);
+	}
+
 	if (status != PJ_SUCCESS) {
 	    /* If enumeration fails, just return the default address */
