Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2019-10

fpbind ipv6 version

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt
to Rainer Stratmann
Rainer Stratmann wrote 11 lines
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.

Alexander Grotewohl
to Michael Van Canneyt

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.
Michael Van Canneyt wrote 25 lines
On Sat, 26 Oct 2019, Rainer Stratmann wrote: > 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. _______________________________________________ fpc-pascal maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Unknown author
to Alexander Grotewohl
Alexander Grotewohl wrote 10 lines
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);

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

Show quoted text 63 lines
    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. On 10/27/2019 5:32 AM, Michael Van Canneyt wrote: > > > On Sat, 26 Oct 2019, Rainer Stratmann wrote: > >> 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. > _______________________________________________ > fpc-pascal maillist  -  > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list unless* *a signed and pre-paid contract is in effect with us.*
Sven Barth
to Unknown author

schrieb am So., 27. Okt. 2019, 19:32:

Show quoted text 20 lines
On 10/27/19 11:56 AM, Alexander Grotewohl wrote: > 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); 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

4 * 32-bit = 128-bit?

Also 8 four *character* hexnumbers are 4 eight character hexnumbers aka four 32-bit integers.

Regards,
Sven

Unknown author
to Sven Barth
Sven Barth wrote 17 lines
schrieb am So., 27. Okt. 2019, 19:32: On 10/27/19 11:56 AM, Alexander Grotewohl wrote: > const >      IN6ADDR_ANY: array[0..3] of longint = (0, 0, 0, 0); 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 4 * 32-bit = 128-bit? Also 8 four *character* hexnumbers are 4 eight character hexnumbers aka four 32-bit integers.

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 :(

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list unless* *a signed and pre-paid contract is in effect with us.*
Sven Barth
to Unknown author

Am 28.10.2019 um 00:24 schrieb

Show quoted text 24 lines
On 10/27/19 6:23 PM, Sven Barth via fpc-pascal wrote: > schrieb am So., 27. Okt. 2019, 19:32: > >     On 10/27/19 11:56 AM, Alexander Grotewohl wrote: >      > const >      >      IN6ADDR_ANY: array[0..3] of longint = (0, 0, 0, 0); > >     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 > > > 4 * 32-bit = 128-bit? > > Also 8 four *character* hexnumbers are 4 eight character hexnumbers > aka four 32-bit integers. 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 :(

For the storage itself it's completely irrelevant whether it's LongWord or LongInt as 128-bit is 128-bit.

Regards,
Sven

Rainer Stratmann
to Michael Van Canneyt: No, it does not have to be.. The addrlen will differ of course. That's why it is there to…
CET Michael Van Canneyt wrote 19 lines
On Sat, 26 Oct 2019, Rainer Stratmann wrote: > 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.

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