Hi João
On Fri, 2021-01-22 at 19:41 +0100, João Pais wrote:
I wanted to check if there are any new methods to get one's own ip from Pd - that is, so that a user doesn't go check the system settings.
I need that, too, and I can't wrap my head around figuring out how to do it. Using a [shell]-like solution would require different scripts for each platform. Also, "knowing" the IP address is not that trivial: A computer might have many physical network interfaces (ethernet and wlan) and a localhost interface and even has more when hosting virtual machines and VPN is configured, etc. I count 10 addresses on my laptop. So, which is the one you're interested in?
Usually, it's the other party (that you're connecting to) that knows. For a specific connection, the other party knows the address that is interesting in the context of that particular connection. In Pd vanilla, [netreceive] reports the source address for received data only for TCP connections, but not for UDP. iemnet's [udpreceive] will tell you the sender, though.
There is no deterministic way to define your own address. Depending on the destination, packets might be routed differently and thus the source address will be different. If you know the destination address, you could parse the routing table and deduce the (your) source address from it.
It would be necessary for all windows, macos and linux. Older messages talk about using [shell] in unix systems, and some hack with a batch file in windows. If this is still the current method, how would one activate a batch file in windows from inside pd?
As my knowledge of network isn't that good, just to check: to send a broadcast message for all peers in the same network, is the correct IP e.g. xxx.xxx.xxx.255?
Depends on the kind of subnet. If your netmask is 255.255.255.0, then yes. But networks can be of any size and depending on the size, the broadcast address of that network might be a different one. The IP- Address in a local network is divided in a network-prefix and host part. You see often addresses specified in CIDR notation, for example: 192.168.50.244/24. The '24' means that the first 24 bits of the address are the network prefix, and the remaining 8 bits is the host part. For getting the broadcast address of a given subnet, you set all bits of the host part to 1, which results in x.x.x.255 for a /24 network.
I read somewhere that 255.255.255.255 was also for broadcast, but since it's not working I imagine I read wrong.
It's the broadcast address of the 0.0.0.0/0 subnet, a.k.a the whole IPv4 internet. However, routers do not pass broadcast message from local network to the internet. But at my home, I can send messages to all my devices using this address.
Note: it works only with shoot-and-forget protocols like UDP, but not with connection-aware protocols like TCP.
Also, I'm not sure if all routers pass on such messages.
Resuming: to send a broadcast message in the network, it's necessary to know the first 3 parts of one's IP?
In my experience not. Just use 255.255.255.255
Roman