apps/netutils/netlib: Add new library functions to manipulate IPv6 addresses
This commit is contained in:
parent
953c0fb069
commit
5741e70eb9
@ -54,7 +54,7 @@
|
|||||||
#include <apps/netutils/netlib.h>
|
#include <apps/netutils/netlib.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Global Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -68,7 +68,7 @@
|
|||||||
* flags The interface flags returned by SIOCGIFFLAGS
|
* flags The interface flags returned by SIOCGIFFLAGS
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* 0 on sucess; -1 on failure
|
* 0 on success; -1 on failure
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* netutils/netlib/netlib_getipv4addr.c
|
* netutils/netlib/netlib_getipv4addr.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -38,7 +38,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
#if defined(CONFIG_NET_IPv4) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||||
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -57,14 +57,14 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Global Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: netlib_get_ipv4addr
|
* Name: netlib_get_ipv4addr
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Get the network driver IP address
|
* Get the network driver IPv4 address
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* ifname The name of the interface to use
|
* ifname The name of the interface to use
|
||||||
@ -75,13 +75,10 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
int netlib_get_ipv4addr(FAR const char *ifname, FAR struct in_addr *addr)
|
||||||
int netlib_get_ipv4addr(const char *ifname, struct in6_addr *addr)
|
|
||||||
#else
|
|
||||||
int netlib_get_ipv4addr(const char *ifname, struct in_addr *addr)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
int ret = ERROR;
|
int ret = ERROR;
|
||||||
|
|
||||||
if (ifname && addr)
|
if (ifname && addr)
|
||||||
{
|
{
|
||||||
int sockfd = socket(PF_INET, NETLIB_SOCK_IOCTL, 0);
|
int sockfd = socket(PF_INET, NETLIB_SOCK_IOCTL, 0);
|
||||||
@ -92,15 +89,10 @@ int netlib_get_ipv4addr(const char *ifname, struct in_addr *addr)
|
|||||||
ret = ioctl(sockfd, SIOCGIFADDR, (unsigned long)&req);
|
ret = ioctl(sockfd, SIOCGIFADDR, (unsigned long)&req);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
FAR struct sockaddr_in6 *req_addr;
|
|
||||||
req_addr = (FAR struct sockaddr_in6 *)&req.ifr_addr;
|
|
||||||
memcpy(addr, &req_addr->sin6_addr, sizeof(struct in6_addr));
|
|
||||||
#else
|
|
||||||
FAR struct sockaddr_in *req_addr;
|
FAR struct sockaddr_in *req_addr;
|
||||||
|
|
||||||
req_addr = (FAR struct sockaddr_in*)&req.ifr_addr;
|
req_addr = (FAR struct sockaddr_in*)&req.ifr_addr;
|
||||||
memcpy(addr, &req_addr->sin_addr, sizeof(struct in_addr));
|
memcpy(addr, &req_addr->sin_addr, sizeof(struct in_addr));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
@ -110,4 +102,4 @@ int netlib_get_ipv4addr(const char *ifname, struct in_addr *addr)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */
|
#endif /* CONFIG_NET_IPv4 && CONFIG_NSOCKET_DESCRIPTORS */
|
||||||
|
106
netutils/netlib/netlib_getipv6addr.c
Normal file
106
netutils/netlib/netlib_getipv6addr.c
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* netutils/netlib/netlib_getipv6addr.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#if defined(CONFIG_NET_IPv6) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <apps/netutils/netlib.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: netlib_get_ipv6addr
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the network driver IPv6 address
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* ifname The name of the interface to use
|
||||||
|
* ipaddr The location to return the IP address
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* 0 on success; -1 on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int netlib_get_ipv6addr(FAR const char *ifname, FAR struct in6_addr *addr)
|
||||||
|
{
|
||||||
|
int ret = ERROR;
|
||||||
|
|
||||||
|
if (ifname && addr)
|
||||||
|
{
|
||||||
|
int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0);
|
||||||
|
if (sockfd >= 0)
|
||||||
|
{
|
||||||
|
struct lifreq req;
|
||||||
|
|
||||||
|
strncpy(req.lifr_name, ifname, IFNAMSIZ);
|
||||||
|
ret = ioctl(sockfd, SIOCGLIFADDR, (unsigned long)&req);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
FAR struct sockaddr_in6 *req_addr;
|
||||||
|
|
||||||
|
req_addr = (FAR struct sockaddr_in6 *)&req.lifr_addr;
|
||||||
|
memcpy(addr, &req_addr->sin6_addr, sizeof(struct in6_addr));
|
||||||
|
}
|
||||||
|
|
||||||
|
close(sockfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_NET_IPv6 && CONFIG_NSOCKET_DESCRIPTORS */
|
@ -53,7 +53,7 @@
|
|||||||
#include <apps/netutils/netlib.h>
|
#include <apps/netutils/netlib.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Global Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -67,7 +67,7 @@
|
|||||||
* macaddr The location to return the MAC address
|
* macaddr The location to return the MAC address
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* 0 on sucess; -1 on failure
|
* 0 on success; -1 on failure
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Global Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -76,7 +76,7 @@
|
|||||||
* MCAST_EXCLUDE: Remove multicast address
|
* MCAST_EXCLUDE: Remove multicast address
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* 0 on sucess; Negated errno on failure
|
* 0 on success; Negated errno on failure
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* netutils/netlib/netlib_setdripv4addr.c
|
* netutils/netlib/netlib_setdripv4addr.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -38,7 +38,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
#if defined(CONFIG_NET_IPv4) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||||
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -53,59 +53,48 @@
|
|||||||
#include <apps/netutils/netlib.h>
|
#include <apps/netutils/netlib.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Global Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: netlib_set_dripv4addr
|
* Name: netlib_set_dripv4addr
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Set the default router IP address
|
* Set the default router IPv4 address
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* ifname The name of the interface to use
|
* ifname The name of the interface to use
|
||||||
* ipaddr The address to set
|
* ipaddr The address to set
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* 0 on sucess; -1 on failure
|
* 0 on success; -1 on failure
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
int netlib_set_dripv4addr(FAR const char *ifname,
|
||||||
int netlib_set_dripv4addr(const char *ifname, const struct in6_addr *addr)
|
FAR const struct in_addr *addr)
|
||||||
#else
|
|
||||||
int netlib_set_dripv4addr(const char *ifname, const struct in_addr *addr)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
int ret = ERROR;
|
int ret = ERROR;
|
||||||
|
|
||||||
if (ifname && addr)
|
if (ifname && addr)
|
||||||
{
|
{
|
||||||
int sockfd = socket(PF_INET, NETLIB_SOCK_IOCTL, 0);
|
int sockfd = socket(PF_INET, NETLIB_SOCK_IOCTL, 0);
|
||||||
if (sockfd >= 0)
|
if (sockfd >= 0)
|
||||||
{
|
{
|
||||||
|
FAR struct sockaddr_in *inaddr;
|
||||||
struct ifreq req;
|
struct ifreq req;
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
struct sockaddr_in6 *inaddr;
|
|
||||||
#else
|
|
||||||
struct sockaddr_in *inaddr;
|
|
||||||
#endif
|
|
||||||
/* Add the device name to the request */
|
/* Add the device name to the request */
|
||||||
|
|
||||||
strncpy(req.ifr_name, ifname, IFNAMSIZ);
|
strncpy(req.ifr_name, ifname, IFNAMSIZ);
|
||||||
|
|
||||||
/* Add the INET address to the request */
|
/* Add the INET address to the request */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
inaddr = (FAR struct sockaddr_in *)&req.ifr_addr;
|
||||||
inaddr = (struct sockaddr_in6 *)&req.ifr_addr;
|
|
||||||
inaddr->sin_family = AF_INET6;
|
|
||||||
inaddr->sin_port = 0;
|
|
||||||
memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr));
|
|
||||||
#else
|
|
||||||
inaddr = (struct sockaddr_in *)&req.ifr_addr;
|
|
||||||
inaddr->sin_family = AF_INET;
|
inaddr->sin_family = AF_INET;
|
||||||
inaddr->sin_port = 0;
|
inaddr->sin_port = 0;
|
||||||
memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr));
|
memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr));
|
||||||
#endif
|
|
||||||
ret = ioctl(sockfd, SIOCSIFDSTADDR, (unsigned long)&req);
|
ret = ioctl(sockfd, SIOCSIFDSTADDR, (unsigned long)&req);
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
@ -114,4 +103,4 @@ int netlib_set_dripv4addr(const char *ifname, const struct in_addr *addr)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */
|
#endif /* CONFIG_NET_IPv4 && CONFIG_NSOCKET_DESCRIPTORS */
|
||||||
|
106
netutils/netlib/netlib_setdripv6addr.c
Normal file
106
netutils/netlib/netlib_setdripv6addr.c
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* netutils/netlib/netlib_setdripv6addr.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#if defined(CONFIG_NET_IPv6) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <apps/netutils/netlib.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: netlib_set_dripv6addr
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Set the default router IP address
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* ifname The name of the interface to use
|
||||||
|
* ipaddr The address to set
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* 0 on success; -1 on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int netlib_set_dripv6addr(FAR const char *ifname,
|
||||||
|
FAR const struct in6_addr *addr)
|
||||||
|
{
|
||||||
|
int ret = ERROR;
|
||||||
|
|
||||||
|
if (ifname && addr)
|
||||||
|
{
|
||||||
|
int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0);
|
||||||
|
if (sockfd >= 0)
|
||||||
|
{
|
||||||
|
FAR struct sockaddr_in6 *inaddr;
|
||||||
|
struct lifreq req;
|
||||||
|
|
||||||
|
/* Add the device name to the request */
|
||||||
|
|
||||||
|
strncpy(req.lifr_name, ifname, IFNAMSIZ);
|
||||||
|
|
||||||
|
/* Add the INET address to the request */
|
||||||
|
|
||||||
|
inaddr = (FAR struct sockaddr_in6 *)&req.lifr_addr;
|
||||||
|
inaddr->sin_family = AF_INET6;
|
||||||
|
inaddr->sin_port = 0;
|
||||||
|
memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr));
|
||||||
|
|
||||||
|
ret = ioctl(sockfd, SIOCSLIFDSTADDR, (unsigned long)((uintptr_t)&req));
|
||||||
|
close(sockfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_NET_IPv6 && CONFIG_NSOCKET_DESCRIPTORS */
|
@ -53,7 +53,7 @@
|
|||||||
#include <apps/netutils/netlib.h>
|
#include <apps/netutils/netlib.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Global Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -66,7 +66,7 @@
|
|||||||
* ifname The name of the interface to use
|
* ifname The name of the interface to use
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* 0 on sucess; -1 on failure
|
* 0 on success; -1 on failure
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ int netlib_ifup(const char *ifname)
|
|||||||
* ifname The name of the interface to use
|
* ifname The name of the interface to use
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* 0 on sucess; -1 on failure
|
* 0 on success; -1 on failure
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* netutils/netlib/netlib_setipv4addr.c
|
* netutils/netlib/netlib_setipv4addr.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -38,7 +38,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
#if defined(CONFIG_NET_IPv4) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||||
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -53,64 +53,53 @@
|
|||||||
#include <apps/netutils/netlib.h>
|
#include <apps/netutils/netlib.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Global Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: netlib_set_ipv4addr
|
* Name: netlib_set_ipv4addr
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Set the network driver IP address
|
* Set the network driver IPv4 address
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* ifname The name of the interface to use
|
* ifname The name of the interface to use
|
||||||
* ipaddr The address to set
|
* ipaddr The address to set
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* 0 on sucess; -1 on failure
|
* 0 on success; -1 on failure
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
int netlib_set_ipv4addr(FAR const char *ifname, FAR const struct in_addr *addr)
|
||||||
int netlib_set_ipv4addr(const char *ifname, const struct in6_addr *addr)
|
|
||||||
#else
|
|
||||||
int netlib_set_ipv4addr(const char *ifname, const struct in_addr *addr)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
int ret = ERROR;
|
int ret = ERROR;
|
||||||
|
|
||||||
if (ifname && addr)
|
if (ifname && addr)
|
||||||
{
|
{
|
||||||
int sockfd = socket(PF_INET, NETLIB_SOCK_IOCTL, 0);
|
int sockfd = socket(PF_INET, NETLIB_SOCK_IOCTL, 0);
|
||||||
if (sockfd >= 0)
|
if (sockfd >= 0)
|
||||||
{
|
{
|
||||||
|
FAR struct sockaddr_in *inaddr;
|
||||||
struct ifreq req;
|
struct ifreq req;
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
struct sockaddr_in6 *inaddr;
|
|
||||||
#else
|
|
||||||
struct sockaddr_in *inaddr;
|
|
||||||
#endif
|
|
||||||
/* Add the device name to the request */
|
/* Add the device name to the request */
|
||||||
|
|
||||||
strncpy(req.ifr_name, ifname, IFNAMSIZ);
|
strncpy(req.ifr_name, ifname, IFNAMSIZ);
|
||||||
|
|
||||||
/* Add the INET address to the request */
|
/* Add the INET address to the request */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
inaddr = (FAR struct sockaddr_in *)&req.ifr_addr;
|
||||||
inaddr = (struct sockaddr_in6 *)&req.ifr_addr;
|
|
||||||
inaddr->sin_family = AF_INET6;
|
|
||||||
inaddr->sin_port = 0;
|
|
||||||
memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr));
|
|
||||||
#else
|
|
||||||
inaddr = (struct sockaddr_in *)&req.ifr_addr;
|
|
||||||
inaddr->sin_family = AF_INET;
|
inaddr->sin_family = AF_INET;
|
||||||
inaddr->sin_port = 0;
|
inaddr->sin_port = 0;
|
||||||
memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr));
|
memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr));
|
||||||
#endif
|
|
||||||
ret = ioctl(sockfd, SIOCSIFADDR, (unsigned long)&req);
|
ret = ioctl(sockfd, SIOCSIFADDR, (unsigned long)&req);
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */
|
#endif /* CONFIG_NET_IPv4 && CONFIG_NSOCKET_DESCRIPTORS */
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* netutils/netlib/netlib_setipv4netmask.c
|
* netutils/netlib/netlib_setipv4netmask.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -38,7 +38,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
#if defined(CONFIG_NET_IPv4) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||||
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -52,64 +52,54 @@
|
|||||||
#include <apps/netutils/netlib.h>
|
#include <apps/netutils/netlib.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Global Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: netlib_set_ipv4netmask
|
* Name: netlib_set_ipv4netmask
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Set the netmask
|
* Set the PIv4 netmask
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* ifname The name of the interface to use
|
* ifname The name of the interface to use
|
||||||
* ipaddr The address to set
|
* ipaddr The address to set
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* 0 on sucess; -1 on failure
|
* 0 on success; -1 on failure
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
int netlib_set_ipv4netmask(FAR const char *ifname,
|
||||||
int netlib_set_ipv4netmask(const char *ifname, const struct in6_addr *addr)
|
FAR const struct in_addr *addr)
|
||||||
#else
|
|
||||||
int netlib_set_ipv4netmask(const char *ifname, const struct in_addr *addr)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
int ret = ERROR;
|
int ret = ERROR;
|
||||||
|
|
||||||
if (ifname && addr)
|
if (ifname && addr)
|
||||||
{
|
{
|
||||||
int sockfd = socket(PF_INET, NETLIB_SOCK_IOCTL, 0);
|
int sockfd = socket(PF_INET, NETLIB_SOCK_IOCTL, 0);
|
||||||
if (sockfd >= 0)
|
if (sockfd >= 0)
|
||||||
{
|
{
|
||||||
|
FAR struct sockaddr_in *inaddr;
|
||||||
struct ifreq req;
|
struct ifreq req;
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
struct sockaddr_in6 *inaddr;
|
|
||||||
#else
|
|
||||||
struct sockaddr_in *inaddr;
|
|
||||||
#endif
|
|
||||||
/* Add the device name to the request */
|
/* Add the device name to the request */
|
||||||
|
|
||||||
strncpy(req.ifr_name, ifname, IFNAMSIZ);
|
strncpy(req.ifr_name, ifname, IFNAMSIZ);
|
||||||
|
|
||||||
/* Add the INET address to the request */
|
/* Add the INET address to the request */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
inaddr = (FAR struct sockaddr_in *)&req.ifr_addr;
|
||||||
inaddr = (struct sockaddr_in6 *)&req.ifr_addr;
|
|
||||||
inaddr->sin_family = AF_INET6;
|
|
||||||
inaddr->sin_port = 0;
|
|
||||||
memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr));
|
|
||||||
#else
|
|
||||||
inaddr = (struct sockaddr_in *)&req.ifr_addr;
|
|
||||||
inaddr->sin_family = AF_INET;
|
inaddr->sin_family = AF_INET;
|
||||||
inaddr->sin_port = 0;
|
inaddr->sin_port = 0;
|
||||||
memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr));
|
memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr));
|
||||||
#endif
|
|
||||||
ret = ioctl(sockfd, SIOCSIFNETMASK, (unsigned long)&req);
|
ret = ioctl(sockfd, SIOCSIFNETMASK, (unsigned long)&req);
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */
|
#endif /* CONFIG_NET_IPv4 && CONFIG_NSOCKET_DESCRIPTORS */
|
||||||
|
106
netutils/netlib/netlib_setipv6addr.c
Normal file
106
netutils/netlib/netlib_setipv6addr.c
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* netutils/netlib/netlib_setipv6addr.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#if defined(CONFIG_NET_IPv6) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <apps/netutils/netlib.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: netlib_set_ipv6addr
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Set the network driver IPv6 address
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* ifname The name of the interface to use
|
||||||
|
* ipaddr The address to set
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* 0 on success; -1 on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int netlib_set_ipv6addr(FAR const char *ifname,
|
||||||
|
FAR const struct in6_addr *addr)
|
||||||
|
{
|
||||||
|
int ret = ERROR;
|
||||||
|
|
||||||
|
if (ifname && addr)
|
||||||
|
{
|
||||||
|
int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0);
|
||||||
|
if (sockfd >= 0)
|
||||||
|
{
|
||||||
|
FAR struct sockaddr_in6 *inaddr;
|
||||||
|
struct lifreq req;
|
||||||
|
|
||||||
|
/* Add the device name to the request */
|
||||||
|
|
||||||
|
strncpy(req.lifr_name, ifname, IFNAMSIZ);
|
||||||
|
|
||||||
|
/* Add the INET address to the request */
|
||||||
|
|
||||||
|
inaddr = (FAR struct sockaddr_in6 *)&req.lifr_addr;
|
||||||
|
inaddr->sin_family = AF_INET6;
|
||||||
|
inaddr->sin_port = 0;
|
||||||
|
memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr));
|
||||||
|
|
||||||
|
ret = ioctl(sockfd, SIOCSLIFADDR, ((unsigned long)(uintptr_t)&req));
|
||||||
|
close(sockfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_NET_IPv6 && CONFIG_NSOCKET_DESCRIPTORS */
|
105
netutils/netlib/netlib_setipv6netmask.c
Normal file
105
netutils/netlib/netlib_setipv6netmask.c
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* netutils/netlib/netlib_setipv6netmask.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#if defined(CONFIG_NET_IPv6) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include <apps/netutils/netlib.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: netlib_set_ipv6netmask
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Set the netmask
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* ifname The name of the interface to use
|
||||||
|
* ipaddr The address to set
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* 0 on success; -1 on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int netlib_set_ipv6netmask(FAR const char *ifname,
|
||||||
|
FAR const struct in6_addr *addr)
|
||||||
|
{
|
||||||
|
int ret = ERROR;
|
||||||
|
|
||||||
|
if (ifname && addr)
|
||||||
|
{
|
||||||
|
int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0);
|
||||||
|
if (sockfd >= 0)
|
||||||
|
{
|
||||||
|
FAR struct sockaddr_in6 *inaddr;
|
||||||
|
struct lifreq req;
|
||||||
|
|
||||||
|
/* Add the device name to the request */
|
||||||
|
|
||||||
|
strncpy(req.lifr_name, ifname, IFNAMSIZ);
|
||||||
|
|
||||||
|
/* Add the INET address to the request */
|
||||||
|
|
||||||
|
inaddr = (FAR struct sockaddr_in6 *)&req.lifr_addr;
|
||||||
|
inaddr->sin_family = AF_INET6;
|
||||||
|
inaddr->sin_port = 0;
|
||||||
|
memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr));
|
||||||
|
|
||||||
|
ret = ioctl(sockfd, SIOCSLIFNETMASK, (unsigned long)((uintptr_t)&req));
|
||||||
|
close(sockfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_NET_IPv6 && CONFIG_NSOCKET_DESCRIPTORS */
|
@ -63,7 +63,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Global Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -77,7 +77,7 @@
|
|||||||
* macaddr MAC address to set, size must be IFHWADDRLEN
|
* macaddr MAC address to set, size must be IFHWADDRLEN
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* 0 on sucess; -1 on failure
|
* 0 on success; -1 on failure
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user