diff --git a/tcp.c b/tcp.c index cdf55219..35fc6ec1 100644 --- a/tcp.c +++ b/tcp.c @@ -61,8 +61,25 @@ tcp_qprintf(tcp_queue_t *tq, const char *fmt, ...) tq->tq_depth += td->td_datalen; } +/* + * Put data on a TCP queue + */ +void +tcp_qput(tcp_queue_t *tq, const uint8_t *buf, size_t len) +{ + tcp_data_t *td; + void *out; + td = malloc(sizeof(tcp_data_t)); + td->td_offset = 0; + td->td_datalen = len; + out = malloc(td->td_datalen); + memcpy(out, buf, td->td_datalen); + td->td_data = out; + TAILQ_INSERT_TAIL(&tq->tq_messages, td, td_link); + tq->tq_depth += td->td_datalen; +} /* * printfs data on a TCP connection diff --git a/tcp.h b/tcp.h index 231ac621..d9af2ed1 100644 --- a/tcp.h +++ b/tcp.h @@ -104,6 +104,8 @@ void tcp_printf(tcp_session_t *ses, const char *fmt, ...); void tcp_qprintf(tcp_queue_t *tq, const char *fmt, ...); +void tcp_qput(tcp_queue_t *tq, const uint8_t *buf, size_t len); + void tcp_output_queue(tcp_session_t *ses, tcp_queue_t *dst, tcp_queue_t *src); void *tcp_create_client(const char *hostname, int port, size_t session_size,