2 * Copyright (c) 2004, Adam Dunkels.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * This file is part of the Contiki operating system.
31 * Author: Adam Dunkels <adam@sics.se>
33 * $Id: shell-netstat.c,v 1.1 2009/05/10 21:02:24 adamdunkels Exp $
42 #include "contiki-net.h"
44 static const char closed
[] = /* "CLOSED",*/
45 {0x43, 0x4c, 0x4f, 0x53, 0x45, 0x44, 0};
46 static const char syn_rcvd
[] = /* "SYN-RCVD",*/
47 {0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56,
49 static const char syn_sent
[] = /* "SYN-SENT",*/
50 {0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e,
52 static const char established
[] = /* "ESTABLISHED",*/
53 {0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49,
54 0x53, 0x48, 0x45, 0x44, 0};
55 static const char fin_wait_1
[] = /* "FIN-WAIT-1",*/
56 {0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
58 static const char fin_wait_2
[] = /* "FIN-WAIT-2",*/
59 {0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
61 static const char closing
[] = /* "CLOSING",*/
62 {0x43, 0x4c, 0x4f, 0x53, 0x49,
64 static const char time_wait
[] = /* "TIME-WAIT,"*/
65 {0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41,
67 static const char last_ack
[] = /* "LAST-ACK"*/
68 {0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43,
70 static const char none
[] = /* "NONE"*/
71 {0x4e, 0x4f, 0x4e, 0x45, 0};
72 static const char running
[] = /* "RUNNING"*/
73 {0x52, 0x55, 0x4e, 0x4e, 0x49, 0x4e, 0x47,
75 static const char called
[] = /* "CALLED"*/
76 {0x43, 0x41, 0x4c, 0x4c, 0x45, 0x44, 0};
77 static const char file_name
[] = /* "file-stats"*/
78 {0x66, 0x69, 0x6c, 0x65, 0x2d, 0x73, 0x74,
80 static const char tcp_name
[] = /* "tcp-connections"*/
81 {0x74, 0x63, 0x70, 0x2d, 0x63, 0x6f, 0x6e,
82 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e,
84 static const char proc_name
[] = /* "processes"*/
85 {0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73,
88 static const char *states
[] = {
104 /*---------------------------------------------------------------------------*/
105 PROCESS(shell_netstat_process
, "netstat");
106 SHELL_COMMAND(netstat_command
,
108 "netstat: show UDP and TCP connections",
109 &shell_netstat_process
);
110 /*---------------------------------------------------------------------------*/
111 PROCESS_THREAD(shell_netstat_process
, ev
, data
)
115 struct uip_conn
*conn
;
118 for(i
= 0; i
< UIP_CONNS
; ++i
) {
119 conn
= &uip_conns
[i
];
120 snprintf(buf
, BUFLEN
,
121 "%d, %u.%u.%u.%u:%u, %s, %u, %u, %c %c",
128 states
[conn
->tcpstateflags
& UIP_TS_MASK
],
131 (uip_outstanding(conn
))? '*':' ',
132 (uip_stopped(conn
))? '!':' ');
133 shell_output_str(&netstat_command
, "TCP ", buf
);
137 /*---------------------------------------------------------------------------*/
139 shell_netstat_init(void)
141 shell_register_command(&netstat_command
);
143 /*---------------------------------------------------------------------------*/