Add an NSH nslookup command
This commit is contained in:
parent
7e43ffa602
commit
25d45d642f
@ -1349,3 +1349,5 @@
|
||||
* apps/netutils/netlib and other files: Create netlib wrapper functions
|
||||
around dns_getserver() and dns_setserver() to isolate application
|
||||
code from changes to those interfaces (2015-07-12).
|
||||
* apps/nshlib: Add an nslookup command (2015-07-13).
|
||||
|
||||
|
@ -298,6 +298,11 @@ config NSH_DISABLE_NSFMOUNT
|
||||
default n
|
||||
depends on NFS
|
||||
|
||||
config NSH_DISABLE_NSLOOKUP
|
||||
bool "Disable nslookup"
|
||||
default n
|
||||
depends on LIBC_NETDB && NETDB_DNSCLIENT
|
||||
|
||||
config NSH_DISABLE_POWEROFF
|
||||
bool "Disable poweroff"
|
||||
default n if !DEFAULT_SMALL && !BOARDCTL_RESET
|
||||
|
@ -762,6 +762,10 @@ o nfsmount <server-address> <mount-point> <remote-path>
|
||||
Mount the remote NFS server directory <remote-path> at <mount-point> on the target machine.
|
||||
<server-address> is the IP address of the remote server.
|
||||
|
||||
o nslookup <host-name>
|
||||
|
||||
Lookup and print the IP address associated with <host-name>
|
||||
|
||||
o ping [-c <count>] [-i <interval>] <ip-address>
|
||||
ping6 [-c <count>] [-i <interval>] <ip-address>
|
||||
|
||||
@ -1025,9 +1029,10 @@ Command Dependencies on Configuration Settings
|
||||
mount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE (see note 3)
|
||||
mv (((!CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_WRITABLE) || !CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && CONFIG_NFILE_DESCRIPTORS > 0) (see note 4)
|
||||
nfsmount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET && CONFIG_NFS
|
||||
poweroff CONFIG_BOARDCTL_POWEROFF
|
||||
nslookup CONFIG_LIBC_NETDB && CONFIG_NETDB_DNSCLIENT
|
||||
ping CONFIG_NET && CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING && !CONFIG_DISABLE_SIGNALS
|
||||
ping6 CONFIG_NET && CONFIG_NET_ICMPv6 && CONFIG_NET_ICMPv6_PING && !CONFIG_DISABLE_SIGNALS
|
||||
poweroff CONFIG_BOARDCTL_POWEROFF
|
||||
ps --
|
||||
put CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && MTU >= 558 (see note 1,2)
|
||||
pwd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
@ -1073,14 +1078,14 @@ also allow it to squeeze into very small memory footprints.
|
||||
CONFIG_NSH_DISABLE_MD5 CONFIG_NSH_DISABLE_MB, CONFIG_NSH_DISABLE_MKDIR,
|
||||
CONFIG_NSH_DISABLE_MKFATFS, CONFIG_NSH_DISABLE_MKFIFO, CONFIG_NSH_DISABLE_MKRD,
|
||||
CONFIG_NSH_DISABLE_MH, CONFIG_NSH_DISABLE_MOUNT, CONFIG_NSH_DISABLE_MW,
|
||||
CONFIG_NSH_DISABLE_MV, CONFIG_NSH_DISABLE_NFSMOUNT, CONFIG_NSH_DISABLE_POWEROFF,
|
||||
CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING, CONFIG_NSH_DISABLE_PING6,
|
||||
CONFIG_NSH_DISABLE_PUT, CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_REBOOT,
|
||||
CONFIG_NSH_DISABLE_RM, CONFIG_NSH_DISABLE_RMDIR, CONFIG_NSH_DISABLE_SET,
|
||||
CONFIG_NSH_DISABLE_SH, CONFIG_NSH_DISABLE_SHUTDOWN, CONFIG_NSH_DISABLE_SLEEP,
|
||||
CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT, CONFIG_NSH_DISABLE_UNSET,
|
||||
CONFIG_NSH_DISABLE_URLDECODE, CONFIG_NSH_DISABLE_URLENCODE, CONFIG_NSH_DISABLE_USLEEP,
|
||||
CONFIG_NSH_DISABLE_WGET, CONFIG_NSH_DISABLE_XD
|
||||
CONFIG_NSH_DISABLE_MV, CONFIG_NSH_DISABLE_NFSMOUNT, CONFIG_NSH_DISABLE_NSLOOKUP,
|
||||
CONFIG_NSH_DISABLE_POWEROFF, CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING,
|
||||
CONFIG_NSH_DISABLE_PING6, CONFIG_NSH_DISABLE_PUT, CONFIG_NSH_DISABLE_PWD,
|
||||
CONFIG_NSH_DISABLE_REBOOT, CONFIG_NSH_DISABLE_RM, CONFIG_NSH_DISABLE_RMDIR,
|
||||
CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH, CONFIG_NSH_DISABLE_SHUTDOWN,
|
||||
CONFIG_NSH_DISABLE_SLEEP, CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT,
|
||||
CONFIG_NSH_DISABLE_UNSET, CONFIG_NSH_DISABLE_URLDECODE, CONFIG_NSH_DISABLE_URLENCODE,
|
||||
CONFIG_NSH_DISABLE_USLEEP, CONFIG_NSH_DISABLE_WGET, CONFIG_NSH_DISABLE_XD
|
||||
|
||||
Verbose help output can be suppressed by defining CONFIG_NSH_HELP_TERSE. In that
|
||||
case, the help command is still available but will be slightly smaller.
|
||||
|
@ -988,6 +988,11 @@ void nsh_usbtrace(void);
|
||||
# endif
|
||||
#endif /* CONFIG_NET */
|
||||
|
||||
#if defined(CONFIG_LIBC_NETDB) && defined(CONFIG_NETDB_DNSCLIENT) && \
|
||||
!defined(CONFIG_NSH_DISABLE_NSLOOKUP)
|
||||
int cmd_nslookup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BOARDCTL_POWEROFF) && !defined(CONFIG_NSH_DISABLE_POWEROFF)
|
||||
int cmd_poweroff(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
#endif
|
||||
|
@ -317,6 +317,11 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LIBC_NETDB) && defined(CONFIG_NETDB_DNSCLIENT) && \
|
||||
!defined(CONFIG_NSH_DISABLE_NSLOOKUP)
|
||||
{ "nslookup", cmd_nslookup, 2, 2, "<host-name>" },
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET) && defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && !defined(CONFIG_DISABLE_SIGNALS)
|
||||
# ifndef CONFIG_NSH_DISABLE_PING
|
||||
{ "ping", cmd_ping, 2, 6, "[-c <count>] [-i <interval>] <ip-address>" },
|
||||
|
@ -38,8 +38,11 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <sys/stat.h> /* Needed for open */
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@ -54,6 +57,12 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#if defined(CONFIG_LIBC_NETDB) && defined(CONFIG_NETDB_DNSCLIENT)
|
||||
# ifndef CONFIG_NSH_DISABLE_NSLOOKUP
|
||||
# include <netdb.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <net/ethernet.h>
|
||||
#include <net/if.h>
|
||||
#include <arpa/inet.h>
|
||||
@ -1268,6 +1277,86 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_nslookup
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_LIBC_NETDB) && defined(CONFIG_NETDB_DNSCLIENT) && \
|
||||
!defined(CONFIG_NSH_DISABLE_NSLOOKUP)
|
||||
int cmd_nslookup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
FAR struct hostent *host;
|
||||
FAR const char *addrtype;
|
||||
char buffer[48];
|
||||
|
||||
/* We should be guaranteed this by the command line parser */
|
||||
|
||||
DEBUGASSERT(argc == 2);
|
||||
|
||||
/* Get the matching address + any aliases */
|
||||
|
||||
host = gethostbyname(argv[1]);
|
||||
if (!host)
|
||||
{
|
||||
/* REVISIT: gethostbyname() does not set errno, but h_errno */
|
||||
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "gethostbyname", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Convert the address to a string */
|
||||
/* Handle IPv4 addresses */
|
||||
|
||||
if (host->h_addrtype == AF_INET)
|
||||
{
|
||||
if (inet_ntop(AF_INET, host->h_addr, buffer, 48) == NULL)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "inet_ntop", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
addrtype = "IPv4";
|
||||
}
|
||||
|
||||
/* Handle IPv6 addresses */
|
||||
|
||||
else /* if (host->h_addrtype == AF_INET6) */
|
||||
{
|
||||
DEBUGASSERT(host->h_addrtype == AF_INET6);
|
||||
|
||||
if (inet_ntop(AF_INET6, host->h_addr, buffer, 48) == NULL)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "inet_ntop", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
addrtype = "IPv6";
|
||||
}
|
||||
|
||||
/* Print the host name / address mapping */
|
||||
|
||||
nsh_output(vtbl, "Host: %s %s Addr: %s\n", host->h_name, addrtype, buffer);
|
||||
|
||||
/* Print any host name aliases */
|
||||
|
||||
if (host->h_aliases != NULL && *host->h_aliases != NULL)
|
||||
{
|
||||
FAR char **alias;
|
||||
|
||||
nsh_output(vtbl, "Aliases:");
|
||||
for (alias = host->h_aliases; *alias != NULL; alias++)
|
||||
{
|
||||
nsh_output(vtbl, " %s", *alias);
|
||||
}
|
||||
|
||||
nsh_output(vtbl, "\n");
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_ping
|
||||
****************************************************************************/
|
||||
|
Loading…
x
Reference in New Issue
Block a user