[fpc-pascal] fpbind ipv6 version
wkitty42 at windstream.net
wkitty42 at windstream.net
Sun Oct 27 19:12:14 CET 2019
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 - fpc-pascal at lists.freepascal.org
>> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> 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.*
More information about the fpc-pascal
mailing list