Sync with usrsctp code.


git-svn-id: http://sctp-refimpl.googlecode.com/svn/trunk@8448 9df1edf5-d72c-5b5f-11c0-5f5209eb73f7
diff --git a/KERN/netinet/sctp_bsd_addr.c b/KERN/netinet/sctp_bsd_addr.c
index 52f8a16..0210902 100755
--- a/KERN/netinet/sctp_bsd_addr.c
+++ b/KERN/netinet/sctp_bsd_addr.c
@@ -366,23 +366,28 @@
 	/* Enumerate through each returned adapter and save its information */
 	for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) {
 		if (pAdapt->IfType == IF_TYPE_IEEE80211 || pAdapt->IfType == IF_TYPE_ETHERNET_CSMACD) {
-			ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
-			ifa->ifa_name = strdup(pAdapt->AdapterName);
-			ifa->ifa_flags = pAdapt->Flags;
-			ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
-			memcpy(ifa->ifa_addr, pAdapt->FirstUnicastAddress->Address.lpSockaddr, sizeof(struct sockaddr_in));
+			for (pUnicast = pAdapt->FirstUnicastAddress; pUnicast; pUnicast = pUnicast->Next) {
+				if (IN4_ISLINKLOCAL_ADDRESS(&(((struct sockaddr_in *)(pUnicast->Address.lpSockaddr))->sin_addr))) {
+					continue;
+				}
+				ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
+				ifa->ifa_name = strdup(pAdapt->AdapterName);
+				ifa->ifa_flags = pAdapt->Flags;
+				ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
+				memcpy(ifa->ifa_addr, pUnicast->Address.lpSockaddr, sizeof(struct sockaddr_in));
 
-			sctp_ifa = sctp_add_addr_to_vrf(0,
-			                                ifa,
-			                                pAdapt->IfIndex,
-			                                (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType,
-			                                ifa->ifa_name,
-			                                (void *)ifa,
-			                                ifa->ifa_addr,
-			                                ifa->ifa_flags,
-			                                0);
-			if (sctp_ifa) {
-				sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
+				sctp_ifa = sctp_add_addr_to_vrf(0,
+				                                ifa,
+				                                pAdapt->IfIndex,
+				                                (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType,
+				                                ifa->ifa_name,
+				                                (void *)ifa,
+				                                ifa->ifa_addr,
+				                                ifa->ifa_flags,
+				                                0);
+				if (sctp_ifa) {
+					sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
+				}
 			}
 		}
 	}
diff --git a/KERN/nke/sctp_nke/Leopard/netinet/sctp_bsd_addr.c b/KERN/nke/sctp_nke/Leopard/netinet/sctp_bsd_addr.c
index 52f8a16..0210902 100755
--- a/KERN/nke/sctp_nke/Leopard/netinet/sctp_bsd_addr.c
+++ b/KERN/nke/sctp_nke/Leopard/netinet/sctp_bsd_addr.c
@@ -366,23 +366,28 @@
 	/* Enumerate through each returned adapter and save its information */
 	for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) {
 		if (pAdapt->IfType == IF_TYPE_IEEE80211 || pAdapt->IfType == IF_TYPE_ETHERNET_CSMACD) {
-			ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
-			ifa->ifa_name = strdup(pAdapt->AdapterName);
-			ifa->ifa_flags = pAdapt->Flags;
-			ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
-			memcpy(ifa->ifa_addr, pAdapt->FirstUnicastAddress->Address.lpSockaddr, sizeof(struct sockaddr_in));
+			for (pUnicast = pAdapt->FirstUnicastAddress; pUnicast; pUnicast = pUnicast->Next) {
+				if (IN4_ISLINKLOCAL_ADDRESS(&(((struct sockaddr_in *)(pUnicast->Address.lpSockaddr))->sin_addr))) {
+					continue;
+				}
+				ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
+				ifa->ifa_name = strdup(pAdapt->AdapterName);
+				ifa->ifa_flags = pAdapt->Flags;
+				ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
+				memcpy(ifa->ifa_addr, pUnicast->Address.lpSockaddr, sizeof(struct sockaddr_in));
 
-			sctp_ifa = sctp_add_addr_to_vrf(0,
-			                                ifa,
-			                                pAdapt->IfIndex,
-			                                (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType,
-			                                ifa->ifa_name,
-			                                (void *)ifa,
-			                                ifa->ifa_addr,
-			                                ifa->ifa_flags,
-			                                0);
-			if (sctp_ifa) {
-				sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
+				sctp_ifa = sctp_add_addr_to_vrf(0,
+				                                ifa,
+				                                pAdapt->IfIndex,
+				                                (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType,
+				                                ifa->ifa_name,
+				                                (void *)ifa,
+				                                ifa->ifa_addr,
+				                                ifa->ifa_flags,
+				                                0);
+				if (sctp_ifa) {
+					sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
+				}
 			}
 		}
 	}
diff --git a/KERN/nke/sctp_nke/Lion/netinet/sctp_bsd_addr.c b/KERN/nke/sctp_nke/Lion/netinet/sctp_bsd_addr.c
index 52f8a16..0210902 100755
--- a/KERN/nke/sctp_nke/Lion/netinet/sctp_bsd_addr.c
+++ b/KERN/nke/sctp_nke/Lion/netinet/sctp_bsd_addr.c
@@ -366,23 +366,28 @@
 	/* Enumerate through each returned adapter and save its information */
 	for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) {
 		if (pAdapt->IfType == IF_TYPE_IEEE80211 || pAdapt->IfType == IF_TYPE_ETHERNET_CSMACD) {
-			ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
-			ifa->ifa_name = strdup(pAdapt->AdapterName);
-			ifa->ifa_flags = pAdapt->Flags;
-			ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
-			memcpy(ifa->ifa_addr, pAdapt->FirstUnicastAddress->Address.lpSockaddr, sizeof(struct sockaddr_in));
+			for (pUnicast = pAdapt->FirstUnicastAddress; pUnicast; pUnicast = pUnicast->Next) {
+				if (IN4_ISLINKLOCAL_ADDRESS(&(((struct sockaddr_in *)(pUnicast->Address.lpSockaddr))->sin_addr))) {
+					continue;
+				}
+				ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
+				ifa->ifa_name = strdup(pAdapt->AdapterName);
+				ifa->ifa_flags = pAdapt->Flags;
+				ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
+				memcpy(ifa->ifa_addr, pUnicast->Address.lpSockaddr, sizeof(struct sockaddr_in));
 
-			sctp_ifa = sctp_add_addr_to_vrf(0,
-			                                ifa,
-			                                pAdapt->IfIndex,
-			                                (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType,
-			                                ifa->ifa_name,
-			                                (void *)ifa,
-			                                ifa->ifa_addr,
-			                                ifa->ifa_flags,
-			                                0);
-			if (sctp_ifa) {
-				sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
+				sctp_ifa = sctp_add_addr_to_vrf(0,
+				                                ifa,
+				                                pAdapt->IfIndex,
+				                                (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType,
+				                                ifa->ifa_name,
+				                                (void *)ifa,
+				                                ifa->ifa_addr,
+				                                ifa->ifa_flags,
+				                                0);
+				if (sctp_ifa) {
+					sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
+				}
 			}
 		}
 	}
diff --git a/KERN/nke/sctp_nke/MountainLion/netinet/sctp_bsd_addr.c b/KERN/nke/sctp_nke/MountainLion/netinet/sctp_bsd_addr.c
index 52f8a16..0210902 100755
--- a/KERN/nke/sctp_nke/MountainLion/netinet/sctp_bsd_addr.c
+++ b/KERN/nke/sctp_nke/MountainLion/netinet/sctp_bsd_addr.c
@@ -366,23 +366,28 @@
 	/* Enumerate through each returned adapter and save its information */
 	for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) {
 		if (pAdapt->IfType == IF_TYPE_IEEE80211 || pAdapt->IfType == IF_TYPE_ETHERNET_CSMACD) {
-			ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
-			ifa->ifa_name = strdup(pAdapt->AdapterName);
-			ifa->ifa_flags = pAdapt->Flags;
-			ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
-			memcpy(ifa->ifa_addr, pAdapt->FirstUnicastAddress->Address.lpSockaddr, sizeof(struct sockaddr_in));
+			for (pUnicast = pAdapt->FirstUnicastAddress; pUnicast; pUnicast = pUnicast->Next) {
+				if (IN4_ISLINKLOCAL_ADDRESS(&(((struct sockaddr_in *)(pUnicast->Address.lpSockaddr))->sin_addr))) {
+					continue;
+				}
+				ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
+				ifa->ifa_name = strdup(pAdapt->AdapterName);
+				ifa->ifa_flags = pAdapt->Flags;
+				ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
+				memcpy(ifa->ifa_addr, pUnicast->Address.lpSockaddr, sizeof(struct sockaddr_in));
 
-			sctp_ifa = sctp_add_addr_to_vrf(0,
-			                                ifa,
-			                                pAdapt->IfIndex,
-			                                (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType,
-			                                ifa->ifa_name,
-			                                (void *)ifa,
-			                                ifa->ifa_addr,
-			                                ifa->ifa_flags,
-			                                0);
-			if (sctp_ifa) {
-				sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
+				sctp_ifa = sctp_add_addr_to_vrf(0,
+				                                ifa,
+				                                pAdapt->IfIndex,
+				                                (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType,
+				                                ifa->ifa_name,
+				                                (void *)ifa,
+				                                ifa->ifa_addr,
+				                                ifa->ifa_flags,
+				                                0);
+				if (sctp_ifa) {
+					sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
+				}
 			}
 		}
 	}
diff --git a/KERN/nke/sctp_nke/SnowLeopard/netinet/sctp_bsd_addr.c b/KERN/nke/sctp_nke/SnowLeopard/netinet/sctp_bsd_addr.c
index 52f8a16..0210902 100755
--- a/KERN/nke/sctp_nke/SnowLeopard/netinet/sctp_bsd_addr.c
+++ b/KERN/nke/sctp_nke/SnowLeopard/netinet/sctp_bsd_addr.c
@@ -366,23 +366,28 @@
 	/* Enumerate through each returned adapter and save its information */
 	for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) {
 		if (pAdapt->IfType == IF_TYPE_IEEE80211 || pAdapt->IfType == IF_TYPE_ETHERNET_CSMACD) {
-			ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
-			ifa->ifa_name = strdup(pAdapt->AdapterName);
-			ifa->ifa_flags = pAdapt->Flags;
-			ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
-			memcpy(ifa->ifa_addr, pAdapt->FirstUnicastAddress->Address.lpSockaddr, sizeof(struct sockaddr_in));
+			for (pUnicast = pAdapt->FirstUnicastAddress; pUnicast; pUnicast = pUnicast->Next) {
+				if (IN4_ISLINKLOCAL_ADDRESS(&(((struct sockaddr_in *)(pUnicast->Address.lpSockaddr))->sin_addr))) {
+					continue;
+				}
+				ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
+				ifa->ifa_name = strdup(pAdapt->AdapterName);
+				ifa->ifa_flags = pAdapt->Flags;
+				ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
+				memcpy(ifa->ifa_addr, pUnicast->Address.lpSockaddr, sizeof(struct sockaddr_in));
 
-			sctp_ifa = sctp_add_addr_to_vrf(0,
-			                                ifa,
-			                                pAdapt->IfIndex,
-			                                (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType,
-			                                ifa->ifa_name,
-			                                (void *)ifa,
-			                                ifa->ifa_addr,
-			                                ifa->ifa_flags,
-			                                0);
-			if (sctp_ifa) {
-				sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
+				sctp_ifa = sctp_add_addr_to_vrf(0,
+				                                ifa,
+				                                pAdapt->IfIndex,
+				                                (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType,
+				                                ifa->ifa_name,
+				                                (void *)ifa,
+				                                ifa->ifa_addr,
+				                                ifa->ifa_flags,
+				                                0);
+				if (sctp_ifa) {
+					sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
+				}
 			}
 		}
 	}