Pregunta

Is there any way to perform 3-way TCP/IP handshake in Ada without the use of c++ Pragma?

If so, does anybody have an example?

¿Fue útil?

Solución

If you’re using GNAT, the answer is to use GNAT.Sockets; from the spec of that package, there’s the server side (with use GNAT.Sockets):

Address.Addr := Addresses (Get_Host_By_Name (Host_Name), 1);
Address.Port := 5876;
Create_Socket (Server);
Set_Socket_Option
  (Server,
   Socket_Level,
   (Reuse_Address, True));
Bind_Socket (Server, Address);
Listen_Socket (Server);
Accept_Socket (Server, Socket, Address);

and the client side:

Address.Addr := Addresses (Get_Host_By_Name (Host_Name), 1);
Address.Port := 5876;
Create_Socket (Socket);
Set_Socket_Option
  (Socket,
   Socket_Level,
   (Reuse_Address, True));
Connect_Socket (Socket, Address);

If you’re not using GNAT, you may be lucky enough to find that your compiler provides an equivalent. If you’re using GNAT but want to see how they’ve done it, look at the body of GNAT.Sockets.

Otros consejos

If you want to control the sending of SYN, SYN-ACK and ACK packages youself, you have to circumvent the TCP stack, as that is what a TCP stack does for you, so you don't have to do it yourself.

How to circumvent the TCP stack depends on your operating system.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top