TIdStack.AddLocalAddressesToList() method is now deprecated

The TIdStack.AddLocalAddressesToList() method was introduced as a replacement for the TIdStack.LocalAddress and TIdStack.LocalAddresses properties, to help make retreival of local IP addresses more thread-safe. However, the implementation of AddLocalAddressesToList() in the various TIdStack descendant classes is limited to reporting IPv4 addresses only, even though most OSes provide APIs for retreiving both local IPv4 and IPv6 addresses. You provide AddLocalAddressesToList() with a TStrings object for it to fill with IP address strings, but it cannot assume how you are using the TStrings.Objects property, so there is no good way for it to report which address is IPv4 vs IPv6 in a way that is readily accessible without requiring you to parse the IP addresses manually.

A new TIdStack.GetLocalAddressList() method has been added to replace TIdStack.AddLocalAddressesToList():

procedure GetLocalAddressList(AAddresses: TIdStackLocalAddressList);

You provide a TIdStackLocalAddressList object as input, and the method fills it with TIdStackLocalAddress-derived objects as needed. Currently TIdStackLocalAddressIPv4 and TIdStackLocalAddressIPv6 classes are implemented. TIdStackLocalAddress has public IPVersion and IPAddress properties, and TIdStackLocalAddressIPv4 adds a public SubNetMask property.

This gives users a very straight-forward way to determine which local IPv4 and IPv6 addresses are available, and in the case of IPv4 also the associated subnet masks (though the SubNetMask may not be available on all platforms). For example:

  LList: TIdStackLocalAddressList;
  LAddr: TIdStackLocalAddress;
  I: Integer;
  LList := TIdStackLocalAddressList.Create;
    for I := 0 to LList.Count-1 do begin
      LAddr := LList[I];
      case LAddr.IPVersion of
        Id_IPv4: begin
          // use LAddr.IPAddress as needed...
          // use TIdStackLocalAddressIPv4(LAddr).SubNetMask as well...
        Id_IPv6: begin
          // use LAddr.IPAddress as needed...

In a future release, a BroadcastIP property may be added to TIdStackLocalAddressIPv4 for reporting subnet broadcast IPs.