Re: My IP Address
Re: My IP Address
- Subject: Re: My IP Address
- From: Paul Forgey <email@hidden>
- Date: Tue, 30 Nov 2004 13:34:54 -0800
On Nov 30, 2004, at 12:58 PM, Mark Gilbert wrote:
Also, I am creating (in C) an HTML web page with a 'refresh' line, to
make the page automatically reload every 2 seconds (to generate a live
update of status). In order to do that I have to code my own IP
address into the HTML which I return to the client.
In this case I would use getsockname() as another person responding
suggested. Since you already have a connection with the web client,
you now know which interface is being used with it. If you do this per
connection, then you will work rather reliably in most cases. Even if
there are multiple interfaces or your assigned address changes.
So, first of all, I would like to have a status window in my app's GUI
which tells a local user which address they need to enter remotely to
control the app (without having to look elsewhere in the computer to
find it).
As has been stated before there is no 100% reliable or sensible way to
do that. You may well have multiple interfaces to separate networks
which don't route. If you are trying to emulate what the sharing panel
does, it uses the fqdn if the system has one, otherwise I believe
(maybe wrongly) it uses the IP address of the interface with highest
"priority" as specified in the network panel.
You could do a best guess by using gethostname() and then resolving the
result with gethostbyname(), but that assumes a network where host
names have been assigned and are resolvable in DNS. This really is one
of the main reasons DNS exists in the first place :).
You could also advertise your service in Rendezvous and let clients
find you.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden