Added function tcp_debug_state_str() to convert a tcp state to a human-readable string.

This commit is contained in:
goldsimon 2009-08-23 10:57:37 +00:00
parent 4f265dce60
commit ae7a7a0abf
3 changed files with 26 additions and 36 deletions

View File

@ -19,6 +19,10 @@ HISTORY
++ New features: ++ New features:
2009-09-23 Simon Goldschmidt
* tcp.h/.c: Added function tcp_debug_state_str() to convert a tcp state
to a human-readable string.
++ Bugfixes: ++ Bugfixes:

View File

@ -53,6 +53,20 @@
#include <string.h> #include <string.h>
const char *tcp_state_str[] = {
"CLOSED",
"LISTEN",
"SYN_SENT",
"SYN_RCVD",
"ESTABLISHED",
"FIN_WAIT_1",
"FIN_WAIT_2",
"CLOSE_WAIT",
"CLOSING",
"LAST_ACK",
"TIME_WAIT"
};
/* Incremented every coarse grained timer shot (typically every 500 ms). */ /* Incremented every coarse grained timer shot (typically every 500 ms). */
u32_t tcp_ticks; u32_t tcp_ticks;
const u8_t tcp_backoff[13] = const u8_t tcp_backoff[13] =
@ -1325,6 +1339,12 @@ tcp_debug_print(struct tcp_hdr *tcphdr)
LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n")); LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
} }
const char*
tcp_debug_state_str(enum tcp_state s)
{
return tcp_state_str[s];
}
/** /**
* Print a tcp state for debugging purposes. * Print a tcp state for debugging purposes.
* *
@ -1333,42 +1353,7 @@ tcp_debug_print(struct tcp_hdr *tcphdr)
void void
tcp_debug_print_state(enum tcp_state s) tcp_debug_print_state(enum tcp_state s)
{ {
LWIP_DEBUGF(TCP_DEBUG, ("State: ")); LWIP_DEBUGF(TCP_DEBUG, ("State: %s\n", tcp_state_str[s]));
switch (s) {
case CLOSED:
LWIP_DEBUGF(TCP_DEBUG, ("CLOSED\n"));
break;
case LISTEN:
LWIP_DEBUGF(TCP_DEBUG, ("LISTEN\n"));
break;
case SYN_SENT:
LWIP_DEBUGF(TCP_DEBUG, ("SYN_SENT\n"));
break;
case SYN_RCVD:
LWIP_DEBUGF(TCP_DEBUG, ("SYN_RCVD\n"));
break;
case ESTABLISHED:
LWIP_DEBUGF(TCP_DEBUG, ("ESTABLISHED\n"));
break;
case FIN_WAIT_1:
LWIP_DEBUGF(TCP_DEBUG, ("FIN_WAIT_1\n"));
break;
case FIN_WAIT_2:
LWIP_DEBUGF(TCP_DEBUG, ("FIN_WAIT_2\n"));
break;
case CLOSE_WAIT:
LWIP_DEBUGF(TCP_DEBUG, ("CLOSE_WAIT\n"));
break;
case CLOSING:
LWIP_DEBUGF(TCP_DEBUG, ("CLOSING\n"));
break;
case LAST_ACK:
LWIP_DEBUGF(TCP_DEBUG, ("LAST_ACK\n"));
break;
case TIME_WAIT:
LWIP_DEBUGF(TCP_DEBUG, ("TIME_WAIT\n"));
break;
}
} }
/** /**

View File

@ -591,6 +591,7 @@ extern u32_t tcp_ticks;
#if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG #if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
void tcp_debug_print(struct tcp_hdr *tcphdr); void tcp_debug_print(struct tcp_hdr *tcphdr);
void tcp_debug_print_flags(u8_t flags); void tcp_debug_print_flags(u8_t flags);
const char* tcp_debug_state_str(enum tcp_state s);
void tcp_debug_print_state(enum tcp_state s); void tcp_debug_print_state(enum tcp_state s);
void tcp_debug_print_pcbs(void); void tcp_debug_print_pcbs(void);
s16_t tcp_pcbs_sane(void); s16_t tcp_pcbs_sane(void);