https://www.freepascal.org/docs-html/current/rtl/sockets/fpbind.html
Is there an example for IPV6?
function fpbind(
s: cint;
addrx: psockaddr;
addrlen: TSockLen
):cint;I guess psockaddr is different in IPV6 version.

Mailing lists / fpc-pascal / 2019-10
8 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
https://www.freepascal.org/docs-html/current/rtl/sockets/fpbind.html
Is there an example for IPV6?
function fpbind(
s: cint;
addrx: psockaddr;
addrlen: TSockLen
):cint;I guess psockaddr is different in IPV6 version.
No, it does not have to be..
The addrlen will differ of course. That's why it is there to begin with. Maybe an overload could be added, I would need to look into this to see if it is required.
Michael.
I sent this direct to him on accident but I don't think it worked anyways (bounced?)
Just some test code so not very pretty. It works, but IN6ADDR_ANY was missing and I'm not familiar enough with ipv6 to know how it might be defined in other languages.
uses sockets;
const
IN6ADDR_ANY: array[0..3] of longint = (0, 0, 0, 0);
test: string = 'derp derp derp'#13#10;
var
servsoc: longint;
clientsoc: longint;
serv, client: TInetSockAddr6;
i, res: longint;
begin
servsoc:=fpsocket(AF_INET6, SOCK_STREAM, 0);
fillchar(serv, sizeof(serv), 0);
serv.sin6_family:=AF_INET6;
serv.sin6_port:=htons(1234);
serv.sin6_addr.s6_addr32:=IN6ADDR_ANY;
fpbind(servsoc, @serv, sizeof(serv));
if (fplisten(servsoc, 10) < 0) then
writeln('ow');
i:=sizeof(client);
clientsoc:=fpaccept(servsoc, @client, @i);
if (clientsoc = -1) then
writeln('ow');
res:=fpsend(clientsoc, @test[1], length(test), 0);
if (res = -1) then
writeln('ow')
else
writeln(res);
closesocket(clientsoc);
closesocket(servsoc);
end.well, that certainly can't work... the IPv6 format is max 8 four character hex numbers and 128 bits...
https://en.wikipedia.org/wiki/IPv6_address#Representation
schrieb am So., 27. Okt. 2019, 19:32:
4 * 32-bit = 128-bit?
Also 8 four *character* hexnumbers are 4 eight character hexnumbers aka four 32-bit integers.
Regards,
Sven
erk! i totally missed that was using longint... not sure if that would work, either, though, since longint can go negative... but i was mainly looking at the format and expecting to see 8 fields, not four... i guess i needed more c0ffee :(
Am 28.10.2019 um 00:24 schrieb
For the storage itself it's completely irrelevant whether it's LongWord or LongInt as 128-bit is 128-bit.
Regards,
Sven
No, it does not have to be.. The addrlen will differ of course. That's why it is there to…
I wrote an http server on my own. It works a long time already with IPv4.
For the IPV6 version I changed psockaddr to sockaddr_in6. And the proper addrlen -> sizeof( sockaddr_in6 );
I discovered that shortly after my first question about this topic here in the mailinglist.
Additionally the socket protocol family was changed from PF_INET to PF_INET6 when creating the socket.
Also I have to change fpaccept the same way as fpbind.
The server then worked properly with a localhost IPV6 request from a browser [::1]
FPC 2.6.4
Michael. _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal