Wednesday, August 30, 2017

lang/gcc gnat : seems that sockets doesn't work

Hello,

I'm learning Ada language and found that the following code
raise an error at runtime on OpenBSD 6.1 :

raised GNAT.SOCKETS.SOCKET_ERROR : [47] Address family not supported by
protocol family

The following code works on another operating system also using gnat

-->B------------------------------------------------>B---
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Sockets; use GNAT.Sockets;
with Ada.Streams; use Ada.Streams;

procedure Main is
Client : Socket_Type;
Address : Sock_Addr_Type;
Channel : Stream_Access;
Send : String := (1 => ASCII.CR, 2 => ASCII.LF,
3 => ASCII.CR, 4 => ASCII.LF);
Offset : Ada.Streams.Stream_Element_Count;
Data : Ada.Streams.Stream_Element_Array (1 .. 256);
begin
Address.Addr := Inet_Addr("163.172.223.238");
Address.Port := 70;
Create_Socket (Client);
Connect_Socket (Client, Address);
Channel := Stream(Client);

String'Write (Channel, "/" & Send);
loop
Read (Channel.All, Data, Offset);
exit when Offset = 0;
for I in 1 .. Offset loop
Ada.Text_IO.Put (Character'Val (Data (I)));
end loop;
end loop;
end Main;
-->B------------------------------------------------>B---

No comments:

Post a Comment