  Using the TCP/IP stack

To start the TCP/IP stack in command line mode, run
the TCP.EXE binary without arguments.

You can also give the program to start as a command
line argument.


  How to use the TCP services in your own programs

This TCP/IP stack works using software interrupts.
It has the following commands:

  (AX = 0) Service

Reads raw packets from the incoming packet buffer, parses
them and writes the data to the corresponding sockets
read buffers. Sends all data that is waiting in sockets
write buffers.

  (AX = 1) Connect

DS:SI = pointer to DNS or IP address
BX = port
CX = udp socket (0 if tcp)

Resolves DNS and creates a socket. Returns the socket
descriptor to AX, or -1 if an error happened. Note that
the socket is not usable before the server responds to the
SYN by sending ACK. Currently there is is no error codes
implemented so it's impossible to know when the socket has
became usable.

  (AX = 2) Read

BX = socket descriptor

Reads a byte from the socket. Returns -1 if the read
buffer was empty or if an error happened.

  (AX = 3) Write

BX = socket descriptor
CX = byte

Writes the byte in CX to the socket. Returns -1 if
an error happened.

  (AX = 4) Close socket

BX = socket descriptor

Closes the socket.

  (AX = 5) Open port

BX = port
CX = udp (0 if tcp)

Opens a port. Returns a special socket descriptor in AX.
Reading the descriptor returns -1 if the port has no incoming
connections. If the port has an incoming connection, the new socket
descriptor has to be extracted by using two reads. The first read
returns the more significant byte of the socket descriptor OR'd
by the sign bit. The second read returns the less significant byte.

C-like pseudocode of accepting the connection:

short int c;
unsigned short new_connection;

while(1)
{
  c = read(port_sd);
  if(c != -1)
  {
    new_connection = (unsigned short)c << 8;
    c = read(port_sd);
    new_connection |= c;
    new_connection &= 0x7FFF;
    serve_socket(new_connection);
  }
}

The port can be closed by calling the close function with the port's
socket descriptor.