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


TnProtoExchange


This function sends a command using TnSend(), waits for its reply using a application-specified function, then translates the reply using a application specified array.
Notes:

Syntax:   TnProtoExchange (SOCKET s, 
                           LPCSTR szCommand,
                           LPSTR  szResponse, UINT uBufSize, 
                           int CALLBACK TnProtoRecv (SOCKET s, 
                                                     LPSTR  szResponse,
                                                     UINT   uBufSize, 
                                                     UINT   uTimeOut, 
                                                     HFILE  hLogFile),
                           struct S_TnProto *tTranslation, 
                           int    nTabSize,
                           BOOL   bCaseCmp,
                           UINT   uTimeout,
                           HFILE  hLogFile);

Arguments:

s
The descriptor of the connection returned by TcpConnect or TcpAccept
szCommand
The command to be sent. NULL if no command are to be sent.
szResponse
A buffer provided by the application. This buffer shall be large enough to contain the full answer returned by the server
uBufSize
Its size
TnProtoRecv
A callback function call with arguments provided by the application. This function waits for the server's response. On success, it should return a positive value.
tTranslation
An array of S_TnProto structures. TnProtoExchange compare each string of this array with the beginning of the server's reply until the both strings match. On success, it returns the integer part of the structure. If a string is set to NULL, TnProtoExchange returns a TN_UNEXPECTED answer.
nTabSize
number of structures S_TnProto contained in the array tTranslation
bCaseCmp
True if the comparison between the char part of the structure S_TnProto and the received string should be case sensitive
uTimeOut
The timeout in seconds
hLogFile
A file handler into which the transmission will be copied for logging purpose


Returns:

TN_ERROR
An error has occurred
TN_OVERFLOW
uBufSize character have been transferred into the user's buffer, but the telnet termination mark has not been found
TN_TIMEOUT
A timeout has occurred
TN_SOCKETCLOSED
Remote host has closed the connection
TN_UNEXPECTED
The beginning of the string sent by the server does not match any strings from the tTranslation array
Other
The integer part of the matching S_TnProto element






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 when the last string received begins with a digit character ('0', ..., '9') and if its 4th character is not an hyphen character ('-').

220 Hello
or
220-
220-  Welcome to our FTP server
  123 digits padded with blanks
220 end of string


Note: TnReadLine should be enough for numerous protocols, however some more sophisticated 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>).
Note :
If an end of line character (<LF>) is found in the string, no conversion is done.

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


TnSendMultiLine


This function sends a 0-terminated string, then sends the telnet termination string (<CR><LF>).
The end of line characters <LF> are expanded into the telnet format <CR><LF>. Of course the sequence <CR><LF> is send as is.

Syntax:    TnSendMultiLine (SOCKET skt, LPCSTR szString, HFILE hf);

Arguments:

skt
The descriptor of the connection returned by TcpConnect or TcpAccept
szString
The string to be sent
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 SMTP functions
Tcp4u version 3.31 by Ph. Jounin and Laurent Le Bras Last updated: 10th march 1998