Tcp4u - Telnet related functions


TnGetAnswerCode


This function reads a full answer via TnReadMultiLine, then translate the 3 digits at the beginning of the string.
The function returns either a telnet code (the 3 digits at the beginning of the string) or an error code.

Syntax:   TnGetAnswerCode (SOCKET skt, LPSTR szBuf, UINT uBufSize,
                           UINT uTimeOut, HFILE hf);

Arguments:

skt
The descriptor of the connection returned by TcpConnect or TcpAccept
szBuf
The user's buffer into which the string will be copied
uBufSize
Its size
uTimeOut
The timeout
hf
A file handler into which the data will be copied


Returns:

TN_ERROR
An error or a timeout has occurred
100< Rc < 999
Rc is a telnet answer code


TnReadLine


This function receives a string ended by an EOL character (ASCII 10).
A NUL character is added to the returned string.

Syntax:    TnReadLine (SOCKET skt, LPSTR szBuf, UINT uBufSize,
                       UINT uTimeOut, HFILE hf);

Arguments:

skt
The descriptor of the connection returned by TcpConnect or TcpAccept
szBuf
The user's buffer into which the string will be copied
uBufSize
Its size
uTimeOut
The timeout
hf
A file handler into which the data will be copied


Returns:

TN_BUFFERFREED
szBuf is not a writeable buffer
TN_ERROR
An error has occurred
TN_OVERFLOW
uBufSize character have been transferred into the user's buffer, but the EOL character has not been found
TN_TIMEOUT
A timeout has occurred
TN_SOCKETCLOSED
Remote host has closed the connection
TN_SUCCESS
The string is available into szBuf


TnReadMultiLine


This function receives one or more strings ended by an EOL character (ASCII 10).
A NUL character is added to the returned string.
TnReadMultiLine returns if the last string received does not contain an hyphen character.
For instance, here are two valid strings:

220 Hello
or
220-
220-  Welcome to our FTP server
220-
220


Note: TnReadLine should be enough for numerous protocols, however some more sophiscated protocols like FTP are more verbose and require to send multi-line requests or response. TnReadMultiLine reads the full request or response.

Syntax:    TnReadMultiLine (SOCKET skt, LPSTR szBuf, UINT uBufSize,
                            UINT uTimeOut, HFILE hf);

Arguments:

skt
The descriptor of the connection returned by TcpConnect or TcpAccept
szBuf
The user's buffer into which the string will be copied
uBufSize
Its size
uTimeOut
The timeout
hf
A file handler into which the data will be copied


Returns:

TN_BUFFERFREED
szBuf is not a writeable buffer
TN_ERROR
An error has occurred
TN_OVERFLOW
uBufSize character have been transferred into the user's buffer, but the EOL character has not been found
TN_TIMEOUT
A timeout has occurred
TN_SOCKETCLOSED
Remote host has closed the connection
TN_SUCCESS
The string is available into szBuf

TnSend


This function sends a 0-terminated string, then sends the telnet termination string (<CR><LF>).

Syntax:    TnSend (SOCKET skt, LPCSTR szString, BOOL bHighPriority, HFILE hf);

Arguments:

skt
The descriptor of the connection returned by TcpConnect or TcpAccept
szString
The string to be sent
bHighPriority
TRUE if the string must be sent in Out Of Band mode
hf
A file handler into which the data will be written


Returns:

TN_ERROR
An error has occurred
TN_SUCCESS
The string has been successfully sent


Overview Multi purpose func. TCP functions Telnet related func HTTP functions UDP functions
Tcp4u version 3.2 by Ph. Jounin and Laurent Le Bras