Page 1 of 1

How to get local ip address on Linux?

Posted: Sat Oct 21, 2023 1:36 am
by NathanH
Hi,
The following code works differently on Linux (Ubuntu) than it does on OS3 (under WinUAE) and Windows 10 (under Wine).

Code: Select all

CreateServer(1, 49152)
DebugPrint(GetLocalIP(1, #NETWORKSERVER))
DebugPrint(ToIP(GetHostName()))
I thought GetLocalIP() would give me the ip address of the server but it prints 0.0.0.0. Am I misusing it somehow?
The second DebugPrint() gives me 192.168.0.12 on OS3 and Windows which is correct but on Linux it gives me 127.0.1.1 which is technically correct but I need to get to the 192.168.0.12 on Linux also. Is there a way to get that? Thanks.

NathanH

Re: How to get local ip address on Linux?

Posted: Sat Oct 21, 2023 10:47 am
by plouf
yes you miss :)
GetLocalIP() return server ip only when you specify a single binding address and not all (defaults to all)

you can get all IP's a computer have, which is equal to binding in every address, with GetLocalInterfaces()

about binding issue = viewtopic.php?p=15995&hilit=GetLocalIP#p15995
similar discussion for linux -> viewtopic.php?p=16004

Re: How to get local ip address on Linux?

Posted: Mon Oct 23, 2023 5:17 pm
by NathanH
Great info! Thanks.

NathanH