fpbind ipv6 version

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

fpbind ipv6 version

Rainer Stratmann
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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpbind ipv6 version

Michael Van Canneyt


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  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpbind ipv6 version

Alexander Grotewohl
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.

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  -  [hidden email]
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpbind ipv6 version

wkitty42
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


>      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  -  [hidden email]
>> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> 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.*
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpbind ipv6 version

Free Pascal - General mailing list
<[hidden email]> schrieb am So., 27. Okt. 2019, 19:32:
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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpbind ipv6 version

wkitty42
On 10/27/19 6:23 PM, Sven Barth via fpc-pascal wrote:

> <[hidden email]> 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.*
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpbind ipv6 version

Free Pascal - General mailing list
Am 28.10.2019 um 00:24 schrieb [hidden email]:

> On 10/27/19 6:23 PM, Sven Barth via fpc-pascal wrote:
>> <[hidden email]> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpbind ipv6 version

Rainer Stratmann
In reply to this post by Michael Van Canneyt
On Sonntag, 27. Oktober 2019 10:32:11 CET 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.

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  -  [hidden email]
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal