altcp: added 'addrinfo' and 'tcp_state' functions

This commit is contained in:
goldsimon 2017-03-22 22:29:11 +01:00
parent a46664eab2
commit c18393b52b
8 changed files with 123 additions and 8 deletions

View File

@ -840,6 +840,27 @@ altcp_mbedtls_dealloc(struct altcp_pcb *conn)
}
}
err_t
altcp_mbedtls_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port)
{
if (conn) {
return altcp_get_tcp_addrinfo(conn->inner_conn, local, addr, port);
}
return ERR_VAL;
}
#ifdef LWIP_DEBUG
enum tcp_state
altcp_mbedtls_dbg_get_tcp_state(struct altcp_pcb *conn)
{
if (conn) {
return altcp_dbg_get_tcp_state(conn->inner_conn);
}
return CLOSED;
}
#endif
const struct altcp_functions altcp_mbedtls_functions = {
altcp_mbedtls_set_poll,
altcp_mbedtls_recved,
@ -855,7 +876,11 @@ const struct altcp_functions altcp_mbedtls_functions = {
altcp_mbedtls_sndbuf,
altcp_mbedtls_sndqueuelen,
altcp_mbedtls_setprio,
altcp_mbedtls_dealloc
altcp_mbedtls_dealloc,
altcp_mbedtls_get_tcp_addrinfo
#ifdef LWIP_DEBUG
,altcp_mbedtls_dbg_get_tcp_state
#endif
};
#endif /* LWIP_ALTCP_TLS && LWIP_ALTCP_TLS_MBEDTLS */

View File

@ -242,4 +242,24 @@ altcp_setprio(struct altcp_pcb *conn, u8_t prio)
}
}
err_t
altcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port)
{
if (conn && conn->fns && conn->fns->addrinfo) {
return conn->fns->addrinfo(conn, local, addr, port);
}
return ERR_VAL;
}
#ifdef LWIP_DEBUG
enum tcp_state
altcp_dbg_get_tcp_state(struct altcp_pcb *conn)
{
if (conn && conn->fns && conn->fns->dbg_get_tcp_state) {
return conn->fns->dbg_get_tcp_state(conn);
}
return CLOSED;
}
#endif
#endif /* LWIP_ALTCP */

View File

@ -343,6 +343,29 @@ altcp_tcp_dealloc(struct altcp_pcb *conn)
/* no private state to clean up */
}
err_t
altcp_tcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port)
{
if (conn) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->inner_conn;
return tcp_tcp_get_tcp_addrinfo(pcb, local, addr, port);
}
return ERR_VAL;
}
#ifdef LWIP_DEBUG
enum tcp_state
altcp_tcp_dbg_get_tcp_state(struct altcp_pcb *conn)
{
if (conn) {
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->inner_conn;
if (pcb) {
return pcb->state;
}
}
return CLOSED;
}
#endif
const struct altcp_functions altcp_tcp_functions = {
altcp_tcp_set_poll,
altcp_tcp_recved,
@ -358,7 +381,11 @@ const struct altcp_functions altcp_tcp_functions = {
altcp_tcp_sndbuf,
altcp_tcp_sndqueuelen,
altcp_tcp_setprio,
altcp_tcp_dealloc
altcp_tcp_dealloc,
altcp_tcp_get_tcp_addrinfo
#ifdef LWIP_DEBUG
,altcp_tcp_dbg_get_tcp_state
#endif
};
#endif /* LWIP_ALTCP */

View File

@ -2055,6 +2055,30 @@ tcp_debug_state_str(enum tcp_state s)
return tcp_state_str[s];
}
err_t
tcp_tcp_get_tcp_addrinfo(struct tcp_pcb *pcb, int local, ip_addr_t *addr, u16_t *port)
{
if (pcb) {
if (local) {
if (addr) {
*addr = pcb->local_ip;
}
if (port) {
*port = pcb->local_port;
}
} else {
if (addr) {
*addr = pcb->remote_ip;
}
if (port) {
*port = pcb->remote_port;
}
}
return ERR_OK;
}
return ERR_VAL;
}
#if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
/**
* Print a tcp header for debugging purposes.

View File

@ -39,8 +39,6 @@
*
* Author: Simon Goldschmidt <goldsimon@gmx.de>
*
* @todo:
* - access to local/remote ip/port
*/
#ifndef LWIP_HDR_ALTCP_H
#define LWIP_HDR_ALTCP_H
@ -112,11 +110,14 @@ u16_t altcp_mss(struct altcp_pcb *conn);
u16_t altcp_sndbuf(struct altcp_pcb *conn);
u16_t altcp_sndqueuelen(struct altcp_pcb *conn);
#define TCP_PRIO_MIN 1
#define TCP_PRIO_NORMAL 64
#define TCP_PRIO_MAX 127
void altcp_setprio(struct altcp_pcb *conn, u8_t prio);
err_t altcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port);
#ifdef LWIP_DEBUG
enum tcp_state altcp_dbg_get_tcp_state(struct altcp_pcb *conn);
#endif
#ifdef __cplusplus
}
#endif
@ -157,6 +158,12 @@ void altcp_setprio(struct altcp_pcb *conn, u8_t prio);
#define altcp_sndqueuelen tcp_sndqueuelen
#define altcp_setprio tcp_setprio
#define altcp_get_tcp_addrinfo tcp_get_tcp_addrinfo
#ifdef LWIP_DEBUG
#define altcp_dbg_get_tcp_state tcp_dbg_get_tcp_state
#endif
#endif /* LWIP_ALTCP */
#endif /* LWIP_HDR_ALTCP_H */

View File

@ -78,6 +78,11 @@ typedef void (*altcp_setprio_fn)(struct altcp_pcb *conn, u8_t prio);
typedef void (*altcp_dealloc_fn)(struct altcp_pcb *conn);
typedef err_t (*altcp_get_tcp_addrinfo_fn)(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port);
#ifdef LWIP_DEBUG
typedef enum tcp_state (*altcp_dbg_get_tcp_state_fn)(struct altcp_pcb *conn);
#endif
struct altcp_functions {
altcp_set_poll_fn set_poll;
altcp_recved_fn recved;
@ -94,6 +99,10 @@ struct altcp_functions {
altcp_sndqueuelen_fn sndqueuelen;
altcp_setprio_fn setprio;
altcp_dealloc_fn dealloc;
altcp_get_tcp_addrinfo_fn addrinfo;
#ifdef LWIP_DEBUG
altcp_dbg_get_tcp_state_fn dbg_get_tcp_state;
#endif
};

View File

@ -395,8 +395,9 @@ void tcp_setprio (struct tcp_pcb *pcb, u8_t prio);
err_t tcp_output (struct tcp_pcb *pcb);
err_t tcp_tcp_get_tcp_addrinfo(struct tcp_pcb *pcb, int local, ip_addr_t *addr, u16_t *port);
const char* tcp_debug_state_str(enum tcp_state s);
#define tcp_dbg_get_tcp_state(pcb) ((pcb)->state)
/* for compatibility with older implementation */
#define tcp_new_ip6() tcp_new_ip_type(IPADDR_TYPE_V6)

View File

@ -75,6 +75,8 @@ enum tcp_state {
#define TCP_PRIO_NORMAL 64
#define TCP_PRIO_MAX 127
const char* tcp_debug_state_str(enum tcp_state s);
#ifdef __cplusplus
}
#endif