GetAddrAsInt() returns negative int?

Hey everyone,

When connected to localhost, GetAddrAsInt works well:

31358-localhost.jpg

but when connected to a internet IP, it returns a negative integer:

31359-internet.jpg

Below is the code i used to get both screen captures (in the player controller’s BeginPlayingState()).

if (!IsLocalPlayerController() || Role == ROLE_Authority) return false;

int32 IntIP = ()->NetDriver->ServerConnection->GetAddrAsInt();
FString IntIPStr = FString::FromInt(IntIP);

int32 ServerIPa = IntIP / (256 * 256 * 256);
int32 ServerIPb = (IntIP - ServerIPa * 256 * 256 * 256) / (256 * 256);
int32 ServerIPc = (IntIP - ServerIPa * 256 * 256 * 256 - ServerIPb * 256 * 256) / 256;
int32 ServerIPd = (IntIP - ServerIPa * 256 * 256 * 256 - ServerIPb * 256 * 256 - ServerIPc * 256);

FString ServerIP = FString::FromInt(ServerIPa) + "." + FString::FromInt(ServerIPb) + "." + FString::FromInt(ServerIPc) + "." + FString::FromInt(ServerIPd);

GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Yellow, TEXT("IP int: " + IntIPStr + " = " + ServerIP));

Cedric

You could just use FIPv4Address type which give you some extra fancy functions

But for problem it self problem might be use of int32 which is signed type and IP address is using 4 unsigned bytes so using uint32 insted might fix that up

Hi ,

Very nice guess, i would not have thought about that, the doc says it returns int32:

https://docs.unrealengine.com/latest/INT/API/Runtime/OnlineSubsystemUtils/UIpConnection/GetAddrAsInt/index.html

Anyway, it works well with uint32, thank you very much for your answer, and for the link.

Cheers

Cedric