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