Most examples uses e.g. internet connection e.g. google dns. This is vary bad way since this will not work without internet in local network.
Also some examples uses bad way like analysing "eth0". This is very bad way to have like this hardcoded strings. E.g. in my PC this is not work since my addapter name is "ens160" instead "eth0":
ens160 Link encap:Ethernet HWaddr 00:50:56:ba:75:ea
inet addr:192.168.0.237 Bcast:192.168.1.255 Mask:255.255.254.0
inet6 addr: ... Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:205280 errors:0 dropped:1 overruns:0 frame:0
TX packets:68958 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:266539618 (266.5 MB) TX bytes:4771936 (4.7 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:825 errors:0 dropped:0 overruns:0 frame:0
TX packets:825 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:74843 (74.8 KB) TX bytes:74843 (74.8 KB)
My address in localnetwork is "192.168.0.237", this is ens160. This is default interface and IP which uses in system when some library creates sockets (e.g. microhttpd or any other). How to retrieve it using standard linux libraries/functions?
Thank you in advance