lnet localport incorrect

Original Reporter info from Mantis: greenfil
  • Reporter name: greenfil

Description:

When using "connect" local port I can't determine the local port

Steps to reproduce:

program Project1;

uses lNet, Sockets;

function GetLocalPort(Socket:TLSocket): Word;
var
  a: TSockAddr;
  l: Integer;
begin
  Result := 0;
  l := SizeOf(a);
  if fpGetSockName(Socket.Handle, @a, @l) = 0 then
    Result := NToHs(a.sin_port);
end;

var UDP:TLUdp;

const Port=7080; {any}

begin
  UDP:=TLUdp.Create(nil);
  UDP.Connect('127.0.0.1', Port);
  UDP.SendMessage('Test'); //My detect local port doesn't work without Send
  WriteLn(UDP.Iterator.LocalPort); //write Port - it is incorrect
  WriteLn(GetLocalPort(UDP.Iterator)); //Write correct local port
  UDP.Free;
end.

Mantis conversion info:

  • Mantis ID: 36849
  • OS: debian
  • OS Build: 9
  • Platform: x64