2 * \addtogroup telnetd
\r
8 * An example telnet server shell
\r
9 * \author Adam Dunkels <adam@dunkels.com>
\r
13 * Copyright (c) 2003, Adam Dunkels.
\r
14 * All rights reserved.
\r
16 * Redistribution and use in source and binary forms, with or without
\r
17 * modification, are permitted provided that the following conditions
\r
19 * 1. Redistributions of source code must retain the above copyright
\r
20 * notice, this list of conditions and the following disclaimer.
\r
21 * 2. Redistributions in binary form must reproduce the above copyright
\r
22 * notice, this list of conditions and the following disclaimer in the
\r
23 * documentation and/or other materials provided with the distribution.
\r
24 * 3. The name of the author may not be used to endorse or promote
\r
25 * products derived from this software without specific prior
\r
26 * written permission.
\r
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
\r
29 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
\r
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
\r
34 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
\r
36 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
40 * This file is part of the Contiki desktop OS.
\r
42 * $Id: telnetd-shell.c,v 1.1.2.1 2003/10/06 22:56:22 adam Exp $
\r
47 #include "telnetd.h"
\r
52 void (* pfunc)(struct telnetd_state *s, char *str);
\r
55 /*-----------------------------------------------------------------------------------*/
\r
57 parse(struct telnetd_state *s, register char *str, struct ptentry *t)
\r
59 register struct ptentry *p;
\r
64 /* Loop over the parse table entries in t in order to find one that
\r
65 matches the first character in str. */
\r
66 for(p = t; p->c != 0; ++p) {
\r
68 /* Skip rest of the characters up to the first space. */
\r
69 while(*str != ' ') {
\r
73 /* Skip all spaces.*/
\r
74 while(*str == ' ') {
\r
78 /* Call parse table entry function and return. */
\r
84 /* Did not find matching entry in parse table. We just call the
\r
85 default handler supplied by the caller and return. */
\r
88 /*-----------------------------------------------------------------------------------*/
\r
90 exitt(struct telnetd_state *s, char *str)
\r
94 /*-----------------------------------------------------------------------------------*/
\r
96 inttostr(register char *str, unsigned int i)
\r
98 str[0] = '0' + i / 100;
\r
102 str[1] = '0' + (i / 10) % 10;
\r
103 if(str[1] == '0') {
\r
106 str[2] = '0' + i % 10;
\r
110 /*-----------------------------------------------------------------------------------*/
\r
112 stats(struct telnetd_state *s, char *strr)
\r
116 inttostr(str, uip_stat.ip.recv);
\r
117 telnetd_output(s, "IP packets received ", str);
\r
118 inttostr(str, uip_stat.ip.sent);
\r
119 telnetd_output(s, "IP packets sent ", str);
\r
120 inttostr(str, uip_stat.ip.drop);
\r
121 telnetd_output(s, "IP packets dropped ", str);
\r
123 inttostr(str, uip_stat.icmp.recv);
\r
124 telnetd_output(s, "ICMP packets received ", str);
\r
125 inttostr(str, uip_stat.icmp.sent);
\r
126 telnetd_output(s, "ICMP packets sent ", str);
\r
127 inttostr(str, uip_stat.icmp.drop);
\r
128 telnetd_output(s, "ICMP packets dropped ", str);
\r
130 inttostr(str, uip_stat.tcp.recv);
\r
131 telnetd_output(s, "TCP packets received ", str);
\r
132 inttostr(str, uip_stat.tcp.sent);
\r
133 telnetd_output(s, "TCP packets sent ", str);
\r
134 inttostr(str, uip_stat.tcp.drop);
\r
135 telnetd_output(s, "TCP packets dropped ", str);
\r
136 inttostr(str, uip_stat.tcp.rexmit);
\r
137 telnetd_output(s, "TCP packets retransmitted ", str);
\r
138 inttostr(str, uip_stat.tcp.synrst);
\r
139 telnetd_output(s, "TCP connection attempts ", str);
\r
141 /*-----------------------------------------------------------------------------------*/
\r
143 help(struct telnetd_state *s, char *str)
\r
145 telnetd_output(s, "Available commands:", "");
\r
146 telnetd_output(s, "stats - show uIP statistics", "");
\r
147 telnetd_output(s, "exit - exit shell", "");
\r
148 telnetd_output(s, "? - show this help", "");
\r
150 /*-----------------------------------------------------------------------------------*/
\r
152 none(struct telnetd_state *s, char *str)
\r
154 if(strlen(str) > 0) {
\r
155 telnetd_output(s, "Unknown command", "");
\r
158 /*-----------------------------------------------------------------------------------*/
\r
159 static struct ptentry configparsetab[] =
\r
164 /* Default action */
\r
166 /*-----------------------------------------------------------------------------------*/
\r
168 telnetd_connected(struct telnetd_state *s)
\r
170 telnetd_output(s, "uIP command shell", "");
\r
171 telnetd_output(s, "Type '?' for help", "");
\r
172 telnetd_prompt(s, "uIP-0.9> ");
\r
174 /*-----------------------------------------------------------------------------------*/
\r
176 telnetd_input(struct telnetd_state *s, char *cmd)
\r
178 parse(s, cmd, configparsetab);
\r
179 telnetd_prompt(s, "uIP-0.9> ");
\r
181 /*-----------------------------------------------------------------------------------*/
\r