00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 #include <arpa/inet.h>
00087 #include <netinet/in.h>
00088 #include <netinet/ip.h>
00089 #include <netinet/icmp.h>
00090 #include <netinet/ip_icmp.h>
00091 #include <netinet/ipcsum.h>
00092 #include <net/netdebug.h>
00093 #include <sys/socket.h>
00094
00095 extern TCPSOCKET *tcpSocketList;
00096 extern UDPSOCKET *udpSocketList;
00097
00098 FILE *__tcp_trs;
00099 uint_fast8_t __tcp_trf;
00101 void NutDumpTcpHeader(FILE * stream, char * ds, TCPSOCKET * sock, NETBUF * nb)
00102 {
00103 static prog_char fmt[] = "%s%p[%u]-SEQ(%lx)";
00104 TCPHDR *th = (TCPHDR *) nb->nb_tp.vp;
00105
00106 fprintf_P(stream, fmt, ds, sock, (u_int)nb->nb_ap.sz, ntohl(th->th_seq));
00107 if (th->th_flags & TH_ACK)
00108 fprintf(stream, "-ACK(%lx)", ntohl(th->th_ack));
00109 if (th->th_flags & TH_FIN)
00110 fputs("-FIN", stream);
00111 if (th->th_flags & TH_SYN)
00112 fputs("-SYN", stream);
00113 if (th->th_flags & TH_RST)
00114 fputs("-RST", stream);
00115 if (th->th_flags & TH_PUSH)
00116 fputs("-PSH", stream);
00117 if (th->th_flags & TH_URG)
00118 fputs("-URG", stream);
00119 fputs("\n", stream);
00120 }
00121
00122 void NutDumpSockState(FILE * stream, uint8_t state, char * lead, char * trail)
00123 {
00124 if (lead)
00125 fputs(lead, stream);
00126 switch (state) {
00127 case TCPS_LISTEN:
00128 fputs("LISTEN", stream);
00129 break;
00130 case TCPS_SYN_SENT:
00131 fputs("SYNSENT", stream);
00132 break;
00133 case TCPS_SYN_RECEIVED:
00134 fputs("SYNRCVD", stream);
00135 break;
00136 case TCPS_ESTABLISHED:
00137 fputs("ESTABL", stream);
00138 break;
00139 case TCPS_FIN_WAIT_1:
00140 fputs("FINWAIT1", stream);
00141 break;
00142 case TCPS_FIN_WAIT_2:
00143 fputs("FINWAIT2", stream);
00144 break;
00145 case TCPS_CLOSE_WAIT:
00146 fputs("CLOSEWAIT", stream);
00147 break;
00148 case TCPS_CLOSING:
00149 fputs("CLOSING", stream);
00150 break;
00151 case TCPS_LAST_ACK:
00152 fputs("LASTACK", stream);
00153 break;
00154 case TCPS_TIME_WAIT:
00155 fputs("TIMEWAIT", stream);
00156 break;
00157 case TCPS_CLOSED:
00158 fputs("CLOSED", stream);
00159 break;
00160 default:
00161 fputs("?UNK?", stream);
00162 break;
00163 }
00164 if (trail)
00165 fputs(trail, stream);
00166 }
00167
00168
00169 void NutDumpSocketList(FILE * stream)
00170 {
00171 TCPSOCKET *ts;
00172 UDPSOCKET *us;
00173
00174 static prog_char fmt1[] = "%10p TCP %15s:%-6u ";
00175 static prog_char fmt2[] = "%10p UDP %6u\r\n";
00176
00177 fputs("\r\nSocket Typ Local Remote State\n", stream);
00178
00179
00180 for (ts = tcpSocketList; ts; ts = ts->so_next) {
00181 fprintf_P(stream, fmt1, ts, inet_ntoa(ts->so_local_addr), ntohs(ts->so_local_port));
00182 fprintf(stream, "%15s:%-6u ", inet_ntoa(ts->so_remote_addr), ntohs(ts->so_remote_port));
00183 NutDumpSockState(stream, ts->so_state, 0, "\r\n");
00184 }
00185 for (us = udpSocketList; us; us = us->so_next) {
00186 fprintf_P(stream, fmt2, us, ntohs(us->so_local_port));
00187 }
00188 }
00189
00190
00198 void NutTraceTcp(FILE * stream, uint8_t flags)
00199 {
00200 if (stream)
00201 __tcp_trs = stream;
00202 if (__tcp_trs)
00203 __tcp_trf = flags;
00204 else
00205 __tcp_trf = 0;
00206 }