netdebug.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2003 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00034 /*
00035  * $Log: netdebug.c,v $
00036  * Revision 1.8  2007/07/17 18:31:44  haraldkipp
00037  * Output strings must be signed characters. Fixed provided by Michael Mueller.
00038  *
00039  * Revision 1.7  2006/03/16 15:25:35  haraldkipp
00040  * Changed human readable strings from u_char to char to stop GCC 4 from
00041  * nagging about signedness.
00042  *
00043  * Revision 1.6  2005/01/13 18:48:53  haraldkipp
00044  * Compiler warnings avoided.
00045  *
00046  * Revision 1.5  2005/01/02 10:07:10  haraldkipp
00047  * Replaced platform dependant formats in debug outputs.
00048  *
00049  * Revision 1.4  2004/04/07 12:13:58  haraldkipp
00050  * Matthias Ringwald's *nix emulation added
00051  *
00052  * Revision 1.3  2004/03/19 09:05:08  jdubiec
00053  * Fixed format strings declarations for AVR.
00054  *
00055  * Revision 1.2  2004/03/16 16:48:45  haraldkipp
00056  * Added Jan Dubiec's H8/300 port.
00057  *
00058  * Revision 1.1.1.1  2003/05/09 14:41:34  haraldkipp
00059  * Initial using 3.2.1
00060  *
00061  * Revision 1.8  2003/05/06 18:16:14  harald
00062  * Separate PPP debug module added.
00063  *
00064  * Revision 1.7  2003/02/04 18:14:57  harald
00065  * Version 3 released
00066  *
00067  * Revision 1.6  2002/10/29 15:32:24  harald
00068  * PPP support
00069  *
00070  * Revision 1.5  2002/06/26 17:29:36  harald
00071  * First pre-release with 2.4 stack
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     /*         1234567890 123 123456789012345:123456 123456789012345:123456 */
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 }

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/