diff --git a/examples/telnet_server/Makefile b/examples/telnet_server/Makefile new file mode 100644 index 0000000000000..d1d676f0a7898 --- /dev/null +++ b/examples/telnet_server/Makefile @@ -0,0 +1,47 @@ +# name of your application +APPLICATION = telnet_server + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Include packages that pull up and auto-init the link layer. +# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present +USEMODULE += gnrc_netdev_default +USEMODULE += auto_init_gnrc_netif +# Activate ICMPv6 error messages +USEMODULE += gnrc_icmpv6_error +# Specify the mandatory networking modules for IPv6 +USEMODULE += gnrc_ipv6_default +# Additional networking modules that can be dropped if not needed +USEMODULE += gnrc_icmpv6_echo +USEMODULE += netutils +# Add also the shell, some shell commands +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps +# Include the telnet server +USEMODULE += stdio_telnet + +# enable debug output via UART +ifneq (native, $(BOARD)) + FEATURES_OPTIONAL += periph_uart +endif + +# Optionally include DNS support. This includes resolution of names at an +# upstream DNS server and the handling of RDNSS options in Router Advertisements +# to auto-configure that upstream DNS server. +# USEMODULE += sock_dns # include DNS client +# USEMODULE += gnrc_ipv6_nib_dns # include RDNSS option handling + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +include $(RIOTBASE)/Makefile.include + +# Set a custom channel if needed +include $(RIOTMAKE)/default-radio-settings.inc.mk diff --git a/examples/telnet_server/main.c b/examples/telnet_server/main.c new file mode 100644 index 0000000000000..8a9258fcec0b4 --- /dev/null +++ b/examples/telnet_server/main.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Example application for demonstrating the RIOT network stack + * + * @author Hauke Petersen + * + * @} + */ + +#include + +#include "net/ipv6/addr.h" +#include "net/gnrc.h" +#include "net/gnrc/netif.h" +#include "shell.h" +#include "msg.h" + +#define MAIN_QUEUE_SIZE (8) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +static void _print_addr(void) +{ + gnrc_netif_t *netif = NULL; + while ((netif = gnrc_netif_iter(netif))) { + ipv6_addr_t ipv6_addrs[CONFIG_GNRC_NETIF_IPV6_ADDRS_NUMOF]; + int res = gnrc_netapi_get(netif->pid, NETOPT_IPV6_ADDR, 0, ipv6_addrs, + sizeof(ipv6_addrs)); + + if (res < 0) { + continue; + } + for (unsigned i = 0; i < (unsigned)(res / sizeof(ipv6_addr_t)); i++) { + char ipv6_addr[IPV6_ADDR_MAX_STR_LEN]; + + ipv6_addr_to_str(ipv6_addr, &ipv6_addrs[i], IPV6_ADDR_MAX_STR_LEN); + printf("My address is %s\n", ipv6_addr); + } + } +} + +int main(void) +{ + /* we need a message queue for the thread running the shell in order to + * receive potentially fast incoming networking packets */ + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + puts("RIOT telnet example application"); + + /* print address so we can connect to it */ + _print_addr(); + + /* start shell */ + puts("All up, awaiting connection"); + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + /* should be never reached */ + return 0; +}