diff --git a/apps/netutils/uiplib/uip_gethostaddr.c b/apps/netutils/uiplib/uip_gethostaddr.c index 0de639d6cc..7fe26e6b97 100644 --- a/apps/netutils/uiplib/uip_gethostaddr.c +++ b/apps/netutils/uiplib/uip_gethostaddr.c @@ -92,7 +92,6 @@ int uip_gethostaddr(const char *ifname, struct in_addr *addr) if (!ret) { #ifdef CONFIG_NET_IPv6 -#error "req.ifr_addr.s_addr not big enough for IPv6 address" memcpy(addr, &req.ifr_addr, sizeof(struct in6_addr)); #else memcpy(addr, &req.ifr_addr, sizeof(struct in_addr)); diff --git a/apps/netutils/uiplib/uip_setdraddr.c b/apps/netutils/uiplib/uip_setdraddr.c index 79eac5b972..6ab516afae 100644 --- a/apps/netutils/uiplib/uip_setdraddr.c +++ b/apps/netutils/uiplib/uip_setdraddr.c @@ -96,7 +96,6 @@ int uip_setdraddr(const char *ifname, const struct in_addr *addr) /* Add the INET address to the request */ #ifdef CONFIG_NET_IPv6 -#error "req.ifr_addr.s_addr not big enough for IPv6 address" inaddr = (struct sockaddr_in6 *)&req.ifr_addr; inaddr->sin_family = AF_INET6; inaddr->sin_port = 0; diff --git a/apps/netutils/uiplib/uip_sethostaddr.c b/apps/netutils/uiplib/uip_sethostaddr.c index ccc7526b9a..4db268783c 100644 --- a/apps/netutils/uiplib/uip_sethostaddr.c +++ b/apps/netutils/uiplib/uip_sethostaddr.c @@ -96,7 +96,6 @@ int uip_sethostaddr(const char *ifname, const struct in_addr *addr) /* Add the INET address to the request */ #ifdef CONFIG_NET_IPv6 -#error "req.ifr_addr.s_addr not big enough for IPv6 address" inaddr = (struct sockaddr_in6 *)&req.ifr_addr; inaddr->sin_family = AF_INET6; inaddr->sin_port = 0; diff --git a/apps/netutils/uiplib/uip_setnetmask.c b/apps/netutils/uiplib/uip_setnetmask.c index 2cdc384742..edce31a2a0 100644 --- a/apps/netutils/uiplib/uip_setnetmask.c +++ b/apps/netutils/uiplib/uip_setnetmask.c @@ -95,7 +95,6 @@ int uip_setnetmask(const char *ifname, const struct in_addr *addr) /* Add the INET address to the request */ #ifdef CONFIG_NET_IPv6 -#error "req.ifr_addr.s_addr not big enough for IPv6 address" inaddr = (struct sockaddr_in6 *)&req.ifr_addr; inaddr->sin_family = AF_INET6; inaddr->sin_port = 0; diff --git a/apps/nshlib/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c index 041809faa4..c67ccf3b23 100644 --- a/apps/nshlib/nsh_fscmds.c +++ b/apps/nshlib/nsh_fscmds.c @@ -1226,11 +1226,12 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) FAR char *address; FAR char *lpath; FAR char *rpath; - FAR struct sockaddr_in *sin; 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 bool tcp = false; @@ -1346,11 +1347,19 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) memset(&data, 0, sizeof(data)); +#ifdef CONFIG_NET_IPv6 + sin = (FAR struct sockaddr_in6 *)&data.addr; + sin->sin_family = AF_INET6; + sin->sin_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 data.version = NFS_ARGSVERSION; data.sotype = (tcp) ? SOCK_STREAM : SOCK_DGRAM; diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c index 577b97a499..46d52a4bf5 100644 --- a/nuttx/fs/nfs/nfs_vfsops.c +++ b/nuttx/fs/nfs/nfs_vfsops.c @@ -1182,8 +1182,10 @@ int mountnfs(struct nfs_args *argp, void **handle) nmp->nm_acregmax = NFS_MAXATTRTIMO; nmp->nm_acdirmin = NFS_MINATTRTIMO; nmp->nm_acdirmax = NFS_MAXATTRTIMO; + strncpy(nmp->nm_path, argp->path, 90); - nmp->nm_nam = argp->addr; + memcpy(&nmp->nm_nam, &argp->addr, argp->addrlen); + nfs_decode_args(nmp, argp); /* Set up the sockets and per-host congestion */ diff --git a/nuttx/include/net/if.h b/nuttx/include/net/if.h index 8212bf8bef..0733b699ca 100644 --- a/nuttx/include/net/if.h +++ b/nuttx/include/net/if.h @@ -1,4 +1,4 @@ -/**************************************************************************** +/******************************************************************************************* * include/net/if.h * * Copyright (C) 2007, 2008, 2012 Gregory Nutt. All rights reserved. @@ -31,20 +31,20 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ****************************************************************************/ + *******************************************************************************************/ #ifndef __NET_IF_H #define __NET_IF_H -/**************************************************************************** +/******************************************************************************************* * Included Files - ****************************************************************************/ + *******************************************************************************************/ #include -/**************************************************************************** +/******************************************************************************************* * Pre-Processor Definitions - ****************************************************************************/ + *******************************************************************************************/ /* Sizing parameters */ @@ -52,35 +52,82 @@ #define IF_NAMESIZE 6 /* Newer naming standard */ #define IFHWADDRLEN 6 -/**************************************************************************** +/******************************************************************************************* * Public Type Definitions - ****************************************************************************/ + *******************************************************************************************/ +/* This is the newer form if the I/F request structure that can be used with both IPv4 + * and IPv6. + */ + +struct lifreq +{ + char lifr_name[IFNAMSIZ]; /* Network device name (e.g. "eth0") */ + union + { + struct sockaddr_storage lifru_addr; /* IP Address */ + struct sockaddr_storage lifru_dstaddr; /* P-to-P Address */ + struct sockaddr_storage lifru_broadaddr; /* Broadcast address */ + struct sockaddr_storage lifru_netmask; /* Netmask */ + struct sockaddr_storage lifru_hwaddr; /* MAC address */ + int lifru_count; /* Number of devices */ + int lifru_mtu; /* MTU size */ + } lifr_ifru; +}; + +#define lifr_addr lifr_ifru.lifru_addr /* IP address */ +#define lifr_dstaddr lifr_ifru.lifru_dstaddr /* P-to-P Address */ +#define lifr_broadaddr lifr_ifru.lifru_broadaddr /* Broadcast address */ +#define lifr_netmask lifr_ifru.lifru_netmask /* Interface net mask */ +#define lifr_hwaddr lifr_ifru.lifru_hwaddr /* MAC address */ +#define lifr_mtu lifr_ifru.lifru_mtu /* MTU */ +#define lifr_count lifr_ifru.lifru_count /* Number of devices */ + +/* This is the older I/F request that should only be used with IPv4. However, since + * NuttX only supports IPv4 or 6 (not both), we can force the older structure to + * be compatible when IPv6 is enabled. + */ + +#ifndef CONFIG_NET_IPv6 struct ifreq { - char ifr_name[IFNAMSIZ]; /* Network device name (e.g. "eth0") */ + char ifr_name[IFNAMSIZ]; /* Network device name (e.g. "eth0") */ union { - struct sockaddr ifru_addr; /* IP Address */ - struct sockaddr ifru_dstaddr; /* P-to-P Address */ - struct sockaddr ifru_broadaddr; /* Broadcast address */ - struct sockaddr ifru_netmask; /* Netmask */ - struct sockaddr ifru_hwaddr; /* MAC address */ - int ifru_count; /* Number of devices */ - int ifru_mtu; /* MTU size */ + struct sockaddr ifru_addr; /* IP Address */ + struct sockaddr ifru_dstaddr; /* P-to-P Address */ + struct sockaddr ifru_broadaddr; /* Broadcast address */ + struct sockaddr ifru_netmask; /* Netmask */ + struct sockaddr ifru_hwaddr; /* MAC address */ + int ifru_count; /* Number of devices */ + int ifru_mtu; /* MTU size */ } ifr_ifru; }; -#define ifr_addr ifr_ifru.ifru_addr /* IP address */ -#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* P-to-P Address */ -#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* Broadcast address */ -#define ifr_netmask ifr_ifru.ifru_netmask /* Interface net mask */ -#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ -#define ifr_mtu ifr_ifru.ifru_mtu /* MTU */ -#define ifr_count ifr_ifru.ifru_count /* Number of devices */ +#define ifr_addr ifr_ifru.ifru_addr /* IP address */ +#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* P-to-P Address */ +#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* Broadcast address */ +#define ifr_netmask ifr_ifru.ifru_netmask /* Interface net mask */ +#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ +#define ifr_mtu ifr_ifru.ifru_mtu /* MTU */ +#define ifr_count ifr_ifru.ifru_count /* Number of devices */ + +#else /* CONFIG_NET_IPv6 */ + +#define ifreq lifreq /* Replace ifreq with lifreq */ +#define ifr_name lifr_name /* Network device name */ +#define ifr_addr lifr_ifru.lifru_addr /* IP address */ +#define ifr_dstaddr lifr_ifru.lifru_dstaddr /* P-to-P Address */ +#define ifr_broadaddr lifr_ifru.lifru_broadaddr /* Broadcast address */ +#define ifr_netmask lifr_ifru.lifru_netmask /* Interface net mask */ +#define ifr_hwaddr lifr_ifru.lifru_hwaddr /* MAC address */ +#define ifr_mtu lifr_ifru.lifru_mtu /* MTU */ +#define ifr_count lifr_ifru.lifru_count /* Number of devices */ + +#endif /* CONFIG_NET_IPv6 */ -/**************************************************************************** +/******************************************************************************************* * Public Function Prototypes - ****************************************************************************/ + *******************************************************************************************/ #endif /* __NET_IF_H */ diff --git a/nuttx/include/nuttx/fs/nfs.h b/nuttx/include/nuttx/fs/nfs.h index 7f31da5a96..fcf9c3f7ba 100644 --- a/nuttx/include/nuttx/fs/nfs.h +++ b/nuttx/include/nuttx/fs/nfs.h @@ -63,26 +63,26 @@ struct nfs_args { - uint8_t version; /* Args structure version number */ - uint8_t addrlen; /* Length of address */ - uint8_t sotype; /* Socket type */ - uint8_t proto; /* and Protocol */ - int flags; /* Flags */ - int wsize; /* Write size in bytes */ - int rsize; /* Read size in bytes */ - int readdirsize; /* readdir size in bytes */ - int timeo; /* Initial timeout in .1 secs */ - int retrans; /* Times to retry send */ -//int maxgrouplist; /* Max. size of group list */ -//int readahead; /* # of blocks to readahead */ -//int leaseterm; /* Term (sec) of lease */ -//int deadthresh; /* Retrans threshold */ - char *path; /* Server's path of the directory being mount */ - int acregmin; /* Cache attrs for reg files min time */ - int acregmax; /* Cache attrs for reg files max time */ - int acdirmin; /* Cache attrs for dirs min time */ - int acdirmax; /* Cache attrs for dirs max time */ - struct sockaddr addr; /* File server address (requires 32-bit alignment) */ + uint8_t version; /* Args structure version number */ + uint8_t addrlen; /* Length of address */ + uint8_t sotype; /* Socket type */ + uint8_t proto; /* and Protocol */ + int flags; /* Flags */ + int wsize; /* Write size in bytes */ + int rsize; /* Read size in bytes */ + int readdirsize; /* readdir size in bytes */ + int timeo; /* Initial timeout in .1 secs */ + int retrans; /* Times to retry send */ +//int maxgrouplist; /* Max. size of group list */ +//int readahead; /* # of blocks to readahead */ +//int leaseterm; /* Term (sec) of lease */ +//int deadthresh; /* Retrans threshold */ + char *path; /* Server's path of the directory being mount */ + int acregmin; /* Cache attrs for reg files min time */ + int acregmax; /* Cache attrs for reg files max time */ + int acdirmin; /* Cache attrs for dirs min time */ + int acdirmax; /* Cache attrs for dirs max time */ + struct sockaddr_storage addr; /* File server address (requires 32-bit alignment) */ }; /**************************************************************************** diff --git a/nuttx/include/nuttx/net/ioctl.h b/nuttx/include/nuttx/net/ioctl.h index 4f8a49a7d6..5bce5eaf1c 100644 --- a/nuttx/include/nuttx/net/ioctl.h +++ b/nuttx/include/nuttx/net/ioctl.h @@ -71,6 +71,20 @@ #define SIOCGIPMSFILTER _SIOC(0x000e) /* Retrieve source filter addresses */ #define SIOCSIPMSFILTER _SIOC(0x000f) /* Set source filter content */ +/* Newer interface ioctls that use the struct lifreq. Can be used for + * both IPv4 and IPv6. + */ + +#define SIOCGLIFADDR SIOCGIFADDR /* Get IP address */ +#define SIOCSLIFADDR SIOCSIFADDR /* Set IP address */ +#define SIOCGLIFDSTADDR SIOCSIFDSTADDR /* Get P-to-P address */ +#define SIOCSLIFDSTADDR SIOCSIFDSTADDR /* Set P-to-P address */ +#define SIOCGLIFBRDADDR SIOCGIFBRDADDR /* Get broadcast IP address */ +#define SIOCSLIFBRDADDR SIOCSIFBRDADDR /* Set broadcast IP address */ +#define SIOCGLIFNETMASK SIOCGIFNETMASK /* Get network mask */ +#define SIOCSLIFNETMASK SIOCSIFNETMASK /* Set network mask */ +#define SIOCGLIFMTU SIOCGIFMTU /* Get MTU size */ + /* Wireless ioctl commands **************************************************/ #define SIOCSIWCOMMIT _SIOC(0x0010) /* Commit pending changes to driver */ diff --git a/nuttx/lib/net/lib_inetntop.c b/nuttx/lib/net/lib_inetntop.c index 3c8eb936ac..dc6a2d0d79 100644 --- a/nuttx/lib/net/lib_inetntop.c +++ b/nuttx/lib/net/lib_inetntop.c @@ -109,7 +109,7 @@ FAR const char *inet_ntop(int af, FAR const void *src, FAR char *dst, socklen_t sprintf(dst, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]); return dst; #else - FAR const in6_addr *in6_addr; + FAR const struct in6_addr *in6_addr; uint16_t warray[8]; int offset; int entry; @@ -131,7 +131,7 @@ FAR const char *inet_ntop(int af, FAR const void *src, FAR char *dst, socklen_t goto errout; } - in6_addr = (FAR const in6_addr *)src; + in6_addr = (FAR const struct in6_addr *)src; entry = -1; maxentry = -1; maxcount = 0; diff --git a/nuttx/lib/net/lib_inetpton.c b/nuttx/lib/net/lib_inetpton.c index b4b97f2aed..5371cd3f21 100644 --- a/nuttx/lib/net/lib_inetpton.c +++ b/nuttx/lib/net/lib_inetpton.c @@ -273,14 +273,14 @@ int inet_pton(int af, FAR const char *src, FAR void *dst) if (!rtime) { - ip[(nsep << 1) + 0] = (uint8_t)(value >> 8)) & 0xff; - ip[(nsep << 1) + 1] = (uint8_t)(value >> 0)) & 0xff; + ip[(nsep << 1) + 0] = (uint8_t)((value >> 8) & 0xff); + ip[(nsep << 1) + 1] = (uint8_t)((value >> 0) & 0xff); nsep++; } else { - rip[(nrsep << 1) + 0] = (uint8_t)(value >> 8)) & 0xff; - rip[(nrsep << 1) + 1] = (uint8_t)(value >> 0)) & 0xff; + rip[(nrsep << 1) + 0] = (uint8_t)((value >> 8) & 0xff); + rip[(nrsep << 1) + 1] = (uint8_t)((value >> 0) & 0xff); nrsep++; } diff --git a/nuttx/net/accept.c b/nuttx/net/accept.c index 4dfe4c09da..07e3f983ef 100644 --- a/nuttx/net/accept.c +++ b/nuttx/net/accept.c @@ -108,7 +108,7 @@ static inline void accept_tcpsender(FAR struct uip_conn *conn, { addr->sin_family = AF_INET6; addr->sin_port = conn->rport; - uip_ipaddr_copy(addr->sin_addr.s_addr, conn->ripaddr); + uip_ipaddr_copy(addr->sin6_addr.s6_addr, conn->ripaddr); } } #else diff --git a/nuttx/net/getsockname.c b/nuttx/net/getsockname.c index 35551ccf30..c5cae2f3b3 100644 --- a/nuttx/net/getsockname.c +++ b/nuttx/net/getsockname.c @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -194,7 +195,6 @@ int getsockname(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen) #if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP) #ifdef CONFIG_NET_IPv6 -#error "Not big enough for IPv6 address" outaddr->sin_family = AF_INET6; memcpy(outaddr->sin6_addr.in6_u.u6_addr8, dev->d_ipaddr, 16); *addrlen = sizeof(struct sockaddr_in6); diff --git a/nuttx/net/netdev_findbyaddr.c b/nuttx/net/netdev_findbyaddr.c index 49fc17c20f..50a246f67e 100644 --- a/nuttx/net/netdev_findbyaddr.c +++ b/nuttx/net/netdev_findbyaddr.c @@ -81,6 +81,7 @@ static inline bool netdev_maskcmp(const uip_ipaddr_t *ipaddr, return (*ipaddr & *netmask) == (*raddr & *netmask); #else # warning "Not implemented for IPv6" + return false; #endif } diff --git a/nuttx/net/netdev_ioctl.c b/nuttx/net/netdev_ioctl.c index af0367c50a..f78fc958a1 100644 --- a/nuttx/net/netdev_ioctl.c +++ b/nuttx/net/netdev_ioctl.c @@ -87,7 +87,6 @@ static void ioctl_getipaddr(struct sockaddr *outaddr, uip_ipaddr_t *inaddr) { #ifdef CONFIG_NET_IPv6 -#error "Not big enough for IPv6 address" struct sockaddr_in6 *dest = (struct sockaddr_in6 *)outaddr; dest->sin_family = AF_INET6; dest->sin_port = 0; diff --git a/nuttx/net/netdev_txnotify.c b/nuttx/net/netdev_txnotify.c index d2ecae58f4..4cb705ea85 100644 --- a/nuttx/net/netdev_txnotify.c +++ b/nuttx/net/netdev_txnotify.c @@ -1,8 +1,8 @@ /**************************************************************************** * net/netdev_txnotify.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/net/recvfrom.c b/nuttx/net/recvfrom.c index 5477e29ebc..741cd4c727 100644 --- a/nuttx/net/recvfrom.c +++ b/nuttx/net/recvfrom.c @@ -429,7 +429,7 @@ static inline void recvfrom_tcpsender(struct uip_driver_s *dev, struct recvfrom_ infrom->sin_port = TCPBUF->srcport; #ifdef CONFIG_NET_IPv6 - uip_ipaddr_copy(infrom->sin_addr.s_addr, TCPBUF->srcipaddr); + uip_ipaddr_copy(infrom->sin6_addr.s6_addr, TCPBUF->srcipaddr); #else uip_ipaddr_copy(infrom->sin_addr.s_addr, uip_ip4addr_conv(TCPBUF->srcipaddr)); #endif @@ -626,7 +626,7 @@ static inline void recvfrom_udpsender(struct uip_driver_s *dev, struct recvfrom_ infrom->sin_port = UDPBUF->srcport; #ifdef CONFIG_NET_IPv6 - uip_ipaddr_copy(infrom->sin_addr.s_addr, UDPBUF->srcipaddr); + uip_ipaddr_copy(infrom->sin6_addr.s6_addr, UDPBUF->srcipaddr); #else uip_ipaddr_copy(infrom->sin_addr.s_addr, uip_ip4addr_conv(UDPBUF->srcipaddr)); #endif