How to get local ip address on Linux?

Find quick help here to get you started with Hollywood
Post Reply
NathanH
Posts: 107
Joined: Sun Jul 05, 2015 1:29 am
Location: Caldwell, Idaho

How to get local ip address on Linux?

Post 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
plouf
Posts: 473
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: How to get local ip address on Linux?

Post 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
Christos
NathanH
Posts: 107
Joined: Sun Jul 05, 2015 1:29 am
Location: Caldwell, Idaho

Re: How to get local ip address on Linux?

Post by NathanH »

Great info! Thanks.

NathanH
Post Reply