mirror of https://gerrit.osmocom.org/libtelnet
fix line ending in telnet-client
This commit is contained in:
parent
a7896d1117
commit
e7c442681a
|
@ -29,12 +29,34 @@
|
||||||
#include "libtelnet.h"
|
#include "libtelnet.h"
|
||||||
|
|
||||||
static struct termios orig_tios;
|
static struct termios orig_tios;
|
||||||
|
static struct libtelnet_t telnet;
|
||||||
static int do_echo;
|
static int do_echo;
|
||||||
|
|
||||||
static void _cleanup(void) {
|
static void _cleanup(void) {
|
||||||
tcsetattr(STDOUT_FILENO, TCSADRAIN, &orig_tios);
|
tcsetattr(STDOUT_FILENO, TCSADRAIN, &orig_tios);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _input(unsigned char *buffer, int size) {
|
||||||
|
static unsigned char crlf[] = { '\r', '\n' };
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i != size; ++i) {
|
||||||
|
/* if we got a CR or LF, replace with CRLF
|
||||||
|
* NOTE that usually you'd get a CR in UNIX, but in raw
|
||||||
|
* mode we get LF instead (not sure why)
|
||||||
|
*/
|
||||||
|
if (buffer[i] == '\r' || buffer[i] == '\n') {
|
||||||
|
if (do_echo)
|
||||||
|
write(STDOUT_FILENO, crlf, 2);
|
||||||
|
libtelnet_send_data(&telnet, crlf, 2);
|
||||||
|
} else {
|
||||||
|
if (do_echo)
|
||||||
|
write(STDOUT_FILENO, buffer + i, 1);
|
||||||
|
libtelnet_send_data(&telnet, buffer + i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void _send(int sock, unsigned char *buffer, unsigned int size) {
|
static void _send(int sock, unsigned char *buffer, unsigned int size) {
|
||||||
int rs;
|
int rs;
|
||||||
|
|
||||||
|
@ -147,7 +169,6 @@ int main(int argc, char **argv) {
|
||||||
int sock;
|
int sock;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
struct pollfd pfd[2];
|
struct pollfd pfd[2];
|
||||||
struct libtelnet_t telnet;
|
|
||||||
struct addrinfo *ai;
|
struct addrinfo *ai;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct termios tios;
|
struct termios tios;
|
||||||
|
@ -218,12 +239,7 @@ int main(int argc, char **argv) {
|
||||||
/* read from stdin */
|
/* read from stdin */
|
||||||
if (pfd[0].revents & POLLIN) {
|
if (pfd[0].revents & POLLIN) {
|
||||||
if ((rs = read(STDIN_FILENO, buffer, sizeof(buffer))) > 0) {
|
if ((rs = read(STDIN_FILENO, buffer, sizeof(buffer))) > 0) {
|
||||||
/* local echo */
|
_input(buffer, rs);
|
||||||
if (do_echo)
|
|
||||||
write(STDOUT_FILENO, buffer, rs);
|
|
||||||
|
|
||||||
/* send over the wire */
|
|
||||||
libtelnet_send_data(&telnet, buffer, rs);
|
|
||||||
} else if (rs == 0) {
|
} else if (rs == 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue