libite
|
#include <errno.h>
#include <poll.h>
#include <unistd.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include "lite.h"
Macros | |
#define | EXPECT_DEBUG 0 |
#define | EXPECT_POLL_TIMEOUT 3000 /* 3 sec timeout waiting for server. */ |
#define | TELL(fmt, args...) |
Functions | |
sdbuf_t * | telnet_open (int addr, short port) |
Open telnet connection to addr:port and connect. More... | |
int | telnet_close (sdbuf_t *ctx) |
Close a telnet session previously opened with telnet_open() More... | |
int | telnet_expect (sdbuf_t *ctx, char *script[], FILE *output) |
Poor man's telnet expect. More... | |
int | telnet_session (int addr, short port, char *script[], FILE *output) |
Very simple expect-like implementation for telnet. More... | |
int telnet_close | ( | sdbuf_t * | ctx | ) |
Close a telnet session previously opened with telnet_open()
ctx | An sdbuf_t socket buffer context |
int telnet_expect | ( | sdbuf_t * | ctx, |
char * | script[], | ||
FILE * | output | ||
) |
Poor man's telnet expect.
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
.
sdbuf_t* telnet_open | ( | int | addr, |
short | port | ||
) |
Open telnet connection to addr:port and connect.
addr | Integer encoded IPv4 address in network byte order |
port | Internet port number in network byte order |
int telnet_session | ( | int | addr, |
short | port, | ||
char * | script[], | ||
FILE * | output | ||
) |
Very simple expect-like implementation for telnet.
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.