Jump to content
Drewsky

Indy with Lazarus on Raspberry PI using IPV6 – problem

Recommended Posts

Hi,

 

I am using Indy 10 with Lazarus running on Raspberry PI 4 with Raspbian OS installed. When I try to bind port to IPV6 I get an error while executing application saying “Could not bind socket.”. I have read on forums and other posts online that Linux does not allow binding IPV6 and IPV4 addresses to the same port. I need only IPV6, how can I achieve successful binding to IPV6 address and port? Thank you in advance for any help.

 

Raspberry PI (updated to the latest version)

Lazarus 2.0.8 (built from SVN)

Indy 10 (downloaded and installed via Online Package Manager)

 

Code example:

procedure TFormMain.FormCreate(Sender: TObject);

var

  Binding: TIdSocketHandle;

begin

  Binding := IdHTTPServer1.Bindings.Add;

  Binding.IPVersion := Id_IPv6;

  Binding.IP := 'fe80::b493:ca5a:af2a:a036';

  Binding.Port := 8181

  IdHTTPServer1.Active := True;

end;

Share this post


Link to post

Found the problem. I should not force the IPV6 address. By commenting it, the code binds to IPV6 address only and one can test it with http://[your IPV6 address]:8181

 

Code that works example:

procedure TFormMain.FormCreate(Sender: TObject);

var

  Binding: TIdSocketHandle;

begin

  Binding := IdHTTPServer1.Bindings.Add;

  Binding.IPVersion := Id_IPv6;

  //Binding.IP := 'fe80::b493:ca5a:af2a:a036';

  Binding.Port := 8181

  IdHTTPServer1.Active := True;

end;

  • Like 1

Share this post


Link to post

By omitting the Binding.IP property, the server would bind to the wildcard IP ('::'), causing it to listen on all available IPv6 interfaces on the device. Are you sure that the IP address that you attempted to bind to ('fe80::b493:ca5a:af2a:a036') actually belongs to your device? If it does not, that would cause the bind error you were seeing.

Share this post


Link to post

Hi,

It is the same address because if I enter it into any web browser in local network I get a reply and everything works like a charm. I am using FPC 3.0.4, Lazarus 2.0.8, Indy 10 and Raspberry PI 4. I had to build FPC and Lazarus packages on Pi, since none of the default repository packages worked. I was using this guide

 

Kind regards

Share this post


Link to post
8 hours ago, Drewsky said:

It is the same address because if I enter it into any web browser in local network I get a reply and everything works like a charm.

That does not necessarily mean that is the interface's IP from the server's perspective for binding.  That is just the IP that the LAN uses to reach the device.  Do you get meaningful IPv6 addresses from Indy's GStack.GetLocalAddressList() method (not sure if it is implemented for Raspberry Pi)?  Do you see that IP in the list?

Edited by Remy Lebeau

Share this post


Link to post

Hi,

 

Yes I get the same IP address which customers use to configure connection to the Pi device. This works like that on my Pi, Kubuntu and Manjaro. On Windows it works without any problems.

 

Kind regards

Edited by Drewsky

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×