#include <errno.h>
#include <poll.h>
#include <unistd.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include "lite.h"
Go to the source code of this file.
- Author
- Joachim Wiberg
- Date
- 2010-2021
- Copyright
- ISC License
Definition in file telnet.c.
◆ EXPECT_DEBUG
◆ EXPECT_POLL_TIMEOUT
#define EXPECT_POLL_TIMEOUT 3000 /* 3 sec timeout waiting for server. */ |
◆ TELL
#define TELL |
( |
| fmt, |
|
|
| args... ) |
◆ telnet_close()
Close a telnet session previously opened with telnet_open()
- Parameters
-
ctx | An sdbuf_t socket buffer context |
- Returns
- Always returns POSIX OK(0).
Definition at line 116 of file telnet.c.
◆ telnet_expect()
int telnet_expect |
( |
sdbuf_t * | ctx, |
|
|
char * | script[], |
|
|
FILE * | output ) |
Poor man's telnet expect
- Parameters
-
ctx | Telnet session context from telnet_open() |
script | NULL terminated list of expect and response strings |
output | Optional output from session |
Issues script
sequence on telnet session specified in ctx
, with optional output
from session.
The script
consists of strings of expect and response pairs. For example, expect "ogin: " followed by response "root\n", expect "assword: "with response "secret\n", concluded by NULL
.
- Returns
- POSIX OK(0) or non-zero on error.
Definition at line 174 of file telnet.c.
◆ telnet_open()
sdbuf_t * telnet_open |
( |
int | addr, |
|
|
short | port ) |
Open telnet connection to addr:port and connect.
- Parameters
-
addr | Integer encoded IPv4 address in network byte order |
port | Internet port number in network byte order |
- Returns
- An sdbuf_t socket buffer context.
Definition at line 56 of file telnet.c.
◆ telnet_session()
int telnet_session |
( |
int | addr, |
|
|
short | port, |
|
|
char * | script[], |
|
|
FILE * | output ) |
Very simple expect-like implementation for telnet.
- Parameters
-
addr | Integer encoded IPv4 address, in network byte order, use htonl(). |
port | Internet port to connect to, in network byte order, use htons(). |
script | Expect like script of paired 'expect', 'response' strings. |
output | A FILE pointer to a tempfile() for output from the last command. |
This is a very simple expect-like implementation for querying and operating daemons remotely over telnet.
The script
is a query-response type of list of strings leading up to a final command, which output is then written to the given output
file.
- Returns
- POSIX OK(0), or non-zero with errno set on error.
Definition at line 295 of file telnet.c.