comp.lang.ada
 help / color / mirror / Atom feed
From: "Ultor" <ultor@hert.org>
Subject: Get_Line vs Adasockets
Date: 2000/08/13
Date: 2000-08-13T14:46:04+00:00	[thread overview]
Message-ID: <8n6cbc$9ge$1@news.tpi.pl> (raw)

Hello

I'm new in ADA (code since Friday). I got a problem with Get_Line in my
source. I tried to make it working over 2 hours and still got a problem with
that.

When i did Get_Line like this

   BUF := Get_Line(Incoming_Socket);

then I had problem with CONSTRAINT_ERROR. I don't know how to set size of
BUF to be the same as line from Get_Line (as I know that should eliminate
CONSTRAINT_ERROR).

I would be very gratefull if some1 could correct my source.

---- snip -------
with Ada.Exceptions,Ada.Text_IO,Sockets,Sockets.Thin,Sockets.Naming;
use Ada.Exceptions,Ada.Text_IO,Sockets,Sockets.Thin,Sockets.Naming;
with Ada.Unchecked_Conversion; use type C.int;

procedure testsock is
  function Sock2In is new Ada.Unchecked_Conversion (Source =>
Sockaddr_Access, Target => Sockaddr_In_Access);
  Accepting_Socket : Socket_FD;
  Incoming_Socket  : Socket_FD;
  Socker           : Sockaddr_Access := new Sockaddr;
  BUF              : String (1..500);
  i                : aliased C.int;

begin
  Socket (Accepting_Socket, AF_INET, SOCK_STREAM);
  Setsockopt (Accepting_Socket, SOL_SOCKET, SO_REUSEADDR, 1);
  Bind (Accepting_Socket, 31337);
  Listen (Accepting_Socket);
  Accept_Socket (Accepting_Socket, Incoming_Socket);

  loop
        i:=C_Getpeername(Get_FD(Incoming_Socket),Socker,i'Access);
        Put_Line(Incoming_Socket,"CONNECTED FROM: " &
Image(Sock2In(Socker).Sin_Addr));

        Get_Line(Incoming_Socket,Buf,Buf'Size);
        if BUF(1..Buf'Length)="QUIT" then Put_Line (Incoming_Socket, "BYE
BYE"); end if;

        Shutdown(Incoming_Socket,Both);
  end loop;

end testsock;
---- snip ----

PS. Where can i get some adasockets example sources (other than this one
from library) ?

Best Regards,

 Marek Bialoglowy [Ultor@hert.org] ------ Network Security Consultant
 GROUP: HERT (www.hert.org) -- PGP: http://www.hert.org/pgp/Ultor.asc






             reply	other threads:[~2000-08-13  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-08-13  0:00 Ultor [this message]
2000-08-13  0:00 ` Get_Line vs Adasockets Dale Stanbrough
2000-08-14  0:00   ` Martin Dowie
2000-08-17  0:00     ` tmoran
2000-08-21  0:00       ` Martin Dowie
2000-08-14  0:00 ` Anders Gidenstam
2000-08-14  0:00 ` Ken Garlington
2000-08-14  0:00   ` Ultor
2000-08-14  0:00     ` Ted Dennison
2000-08-14  0:00       ` Michal Zalewski
2000-08-14  0:00         ` Ted Dennison
2000-08-21  1:44   ` David Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox