Thanks for your answer!

Before I write about what I came up with, here some background about my 
project: The goal is that the user can attach a node (an embedded 
computer which provides some service) to the network, and it should show 
up in some GUI application without the need to configure anything. So 
manually setting the IP address which should be published on every node 
separately is not an option.

So here's my idea (the best so far...):
I use boost.asio to get all local IP addresses, using the approach 
described here:
http://hi.baidu.com/xshl5/blog/item/bebd0ee9df347f3ab80e2d8c.html

This is still ugly because it needs to be able to resolve the hostname, 
but at least it should be portable.

Now on my developer machine (with two network cards), I can find three 
IPv6 and two IPv4 addresses. So, as you wrote, the problem is to decide 
which address to use.

I decided to register my service several times, with all available IP 
addresses. As URL-path I use an id which uniquely identifies a node. So 
the GUI will find several services with the same id and it can use ping 
to choose (the) one it can actually reach.

This is not nice, but it's a beginning...

But maybe I should really consider working with hostnames instead of IP 
addresses anyway. Then I would need to register the service only once 
(with one hostname instead of several IPs). I'll have to think about the 
consequences of this desicion for the rest of my project...

With the above mentioned solution for finding my local IP addresses I 
need to make sure that every node has its own unique and valid hostname 
anyway. Maybe my nodes can give themselves an arbitrary, but globally 
unique ID (GUID) as a hostname when they boot for the first time? Then 
there is no need for the user to configure anything.

Robert


Am 04.08.2011 14:05, schrieb Philipp Schafft:

> reflum,
>
> On Thu, 2011-08-04 at 09:29 +0200, Robert Hegner wrote:
>> Using SLPReg I'd like to register
>>
>> service:TrackingNode.CP://192.168.0.100:1234
>>
>> where the IP address should actually be the the local IP address of my
>> NIC. This sounds to me like a common problem when using SLP, but I
>> haven't found a solution yet.
>>
>> The problem is that I haven't found a nice and portable way to discover
>> the local IP address (using gethostname and gethostbyname is ugly and
>> Windows specific, for example).
>>
>> What is the common practice to register a service using the current IP
>> address?
>
> This is a non-easy problem and I don't have a good solution for you.
>
> Yet there are some points you should consider:
> A lot systems (even my laptop) has multiple externel addresses plus
> loopback address. In addition there is no 'eth0' so requesting the
> address of hardcoded 'eth0' will fail on some systems (eth0 broke and I
> replaced the card. As it is a new card it got a new name.)
>
> looking up hostname (both gethostname() and uname()) works for me but
> often people have use strange hostnames ('localhost'...) or hostnames
> can not be resolved.
>
> There can also be some kind of address translation in between (NAT,...)
> which requires you to publish a IP address not your real one.
>
> I think a good application should allow the user to give the address in
> some kind of configuration file, dialog,...
>
> I also think that plublishing hostnames (not IP addresses) solves some
> (most) of the abo´ve problems. This should be prefered.
>
>
> If you find a good solution please tell me. ;)
>
>
>
>
>
> ------------------------------------------------------------------------------
> BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
> The must-attend event for mobile developers. Connect with experts.
> Get tools for creating Super Apps. See the latest technologies.
> Sessions, hands-on labs, demos&  much more. Register early&  save!
> http://p.sf.net/sfu/rim-blackberry-1
>
>
>
> _______________________________________________
> Openslp-users mailing list
> Openslp-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openslp-users



------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts. 
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
Openslp-users mailing list
Openslp-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openslp-users

Reply via email to