[SOLVED] gethostbyname(gethostname, host) returns random host.addr on MacOs lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Key-Real · 2023-11-10 11:30 I'm trying to get my local IP Address under MacOS. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses netdb;var     host : THostEntry;begin     gethostbyname(gethostname, host);     writeln(HostAddrToStr(host.addr));end.  this writes a random ip address what to do? ---------------------------------------------------------------------- loaded · 2023-11-10 12:11 The reason is written here. https://wiki.freepascal.org/Netdb If you want to know the LAN or WAN addresses of your computer. You need to use a different method. I remember an example I wrote on the subject a long time ago. If I can find it I will send it. ---------------------------------------------------------------------- Key-Real · 2023-11-10 12:44 yes, cnetdb (I use it under linux) .... but it is not there for Mac ---------------------------------------------------------------------- loaded · 2023-11-10 13:00 Quote from: Key-Real on November 10, 2023, 01:44:43 pmyes, cnetdb (I use it under linux) .... but it is not there for Mac Yes you are right. I was wrong here.  In my solution it was valid for windows. In this case, I think the advice of someone experienced with MacOs will be useful. ---------------------------------------------------------------------- Remy Lebeau · 2023-11-10 18:14 Quote from: Key-Real on November 10, 2023, 12:30:26 pmI'm trying to get my local IP Address under MacOS. ... this writes a random ip address Well, for one thing, you are not checking the return value of gethostbyname() for failure before using the data.  For another thing, this is not the best way to get local IPs anyway (even on Windows).  Use getifaddrs() instead (or GetAdapterAddresses() on Windows). ---------------------------------------------------------------------- Key-Real · 2023-11-21 10:08 In which unit is getifaddrs() ? ---------------------------------------------------------------------- Key-Real · 2023-11-21 16:08 I wrote custom bindings for getifaddrs(ifap). It works because I get the ifap^.ifa_name right! how to get the ip address string out of ifap^.ifa_addr^ ??? ---------------------------------------------------------------------- Remy Lebeau · 2023-11-21 20:17 Quote from: Key-Real on November 21, 2023, 05:08:54 pmhow to get the ip address string out of ifap^.ifa_addr^ ??? You can use getnameinfo() or inet_ntop(). ---------------------------------------------------------------------- Key-Real · 2023-11-21 20:30 in which unit is getnameinfo. for inet_ntop the unit network.pp is not availible on mac ---------------------------------------------------------------------- Key-Real · 2023-11-22 17:20 I found a solution: https://forum.lazarus.freepascal.org/index.php?topic=65309.msg497550#m sg497550