Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Getting Local IP in a Java program on OS X

Getting Local IP in a Java program on OS X
Thread Tools
Junior Member
Join Date: Sep 2000
Location: Tempe, Az USA
Status: Offline
Reply With Quote
Oct 11, 2000, 01:20 PM
 
Hi-
I am trying to write a little network program and I need to get the local IP of the host. I tried to do a

InetAddress add = InetAddress.getLocalHost ();

This works on Solaris and HP-UX but on OS X it throws a UnknownHostException. Another point is that on the solaris and HP-UX boxes the network connections are through ethernet and are always on, with my OS X box the connection is through my modem using ppp. Could this be a factor? Thanks for any help you can provide.
     
Dedicated MacNNer
Join Date: Nov 2000
Location: Malaysia
Status: Offline
Reply With Quote
Jun 13, 2001, 08:05 AM
 
I'm bringing this to the top of the heap. I'm having a similar problem with the java InetAddress class. If I do:

InetAddress add = InetAddress.getLocalHost ();

I always get the lo0 device (.toString() gives "Localhost/127.0.0.1"). Is there a bug in the implementation of this on OS X?

---gralem
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Jun 13, 2001, 06:33 PM
 
1) Molz, the UnknownHostException is thrown to indicate that the IP address of a host could not be determined. This is a combination of the fact that you are connected via PPP and the problem below. Not so much that PPP is a problem, but add it to the problem below, and you have your situation.

2) gralem, I have a feeling that this problem is related to a problem I have been complaining about in these forums (and to Apple directly) for a while. For more info on what I am talking about, search these forums for a thread called something like "sick and tired of localhost".


Basically, in both cases, we are seeing that the underlying BSD system has no freaking clue as to your real hostname. So, this is not a JDK issue, but an OS X issue, that I have been complaining about for some time. This is a perfect example of why Apple needs to fix this.
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:42 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2