[PD] IP address of local machine

Jack jack at rybn.org
Sun Dec 17 11:34:49 CET 2017


Le 17/12/2017 à 01:41, Roman Haefeli a écrit :
> 
> On Sam, 2017-12-16 at 21:26 +0100, Jack wrote:
>> Your router has a public and local IP. So, i guess your local machine
>> has only a local IP. Then, your local machine need to pass through
>> your
>> router to access remote server. Your router has NAT rules to know
>> which
>> local machine to route the content from the remote server.
>> I don't really understand what exactly you are looking for
> 
> Sorry for not being more clear. I try to rephrase. I like to know what
> local IP address a [tcpclient] or [udpclient] connection is using. So,
> if my wifi interface is configured to 192.168.1.50 and this interface
> is used for communicating to the outside world, how can I get that IP
> from within Pd? Your suggestions may work by using [shell], but still
> they show all kinds of interfaces and IP addresses and its not trivial
> to determine the one that is used to talk to the default gateway (or by
> specific connection).

It is.
If you run :
$ route -n

you can see which interface is connected to the gateway (router).
From Pd, i can't see a solution.


> 
> I would like to implement a technique called UDP hole punching[1] in
> Pd. Before two clients talk to each other directly, they exchange some
> information by talking to a server with a public IP address that acts
> as a man-in-the-middle. As a result, the clients know the public IP
> address and the bind port of their peer. This works well so far, even
> in my patch. However, if both clients are in the same local network,
> they can't establish a connection because they try to connect to the
> public IP address of their own router. So, in order to overcome this
> limitation, my idea was to check if my router's public IP address is
> the same as the one of my peer. If they are, it means both clients are
> part of the same local network.

Or not.
Your router can be connected to 3 or more different networks :
1 public for internet
2 local

But it is not a problem to send a packet from a local network to the
other local network, the router should do the job (depending of its
configuration).

In that case, they would use the public
> server to exchange each other's local IP addresses. However,
> [tcpclient] seems to have no notion of the local IP address of an
> established connection. So the patch actually doesn't know what IP
> address it is using and thus cannot tell its peer.

Yes, [tcpclient] only need the IP and the listening port of the server.
And i can't see an object from Pd library doing this job.

> 
> Using [shell] and a script based on 'ip addr show' seems tedious and
> not very reliable, considering the information needed is part of every
> packet sent and received by [tcpclient]. 
> 
> If there's no easy way, I might turn that into a feature request for
> iemnet's [udpclient] and [tcpclient] to print the src IP address and
> src port on the status outlet. Does that make sense?

Maybe an other object (but not [tcpclient] ?) could return the local IP.
Sending this local IP to the public server could help to create a direct
connection between clients on local networks...
I am also interested to know if there is a better solution.
++

Jack


> 
> 
> Roman
> 
> 
> [1] https://en.wikipedia.org/wiki/UDP_hole_punching
> 
> 
>> , but here
>> some possible answer (on linux) :
>>
>> to get your ip address (local)
>> $ ip addr
>> to get the IP address (local) of the router :
>> $ ip route
>> to get the public address of the router :
>> $ curl -s http://whatismyip.akamai.com/
>> or
>> $ netcat -w 5 4.ifcfg.me 23
>> or
>> $ nc -w 5 4.ifcfg.me 23
>>
>> There is also other command lines (ifconfig (instead of ip addr),
>> route
>> -n (instead ip route), etc.).
>> ++
>>
>> Jack
>>
>>
>>
>> Le 16/12/2017 à 17:35, Roman Haefeli a écrit :
>>>
>>> Hey all
>>>
>>> Is there a simple cross-platform way for a patch to know the main
>>> IP
>>> address of the local machine? Assume the patch is connected to a
>>> remote
>>> server and is able to request its public IP address. What I like to
>>> find out is if the local patch is communicating through NAT or
>>> directly
>>> to the remote server. 
>>>
>>> An incoming IP packet from the remote server would contain that
>>> information in the destination IP address field of the IP header,
>>> but
>>> the network objects I'm using ([tcpclient] and [udpclient]) don't
>>> expose that information. 
>>>
>>> Maybe there are other ways?
>>>
>>> Roman
>>>
>>>
>>>
>>> _______________________________________________
>>> Pd-list at lists.iem.at mailing list
>>> UNSUBSCRIBE and account-management -> https://lists.puredata.info/l
>>> istinfo/pd-list
>>>
>>
>> _______________________________________________
>> Pd-list at lists.iem.at mailing list
>> UNSUBSCRIBE and account-management -> https://lists.puredata.info/lis
>> tinfo/pd-list
>>
>>
>> _______________________________________________
>> Pd-list at lists.iem.at mailing list
>> UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20171217/ad356455/attachment.sig>


More information about the Pd-list mailing list