2

I'm porting an Linux C++ application to Android NDK and my app invokes ping to the shell to see the status of another machine for logging purposes. On my android port this fails for localhost:

# ping -c 10 localhost
ping: unknown host localhost

If I give another web address that appears to send, but no response is seen:

# ping -c 1 google.com
PING google.com (74.125.239.136) 56(84) bytes of data.

--- google.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

Is localhost expected to work on Android to refer back to the android itself (not the host machine running the emulator as discussed here)? If not, is there some other way that will work?

Is ping expected to work on the Android emulator for Mac OSX or must I do something to allow the emulator to see the network fully?

Community
  • 1
  • 1
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
  • 1
    Have you checked this? http://stackoverflow.com/questions/5806220/how-to-connect-to-my-http-localhost-web-server-from-android-emulator-in-eclips – Michell Bak Apr 17 '14 at 21:48
  • @MichellBak Thanks for the link, but that is not the same question, I really want localhost, not the machine running the emulator as that question answers. – WilliamKF Apr 18 '14 at 00:10
  • All right, wasn't sure. Your question could be a bit more specific, I think :) – Michell Bak Apr 18 '14 at 00:10
  • Can you just `ping 127.0.0.1` ? – fadden Apr 18 '14 at 00:18
  • @fadden You are right! I wonder why `localhost` fails but the `127.0.0.1` address works, shouldn't `localhost` resolve to `127.0.0.1`? Regardless, I still cannot `ping` outside, such as to `google.com`, is that normal? – WilliamKF Apr 18 '14 at 00:48

0 Answers0