diff options
author | Corey Tabaka <corey.tabaka@gmail.com> | 2013-07-17 00:38:28 -0700 |
---|---|---|
committer | Corey Tabaka <corey.tabaka@gmail.com> | 2013-07-18 02:30:41 -0700 |
commit | 13339776cdbdf35af7f0377a3739331ce0713c83 (patch) | |
tree | 40c00269a621018388d4fdd782023086aecfc54b | |
parent | f09a432ebe651a3e209b8f4cc44fa4c4caf082a3 (diff) | |
download | lk-13339776cdbdf35af7f0377a3739331ce0713c83.tar.gz |
[lib][lwip] Add simple network test command base.
-rw-r--r-- | lib/lwip/cmd.c | 70 | ||||
-rw-r--r-- | lib/lwip/rules.mk | 1 |
2 files changed, 71 insertions, 0 deletions
diff --git a/lib/lwip/cmd.c b/lib/lwip/cmd.c new file mode 100644 index 00000000..0ee5c1ec --- /dev/null +++ b/lib/lwip/cmd.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013 Corey Tabaka + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#if defined(WITH_LIB_CONSOLE) +#include <lib/console.h> + +#include <stdio.h> +#include <string.h> +#include <lwip/api.h> +#include <lwip/ip_addr.h> + +static int net_cmd(int argc, const cmd_args *argv) +{ + if (argc < 2) { + printf("%s commands:\n", argv[0].str); +usage: + printf("%s lookup <hostname>\n", argv[0].str); + goto out; + } + + if (!strcmp(argv[1].str, "lookup")) { + if (argc < 3) + goto usage; + + ip_addr_t ip_addr; + const char *hostname = argv[2].str; + err_t err; + + err = netconn_gethostbyname(hostname, &ip_addr); + if (err != ERR_OK) { + printf("Failed to resolve host: %d\n", err); + } else { + printf("%s: %u.%u.%u.%u\n", hostname, + ip4_addr1_16(&ip_addr), + ip4_addr2_16(&ip_addr), + ip4_addr3_16(&ip_addr), + ip4_addr4_16(&ip_addr)); + } + } + +out: + return 0; +} + +STATIC_COMMAND_START +{ "net", "net toolbox", &net_cmd }, +STATIC_COMMAND_END(net); + +#endif + diff --git a/lib/lwip/rules.mk b/lib/lwip/rules.mk index 400fab14..489de855 100644 --- a/lib/lwip/rules.mk +++ b/lib/lwip/rules.mk @@ -11,6 +11,7 @@ INCLUDES += \ MODULE_SRCS += \ $(LOCAL_DIR)/sys_arch.c \ + $(LOCAL_DIR)/cmd.c \ $(LOCAL_DIR)/netif.c \ $(LOCAL_DIR)/api/api_lib.c \ $(LOCAL_DIR)/api/api_msg.c \ |