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