I have a piece of code which scans 256 IPv4 addresses within user's network, checks each one for a particular TCP port and checks if it is a server which it can connect to. The concept is fairly simple...
type
TIPAddressV4 = record
IP1: Byte;
IP2: Byte;
IP3: Byte;
IP4: Byte;
function AsString: String;
end;
TServerResult = class(TObject)
//Some proprietary properties...
end;
TServerSearchCallback = Reference to procedure(AItem: TServerResult);
TProgressCallback = Reference to procedure(ACurrent, AMax: Integer);
procedure ServerSearch(ACallback: TServerSearchCallback; AProgressCallback: TProgressCallback);
begin
TThread.CreateAnonymousThread(
procedure
var
Cli: TIdHTTP;
Url, Res, T: String;
IP: TIPAddressV4;
X: Integer;
O: ISuperObject;
S: TServerResult;
begin
IP:= GetThisDeviceIPv4Address;
Cli:= TIdHTTP.Create(nil);
try
Cli.ConnectTimeout:= 50;
//Iterate every possible IPv4 address in same range...
for X := 0 to 255 do begin
//Concatenate IP address and URL...
T:= IntToStr(IP.IP1)+'.'+IntToStr(IP.IP2)+'.'+IntToStr(IP.IP3)+'.'+IntToStr(X);
Url:= 'http://'+T+':12345/ServerInfo';
try
//Test HTTP GET request and check if JSON...
Res:= Cli.Get(Url);
O:= SO(Res);
if O <> nil then begin
//Check if JSON is really expected format...
if O.S['Name'] = 'My Unique Name' then begin
//Trigger callback...
S:= TServerResult.Create;
try
//Populate with proprietary properties...
S.Host:= O.S['host'];
//...
finally
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
if Assigned(ACallback) then
ACallback(S);
end);
//Object is NOT free'd here, receiver takes ownership.
end;
end;
end;
except
on E: Exception do begin
//We don't care about handling exceptions here...
end;
end;
//Used for progress bar...
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
if Assigned(AProgressCallback) then
AProgressCallback(X, 255);
end);
end;
finally
Cli.Free;
end;
end).Start;
end;
For example, if this device's IP is 192.168.0.5, it will scan IP addresses from 192.168.0.0 to 192.168.0.255 to find particular servers it can connect to.
The problem arises with the fact that Apple requires IPv6 support. This code is of course only supporting IPv4 at the moment. IPv6 works entirely differently, and not to mention, a single server might be found on both IPv4 and IPv6.
What do I need to do to make this also work for IPv6, thus fulfilling Apple's IPv6 support requirement?
EDIT
I'm actually thinking that this may not be absolutely required in particular for Apple's requirement. General communication with the API, of course. But for this particular feature of the app, I question whether it falls into the category of this requirement.