Skip to content

Commit

Permalink
Check en0..en8 when generating ip.txt for iOS debug builds (#28764)
Browse files Browse the repository at this point in the history
Summary:
When generating ip.txt in an iOS debug build, search en0 through en8 for an IP address rather than only checking en0 and en1.  For example, on my Mac, the IP address I needed to use was on en5 and the IP address actually detected was a private network of one of my Parallels virtual machines (interface vnic0).

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[iOS] [Fixed] - Search en0 through en8 for the Metro Bundler's IP address when generating iOS debug builds
Pull Request resolved: #28764

Test Plan: Should make no difference to users for whom react-native-xcode.sh already worked. On a Mac with multiple virtual machines installed, should prevent ip.txt getting the private IP address of a virtual machine.

Differential Revision: D21280671

Pulled By: shergin

fbshipit-source-id: e6fe9c8344146626df96129968981462463201f7
  • Loading branch information
malord authored and facebook-github-bot committed Apr 28, 2020
1 parent 423b55b commit b2b23a2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scripts/react-native-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH

# Enables iOS devices to get the IP address of the machine running Metro
if [[ "$CONFIGURATION" = *Debug* && ! "$PLATFORM_NAME" == *simulator ]]; then
IP=$(ipconfig getifaddr en0)
if [[ -z "$IP" || -n "`ifconfig $value | grep 'baseT'`" ]]; then
IP=$(ipconfig getifaddr en1)
fi
for num in 0 1 2 3 4 5 6 7 8; do
IP=$(ipconfig getifaddr en${num})
if [ ! -z "$IP" ]; then
break
fi
done
if [ -z "$IP" ]; then
IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | grep -v ' 169.254.' |cut -d\ -f2 | awk 'NR==1{print $1}')
fi
Expand Down

0 comments on commit b2b23a2

Please sign in to comment.