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.9  2008/04/18 13:32:00  haraldkipp
00037  * Changed size parameter from u_short to int, which is easier to handle
00038  * for 32-bit targets. You need to recompile your ARM code. No impact on
00039  * AVR expected
00040  * I changed u_int to int at some places to avoid some warnings during
00041  * compilation of Nut/Net.
00042  * libs.
00043  *
00044  * Revision 1.8  2007/07/17 18:31:44  haraldkipp
00045  * Output strings must be signed characters. Fixed provided by Michael Mueller.
00046  *
00047  * Revision 1.7  2006/03/16 15:25:35  haraldkipp
00048  * Changed human readable strings from u_char to char to stop GCC 4 from
00049  * nagging about signedness.
00050  *
00051  * Revision 1.6  2005/01/13 18:48:53  haraldkipp
00052  * Compiler warnings avoided.
00053  *
00054  * Revision 1.5  2005/01/02 10:07:10  haraldkipp
00055  * Replaced platform dependant formats in debug outputs.
00056  *
00057  * Revision 1.4  2004/04/07 12:13:58  haraldkipp
00058  * Matthias Ringwald's *nix emulation added
00059  *
00060  * Revision 1.3  2004/03/19 09:05:08  jdubiec
00061  * Fixed format strings declarations for AVR.
00062  *
00063  * Revision 1.2  2004/03/16 16:48:45  haraldkipp
00064  * Added Jan Dubiec's H8/300 port.
00065  *
00066  * Revision 1.1.1.1  2003/05/09 14:41:34  haraldkipp
00067  * Initial using 3.2.1
00068  *
00069  * Revision 1.8  2003/05/06 18:16:14  harald
00070  * Separate PPP debug module added.
00071  *
00072  * Revision 1.7  2003/02/04 18:14:57  harald
00073  * Version 3 released
00074  *
00075  * Revision 1.6  2002/10/29 15:32:24  harald
00076  * PPP support
00077  *
00078  * Revision 1.5  2002/06/26 17:29:36  harald
00079  * First pre-release with 2.4 stack
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     /*         1234567890 123 123456789012345:123456 123456789012345:123456 */
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 }

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