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
00087
00088
00089
00090 #include <arpa/inet.h>
00091 #include <netinet/in.h>
00092 #include <netinet/ip.h>
00093 #include <netinet/icmp.h>
00094 #include <netinet/ip_icmp.h>
00095 #include <netinet/ipcsum.h>
00096 #include <net/netdebug.h>
00097 #include <sys/socket.h>
00098
00099 extern TCPSOCKET *tcpSocketList;
00100 extern UDPSOCKET *udpSocketList;
00101
00102 FILE *__tcp_trs;
00103 uint_fast8_t __tcp_trf;
00105 void NutDumpTcpHeader(FILE * stream, char * ds, TCPSOCKET * sock, NETBUF * nb)
00106 {
00107 static prog_char fmt[] = "%s%p[%u]-SEQ(%lx)";
00108 TCPHDR *th = (TCPHDR *) nb->nb_tp.vp;
00109
00110 fprintf_P(stream, fmt, ds, sock, (unsigned int)nb->nb_ap.sz, ntohl(th->th_seq));
00111 if (th->th_flags & TH_ACK)
00112 fprintf(stream, "-ACK(%lx)", ntohl(th->th_ack));
00113 if (th->th_flags & TH_FIN)
00114 fputs("-FIN", stream);
00115 if (th->th_flags & TH_SYN)
00116 fputs("-SYN", stream);
00117 if (th->th_flags & TH_RST)
00118 fputs("-RST", stream);
00119 if (th->th_flags & TH_PUSH)
00120 fputs("-PSH", stream);
00121 if (th->th_flags & TH_URG)
00122 fputs("-URG", stream);
00123 fputs("\n", stream);
00124 }
00125
00126 void NutDumpSockState(FILE * stream, uint8_t state, char * lead, char * trail)
00127 {
00128 if (lead)
00129 fputs(lead, stream);
00130 switch (state) {
00131 case TCPS_LISTEN:
00132 fputs("LISTEN", stream);
00133 break;
00134 case TCPS_SYN_SENT:
00135 fputs("SYNSENT", stream);
00136 break;
00137 case TCPS_SYN_RECEIVED:
00138 fputs("SYNRCVD", stream);
00139 break;
00140 case TCPS_ESTABLISHED:
00141 fputs("ESTABL", stream);
00142 break;
00143 case TCPS_FIN_WAIT_1:
00144 fputs("FINWAIT1", stream);
00145 break;
00146 case TCPS_FIN_WAIT_2:
00147 fputs("FINWAIT2", stream);
00148 break;
00149 case TCPS_CLOSE_WAIT:
00150 fputs("CLOSEWAIT", stream);
00151 break;
00152 case TCPS_CLOSING:
00153 fputs("CLOSING", stream);
00154 break;
00155 case TCPS_LAST_ACK:
00156 fputs("LASTACK", stream);
00157 break;
00158 case TCPS_TIME_WAIT:
00159 fputs("TIMEWAIT", stream);
00160 break;
00161 case TCPS_CLOSED:
00162 fputs("CLOSED", stream);
00163 break;
00164 default:
00165 fputs("?UNK?", stream);
00166 break;
00167 }
00168 if (trail)
00169 fputs(trail, stream);
00170 }
00171
00172
00173 void NutDumpSocketList(FILE * stream)
00174 {
00175 TCPSOCKET *ts;
00176 UDPSOCKET *us;
00177
00178 static prog_char fmt1[] = "%10p TCP %15s:%-6u ";
00179 static prog_char fmt2[] = "%10p UDP %6u\r\n";
00180
00181 fputs("\r\nSocket Typ Local Remote State\n", stream);
00182
00183
00184 for (ts = tcpSocketList; ts; ts = ts->so_next) {
00185 fprintf_P(stream, fmt1, ts, inet_ntoa(ts->so_local_addr), ntohs(ts->so_local_port));
00186 fprintf(stream, "%15s:%-6u ", inet_ntoa(ts->so_remote_addr), ntohs(ts->so_remote_port));
00187 NutDumpSockState(stream, ts->so_state, 0, "\r\n");
00188 }
00189 for (us = udpSocketList; us; us = us->so_next) {
00190 fprintf_P(stream, fmt2, us, ntohs(us->so_local_port));
00191 }
00192 }
00193
00194
00202 void NutTraceTcp(FILE * stream, uint8_t flags)
00203 {
00204 if (stream)
00205 __tcp_trs = stream;
00206 if (__tcp_trs)
00207 __tcp_trf = flags;
00208 else
00209 __tcp_trf = 0;
00210 }