Ignore all loopback addresses for ip detection

Summary:
There is a bug with IP detection on Macs that have (1) multiple ethernet interfaces, (2) are using the second or third interface as their primary connection and (3) have extra loopback IPs configured (for example when running OpenVPN, running some Docker configurations or other more exotic applications). In those cases, automatic IP detection will falsely detect the IP as something like `127.94.0.1`, which will make it impossible to run debug builds from a physical device.

The underlying network configurations looks something similar to this (irrelevant parts omitted):
```
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
	options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
	inet 127.0.0.1 netmask 0xff000000
	inet 127.94.0.1 netmask 0xff000000
	nd6 options=201<PERFORMNUD,DAD>
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
	ether xx:xx:xx:xx:xx:xx
	nd6 options=201<PERFORMNUD,DAD>
	media: autoselect
Closes https://github.com/facebook/react-native/pull/13415

Differential Revision: D4859654

Pulled By: javache

fbshipit-source-id: 3c5d06201c48a2dfe1c274ff433423e5d7f2cded
This commit is contained in:
Hilke Heremans 2017-04-10 10:47:29 -07:00 committed by Facebook Github Bot
parent 079dcaed99
commit a42fd8c16b
1 changed files with 1 additions and 1 deletions

View File

@ -78,7 +78,7 @@ if [[ "$CONFIGURATION" = "Debug" && ! "$PLATFORM_NAME" == *simulator ]]; then
PLIST=$TARGET_BUILD_DIR/$INFOPLIST_PATH
IP=$(ipconfig getifaddr en0)
if [ -z "$IP" ]; then
IP=$(ifconfig | grep 'inet ' | grep -v 127.0.0.1 | cut -d\ -f2 | awk 'NR==1{print $1}')
IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | cut -d\ -f2 | awk 'NR==1{print $1}')
fi
if [ -z ${DISABLE_XIP+x} ]; then