Added three commands for IP interaction in the shell: ping (sends ICMP ping messages), tcpsend (sets up TCP connections for sending and receiving data), and udpsend (sends and receives UDP packets)

This commit is contained in:
adamdunkels 2009-03-06 00:29:33 +00:00
parent 3848bba210
commit ddafef15e9
8 changed files with 675 additions and 2 deletions

View File

@ -6,7 +6,7 @@ shell_src = shell.c shell-reboot.c \
shell-rime-debug.c shell-coffee.c \
shell-wget.c shell-httpd.c shell-irc.c \
shell-checkpoint.c shell-power.c \
# shell-netcat.c
shell-tcpsend.c shell-udpsend.c shell-ping.c
#shell-rsh.c
shell_dsc = shell-dsc.c

189
apps/shell/shell-ping.c Normal file
View File

@ -0,0 +1,189 @@
/*
* Copyright (c) 2004, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: shell-ping.c,v 1.1 2009/03/06 00:29:33 adamdunkels Exp $
*/
#include <string.h>
#include <stddef.h>
#include "contiki.h"
#include "shell.h"
#include "contiki-net.h"
/*---------------------------------------------------------------------------*/
PROCESS(shell_ping_process, "ping");
SHELL_COMMAND(ping_command,
"ping",
"ping <host>: ping an IP host",
&shell_ping_process);
/*---------------------------------------------------------------------------*/
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
#define PING_DATALEN 16
#define ICMP_ECHO_REPLY 0
#define ICMP_ECHO 8
#define ICMP6_ECHO_REPLY 129
#define ICMP6_ECHO 128
static uip_ipaddr_t remoteaddr;
static unsigned char running;
/*---------------------------------------------------------------------------*/
static void
send_ping(uip_ipaddr_t *dest_addr)
#if UIP_CONF_IPV6
{
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 1;
UIP_IP_BUF->flow = 0;
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
UIP_IP_BUF->ttl = uip_netif_physical_if.cur_hop_limit;
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &dest_addr);
uip_netif_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr);
UIP_ICMP_BUF->type = ICMP6_ECHO_REQUEST;
UIP_ICMP_BUF->icode = 0;
/* set identifier and sequence number to 0 */
memset((void *)UIP_ICMP_BUF + UIP_ICMPH_LEN, 0, 4);
/* put one byte of data */
memset((void *)UIP_ICMP_BUF + UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN,
count, PING_DATALEN);
uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN +
UIP_IPH_LEN + PING_DATALEN;
UIP_IP_BUF->len[0] = (u8_t)((uip_len - 40) >> 8);
UIP_IP_BUF->len[1] = (u8_t)((uip_len - 40) & 0x00ff);
UIP_ICMP_BUF->icmpchksum = 0;
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
tcpip_ipv6_output();
}
#else /* UIP_CONF_IPV6 */
{
static uint16_t ipid = 0;
static uint16_t seqno = 0;
UIP_IP_BUF->vhl = 0x45;
UIP_IP_BUF->tos = 0;
UIP_IP_BUF->ipoffset[0] = UIP_IP_BUF->ipoffset[1] = 0;
++ipid;
UIP_IP_BUF->ipid[0] = ipid >> 8;
UIP_IP_BUF->ipid[1] = ipid & 0xff;
UIP_IP_BUF->proto = UIP_PROTO_ICMP;
UIP_IP_BUF->ttl = UIP_TTL;
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, dest_addr);
uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &uip_hostaddr);
UIP_ICMP_BUF->type = ICMP_ECHO;
UIP_ICMP_BUF->icode = 0;
UIP_ICMP_BUF->id = 0xadad;
UIP_ICMP_BUF->seqno = htons(seqno++);
uip_len = UIP_ICMPH_LEN + UIP_IPH_LEN + PING_DATALEN;
UIP_IP_BUF->len[0] = (u8_t)((uip_len) >> 8);
UIP_IP_BUF->len[1] = (u8_t)((uip_len) & 0x00ff);
UIP_ICMP_BUF->icmpchksum = 0;
UIP_ICMP_BUF->icmpchksum = ~uip_chksum((u16_t *)&(UIP_ICMP_BUF->type),
UIP_ICMPH_LEN + PING_DATALEN);
/* Calculate IP checksum. */
UIP_IP_BUF->ipchksum = 0;
UIP_IP_BUF->ipchksum = ~(uip_ipchksum());
tcpip_output();
}
#endif /* UIP_CONF_IPV6 */
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_ping_process, ev, data)
{
struct shell_input *input;
PROCESS_BEGIN();
if(data == NULL) {
shell_output_str(&ping_command,
"ping <server>: server as address", "");
PROCESS_EXIT();
}
uiplib_ipaddrconv(data, (u8_t *)&remoteaddr);
send_ping(&remoteaddr);
running = 1;
while(running) {
static struct etimer e;
etimer_set(&e, CLOCK_SECOND * 10);
PROCESS_WAIT_EVENT();
if(etimer_expired(&e)) {
PROCESS_EXIT();
}
if(ev == shell_event_input) {
input = data;
if(input->len1 + input->len2 == 0) {
PROCESS_EXIT();
}
#if 0
} else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */
if((char *)data != NULL &&
resolv_lookup((char *)data) != NULL) {
uip_ipaddr_copy(serveraddr, ipaddr);
telnet_connect(&s, server, serveraddr, nick);
} else {
shell_output_str(&ping_command, "Host not found.", "");
}
#endif /* 0 */
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
shell_ping_init(void)
{
shell_register_command(&ping_command);
}
/*---------------------------------------------------------------------------*/

48
apps/shell/shell-ping.h Normal file
View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* $Id: shell-ping.h,v 1.1 2009/03/06 00:29:33 adamdunkels Exp $
*/
/**
* \file
* Header file for Contik shell command ping
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __SHELL_PING_H__
#define __SHELL_PING_H__
#include "shell.h"
void shell_ping_init(void);
#endif /* __SHELL_PING_H__ */

194
apps/shell/shell-tcpsend.c Normal file
View File

@ -0,0 +1,194 @@
/*
* Copyright (c) 2004, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: shell-tcpsend.c,v 1.1 2009/03/06 00:29:33 adamdunkels Exp $
*/
#include <string.h>
#include <stddef.h>
#include "contiki.h"
#include "shell.h"
#include "telnet.h"
#ifndef MIN
#define MIN(a, b) ((a) < (b)? (a) : (b))
#endif /* MIN */
/*---------------------------------------------------------------------------*/
PROCESS(shell_tcpsend_process, "tcpsend");
SHELL_COMMAND(tcpsend_command,
"tcpsend",
"tcpsend <host> <port>: open a TCP connection",
&shell_tcpsend_process);
/*---------------------------------------------------------------------------*/
#define MAX_SERVERLEN 16
static uip_ipaddr_t serveraddr;
static char server[MAX_SERVERLEN + 1];
static struct telnet_state s;
static unsigned char running;
#define MAX_LINELEN 80
static char outputline[MAX_LINELEN];
static uint8_t sending;
/*---------------------------------------------------------------------------*/
void
telnet_text_output(struct telnet_state *s, char *text1, char *text2)
{
char buf1[MAX_SERVERLEN];
int len;
strncpy(buf1, text1, sizeof(buf1));
len = strlen(buf1);
if(len < sizeof(buf1) - 1) {
buf1[len] = ' ';
buf1[len + 1] = 0;
}
shell_output_str(&tcpsend_command, buf1, text2);
}
/*---------------------------------------------------------------------------*/
void
telnet_newdata(struct telnet_state *s, char *data, uint16_t len)
{
shell_output(&tcpsend_command, data, len, "", 0);
}
/*---------------------------------------------------------------------------*/
static void
send_line(struct telnet_state *s, char *data, int len)
{
if(!sending) {
strncpy(outputline, data, MIN(sizeof(outputline), len));
telnet_send(s, data, len);
sending = 1;
} else {
shell_output_str(&tcpsend_command, "Cannot send data, still sending previous data", "");
}
}
/*---------------------------------------------------------------------------*/
void
telnet_sent(struct telnet_state *s)
{
sending = 0;
}
/*---------------------------------------------------------------------------*/
void
telnet_closed(struct telnet_state *s)
{
telnet_text_output(s, server, "connection closed");
running = 0;
}
/*---------------------------------------------------------------------------*/
void
telnet_aborted(struct telnet_state *s)
{
telnet_text_output(s, server, "connection aborted");
running = 0;
}
/*---------------------------------------------------------------------------*/
void
telnet_timedout(struct telnet_state *s)
{
telnet_text_output(s, server, "connection timed out");
running = 0;
}
/*---------------------------------------------------------------------------*/
void
telnet_connected(struct telnet_state *s)
{
telnet_text_output(s, server, "connected");
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_tcpsend_process, ev, data)
{
char *next;
struct shell_input *input;
uint16_t port;
PROCESS_BEGIN();
next = strchr(data, ' ');
if(next == NULL) {
shell_output_str(&tcpsend_command,
"tcpsend <server> <port>: server as address", "");
PROCESS_EXIT();
}
*next = 0;
++next;
strncpy(server, data, sizeof(server));
port = shell_strtolong(next, NULL);
running = 1;
uiplib_ipaddrconv(server, (u8_t *)&serveraddr);
telnet_connect(&s, &serveraddr, port);
while(running) {
PROCESS_WAIT_EVENT();
if(ev == shell_event_input) {
input = data;
if(input->len1 + input->len2 == 0) {
PROCESS_EXIT();
}
if(input->len1 > 0) {
send_line(&s, input->data1, input->len1);
}
} else if(ev == tcpip_event) {
telnet_app(data);
#if 0
} else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */
if((char *)data != NULL &&
resolv_lookup((char *)data) != NULL) {
uip_ipaddr_copy(serveraddr, ipaddr);
telnet_connect(&s, server, serveraddr, nick);
} else {
shell_output_str(&tcpsend_command, "Host not found.", "");
}
#endif /* 0 */
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
shell_tcpsend_init(void)
{
shell_register_command(&tcpsend_command);
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* $Id: shell-tcpsend.h,v 1.1 2009/03/06 00:29:33 adamdunkels Exp $
*/
/**
* \file
* Header file for Contik shell command tcpsend
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __SHELL_TCPSEND_H__
#define __SHELL_TCPSEND_H__
#include "shell.h"
void shell_tcpsend_init(void);
#endif /* __SHELL_TCPSEND_H__ */

View File

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: shell-text.c,v 1.2 2008/02/10 12:29:54 oliverschmidt Exp $
* $Id: shell-text.c,v 1.3 2009/03/06 00:29:33 adamdunkels Exp $
*/
/**
@ -246,6 +246,9 @@ PROCESS_THREAD(shell_binprint_process, ev, data)
ptr++;
}
/* XXX need to check if input->len1 == 1 here, and then shift this
byte into the sequence of 16-bitters below. */
ptr = (uint16_t *)input->data2;
for(i = 0; i < input->len2 && i < input->len2 - 1; i += 2) {
bufptr += sprintf(bufptr, "%u ", *ptr);

143
apps/shell/shell-udpsend.c Normal file
View File

@ -0,0 +1,143 @@
/*
* Copyright (c) 2004, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: shell-udpsend.c,v 1.1 2009/03/06 00:29:33 adamdunkels Exp $
*/
#include <string.h>
#include <stddef.h>
#include "contiki.h"
#include "shell.h"
#include "contiki-net.h"
/*---------------------------------------------------------------------------*/
PROCESS(shell_udpsend_process, "udpsend");
SHELL_COMMAND(udpsend_command,
"udpsend",
"udpsend <host> <remote port> [local port]: send UDP data",
&shell_udpsend_process);
/*---------------------------------------------------------------------------*/
#define MAX_SERVERLEN 16
static struct uip_udp_conn *udpconn;
static uip_ipaddr_t serveraddr;
static char server[MAX_SERVERLEN + 1];
static unsigned char running;
#define MAX_LINELEN 80
static char line[MAX_LINELEN];
/*---------------------------------------------------------------------------*/
static void
send_line(char *line, int len)
{
uip_udp_packet_send(udpconn, line, len);
}
/*---------------------------------------------------------------------------*/
static void
newdata(char *data, uint16_t len)
{
shell_output(&udpsend_command, data, len, "", 0);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_udpsend_process, ev, data)
{
char *next, *nextptr;
struct shell_input *input;
uint16_t port, local_port;
PROCESS_BEGIN();
next = strchr(data, ' ');
if(next == NULL) {
shell_output_str(&udpsend_command,
"udpsend <server> <port> [localport]: server as address", "");
PROCESS_EXIT();
}
*next = 0;
++next;
strncpy(server, data, sizeof(server));
port = shell_strtolong(next, &nextptr);
uiplib_ipaddrconv(server, (u8_t *)&serveraddr);
udpconn = udp_new(&serveraddr, htons(port), NULL);
if(next != nextptr) {
local_port = shell_strtolong(nextptr, &nextptr);
udp_bind(udpconn, htons(local_port));
}
running = 1;
while(running) {
PROCESS_WAIT_EVENT();
if(ev == shell_event_input) {
input = data;
if(input->len1 + input->len2 == 0) {
PROCESS_EXIT();
}
if(input->len1 > 0) {
send_line(input->data1, input->len1);
}
} else if(ev == tcpip_event) {
if(uip_newdata()) {
newdata(uip_appdata, uip_datalen());
}
#if 0
} else if(ev == resolv_event_found) {
/* Either found a hostname, or not. */
if((char *)data != NULL &&
resolv_lookup((char *)data) != NULL) {
uip_ipaddr_copy(serveraddr, ipaddr);
telnet_connect(&s, server, serveraddr, nick);
} else {
shell_output_str(&udpsend_command, "Host not found.", "");
}
#endif /* 0 */
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
shell_udpsend_init(void)
{
shell_register_command(&udpsend_command);
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* $Id: shell-udpsend.h,v 1.1 2009/03/06 00:29:33 adamdunkels Exp $
*/
/**
* \file
* Header file for Contik shell command udpsend
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __SHELL_UDPSEND_H__
#define __SHELL_UDPSEND_H__
#include "shell.h"
void shell_udpsend_init(void);
#endif /* __SHELL_UDPSEND_H__ */