Angus I'm not sure I am verse enough at the lower level code to offer an opinion as to what is "correct" or not. However, just in case someone sees this in a future thread search, here are my thoughts:
1) It seems that IcsGetInterfaceList() would fail if, for some odd reason, the computer only had IPv6 interfaces. It tries to create an AF_INET socket and raises an exception if it fails. Perhaps if should also test an IF_NET6 socket and only raise an exception of BOTH fail. I'll gladly code and submit this change if anyone knows if this is a real possibility. 2) This is my function to replace LocalIpList(). The "uses" clauses is only need because I run this from my app, not from the IPC components and its include files. I have tests to exclude local addresses based on the string. There may be a better performance if this was done on the numeric address values. {$IFDEF POSIX} uses Posix.SysSocket; {$ENDIF} ... {.DEFINE INCLOCAL} {.$DEFINE INCNET6} procedure MyLocalIpList(StrList: TStrings); {$IFNDEF POSIX} const AF_INET = 2; { internetwork: UDP, TCP, etc. } AF_INET6 = 23; { Internetwork Version 6 } {$ENDIF} var iList : TInterfaceList; I : Integer; s: string; begin if not Assigned(StrList) then exit; StrList.Clear; iList := TInterfaceList.Create; try IcsGetInterfaceList(iList); for I := 0 to IList.Count -1 do begin if IList[I]^.iiAddress.AddressIn.sin_family = AF_INET then begin s := String(WSocket_inet_ntoa(IList[I]^.iiAddress.AddressIn.sin_addr)); {$IFNDEF INCLOCAL} if s <> '127.0.0.1' then {$ENDIF} StrList.Add(s); {$IFDEF INCNET6} end else begin if IList[I]^.iiAddress.AddressIn6.sin6_family = AF_INET6 then begin s := WSocketIPv6ToStr(@IList[I]^.iiAddress.AddressIn6); {$IFNDEF INCLOCAL}if copy(s,1,4) <> 'fe80' then {$ENDIF} StrList.Add(s); end; {$ENDIF} end; end; finally iList.Free; end; end; 3) As to the original LocalIPList() function, again not being the verse enough to "officially" suggest a correction, but it seems that the code at the top where it checks for ASocketFamily is not needed as the code in the "else" section handles IPv4 just fine. If you get rid of this, it does not cause the function that fails on a Mac (GetIpList) and seems to work just fine with the caveat that it returns duplicate address values. Maybe someone with better knowledge of the underbelly of the stack would understand this. If this is expected, we simple could ignore duplicates. //WRF - this conditional test is can be removed, keeping only "else" //if ASocketFamily = sfIPv4 then begin // phe := WSocketGetHostByName(LocalHostName); // if phe <> nil then // GetIpList(Phe, IPList); //end //else begin .... //end; Bill -----Original Message----- From: TWSocket [mailto:twsocket-boun...@lists.elists.org] On Behalf Of Angus Robertson - Magenta Systems Ltd Sent: Wednesday, December 20, 2017 2:53 AM To: twsocket@lists.elists.org Subject: Re: [twsocket] LocalIPList on Mac > It seems that LocalIPList on a Mac (POSIX) returns only a single IP > address Note that it seems that gethostbyname() is also a documented > as depreciated function. > I switched and used IcsGetInterfaceList() which seems to work. I can > toss out the AF_INET6 records and the local loop back. Note the local > loop back is only return on the Mac, not windows. The low level code in wsocket is quite convoluted and hard to follow, due to support for multiple OSs and platforms. IcsGetInterfaceList does not currently appear to be used by any ICS components or samples, but I assume was well tested when originally written, and it was an oversight to not update wsocket to use it. If you let me have your modified unit, I'll update it in SVN. But please do test it carefully, to make sure it works as expected. Angus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be