You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/02/27 18:50:04 UTC
[incubator-nuttx-apps] 01/03: nshlib: cmd_nfsmount should try IPv6
then IPv4 if dual stack is enabled
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch pr107
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 11fedb6b9584862ca5e8ad912050fb9887a5e2f3
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Feb 16 21:12:21 2020 +0800
nshlib: cmd_nfsmount should try IPv6 then IPv4 if dual stack is enabled
Change-Id: I0126a97a74008a860beeff363090ee6933286d45
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
nshlib/nsh_mntcmds.c | 99 +++++++++++++++++++++++++---------------------------
1 file changed, 47 insertions(+), 52 deletions(-)
diff --git a/nshlib/nsh_mntcmds.c b/nshlib/nsh_mntcmds.c
index fa3b137..0748a8c 100644
--- a/nshlib/nsh_mntcmds.c
+++ b/nshlib/nsh_mntcmds.c
@@ -257,25 +257,8 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
FAR char *address;
FAR char *lpath;
FAR char *rpath;
- bool badarg = false;
-#ifdef CONFIG_NET_IPv6
- FAR struct sockaddr_in6 *sin;
- struct in6_addr inaddr;
-#else
- FAR struct sockaddr_in *sin;
- struct in_addr inaddr;
-#endif
int ret;
- /* If a bad argument was encountered, then return without processing the
- * command.
- */
-
- if (badarg)
- {
- return ERROR;
- }
-
/* The fist argument on the command line should be the NFS server IP address
* in standard IPv4 (or IPv6) dot format.
*/
@@ -286,54 +269,66 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ERROR;
}
- /* The local mount point path (lpath) might be relative to the current working
- * directory.
- */
-
- lpath = nsh_getfullpath(vtbl, argv[2]);
- if (!lpath)
- {
- return ERROR;
- }
-
/* Get the remote mount point path */
rpath = argv[3];
- /* Convert the IP address string into its binary form */
+ /* Place all of the NFS arguments into the nfs_args structure */
+
+ memset(&data, 0, sizeof(data));
+
+ /* Convert the IP address string into its binary form */
#ifdef CONFIG_NET_IPv6
- ret = inet_pton(AF_INET6, address, &inaddr);
-#else
- ret = inet_pton(AF_INET, address, &inaddr);
+ if (data.addrlen == 0)
+ {
+ FAR struct sockaddr_in6 *sin;
+
+ sin = (FAR struct sockaddr_in6 *)&data.addr;
+ ret = inet_pton(AF_INET6, address, &sin->sin6_addr);
+ if (ret == 1)
+ {
+ sin->sin6_family = AF_INET6;
+ sin->sin6_port = htons(NFS_PMAPPORT);
+ data.addrlen = sizeof(struct sockaddr_in6);
+ }
+ }
#endif
- if (ret != 1)
+
+#ifdef CONFIG_NET_IPv4
+ if (data.addrlen == 0)
{
- nsh_freefullpath(lpath);
- return ERROR;
+ FAR struct sockaddr_in *sin;
+
+ sin = (FAR struct sockaddr_in *)&data.addr;
+ ret = inet_pton(AF_INET, address, &sin->sin_addr);
+ if (ret == 1)
+ {
+ sin->sin_family = AF_INET;
+ sin->sin_port = htons(NFS_PMAPPORT);
+ data.addrlen = sizeof(struct sockaddr_in);
+ }
}
+#endif
- /* Place all of the NFS arguments into the nfs_args structure */
+ if (data.addrlen == 0)
+ {
+ return ERROR;
+ }
- memset(&data, 0, sizeof(data));
+ data.sotype = SOCK_DGRAM;
+ data.path = rpath;
+ data.flags = 0; /* 0=Use all defaults */
-#ifdef CONFIG_NET_IPv6
- sin = (FAR struct sockaddr_in6 *)&data.addr;
- sin->sin6_family = AF_INET6;
- sin->sin6_port = htons(NFS_PMAPPORT);
- memcpy(&sin->sin6_addr, &inaddr, sizeof(struct in6_addr));
- data.addrlen = sizeof(struct sockaddr_in6);
-#else
- sin = (FAR struct sockaddr_in *)&data.addr;
- sin->sin_family = AF_INET;
- sin->sin_port = htons(NFS_PMAPPORT);
- sin->sin_addr = inaddr;
- data.addrlen = sizeof(struct sockaddr_in);
-#endif
+ /* The local mount point path (lpath) might be relative to the current working
+ * directory.
+ */
- data.sotype = SOCK_DGRAM;
- data.path = rpath;
- data.flags = 0; /* 0=Use all defaults */
+ lpath = nsh_getfullpath(vtbl, argv[2]);
+ if (!lpath)
+ {
+ return ERROR;
+ }
/* Perform the mount */