telnet_connection
interface is used to control the text
console telnet server.
The text console has a built-in telnet server. Both IPv4 and IPv6 connections are supported.
The setup method starts a telnet server by opening a listening
socket on port, or an arbitrary port if 0 is given. If a
listening port is already open, it is closed first, which includes
disconnecting any connected client. The method returns false
if the
socket could not be opened e.g. if the given port is busy and the
new_telnet_port_if_busy attribute is false
.
The listening method indicates whether a listening socket has been opened.
The connected method indicates whether there is a connected telnet client.
The remote_port method returns the remote port of the first connected client, or 0 if no client is connected.
The remote_ip method returns the IP of the first connected client, or 0 if no client is connected. The caller is responsible for freeing the returned buffer. The buffer size must be either at least 4 or 16 bytes depending on if the client uses IPv4 or IPv6.
The local_port method returns the port of the listening socket, or 0 if no socket is opened.
The disconnect method forcibly disconnects any connected client.
The shutdown method disconnects any client and closes the listening socket.
SIM_INTERFACE(telnet_connection) { bool (*setup)(conf_object_t *NOTNULL obj, uint16 port); bool (*listening)(conf_object_t *NOTNULL obj); bool (*connected)(conf_object_t *NOTNULL obj); uint16 (*remote_port)(conf_object_t *NOTNULL obj); bytes_t (*remote_ip)(conf_object_t *NOTNULL obj); uint16 (*local_port)(conf_object_t *NOTNULL obj); void (*disconnect)(conf_object_t *NOTNULL obj); void (*shutdown)(conf_object_t *NOTNULL obj); }; #define TELNET_CONNECTION_INTERFACE "telnet_connection"