mirror of https://gerrit.osmocom.org/libtelnet
add printf data sender
This commit is contained in:
parent
ceeeddaff3
commit
d58f49f03a
17
libtelnet.c
17
libtelnet.c
|
@ -855,3 +855,20 @@ void libtelnet_begin_compress2(libtelnet_t *telnet) {
|
||||||
_event(telnet, LIBTELNET_EV_COMPRESS, 1, 0, 0, 0);
|
_event(telnet, LIBTELNET_EV_COMPRESS, 1, 0, 0, 0);
|
||||||
#endif /* HAVE_ZLIB */
|
#endif /* HAVE_ZLIB */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* send formatted data through libtelnet_send_data */
|
||||||
|
int libtelnet_send_printf(libtelnet_t *telnet, const char *fmt, ...) {
|
||||||
|
char buffer[4096];
|
||||||
|
va_list va;
|
||||||
|
int rs;
|
||||||
|
|
||||||
|
/* format */
|
||||||
|
va_start(va, fmt);
|
||||||
|
rs = vsnprintf(buffer, sizeof(buffer), fmt, va);
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
|
/* send */
|
||||||
|
libtelnet_send_data(telnet, (unsigned char *)buffer, rs);
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
|
@ -228,4 +228,13 @@ extern void libtelnet_send_subnegotiation(libtelnet_t *telnet,
|
||||||
/* begin sending compressed data (server only) */
|
/* begin sending compressed data (server only) */
|
||||||
extern void libtelnet_begin_compress2(libtelnet_t *telnet);
|
extern void libtelnet_begin_compress2(libtelnet_t *telnet);
|
||||||
|
|
||||||
|
/* send formatted data (through libtelnet_send_data) */
|
||||||
|
#ifdef __GNUC__
|
||||||
|
# define LIBTELNET_GNU_PRINTF(f,a) __attribute__((printf(f, a)))
|
||||||
|
#else
|
||||||
|
# define LIBTELNET_GNU_PRINTF(f,a)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern int libtelnet_send_printf(libtelnet_t *telnet, const char *fmt, ...);
|
||||||
|
|
||||||
#endif /* !defined(LIBTELNET_INCLUDE) */
|
#endif /* !defined(LIBTELNET_INCLUDE) */
|
||||||
|
|
Loading…
Reference in New Issue