From 101602413fe057426c1aed2eb8c9f97e84cbf040 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 12 Dec 2008 18:01:25 +0000 Subject: Misc fixes for ZDS compile/build git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1451 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/netutils/uiplib/Make.defs | 4 +- nuttx/netutils/uiplib/uip-gethostaddr.c | 107 ------------------- nuttx/netutils/uiplib/uip-getmacaddr.c | 105 ------------------ nuttx/netutils/uiplib/uip-server.c | 182 -------------------------------- nuttx/netutils/uiplib/uip-setdraddr.c | 118 --------------------- nuttx/netutils/uiplib/uip-sethostaddr.c | 118 --------------------- nuttx/netutils/uiplib/uip-setmacaddr.c | 115 -------------------- nuttx/netutils/uiplib/uip-setnetmask.c | 118 --------------------- nuttx/netutils/uiplib/uip_gethostaddr.c | 107 +++++++++++++++++++ nuttx/netutils/uiplib/uip_getmacaddr.c | 105 ++++++++++++++++++ nuttx/netutils/uiplib/uip_server.c | 182 ++++++++++++++++++++++++++++++++ nuttx/netutils/uiplib/uip_setdraddr.c | 118 +++++++++++++++++++++ nuttx/netutils/uiplib/uip_sethostaddr.c | 118 +++++++++++++++++++++ nuttx/netutils/uiplib/uip_setmacaddr.c | 115 ++++++++++++++++++++ nuttx/netutils/uiplib/uip_setnetmask.c | 118 +++++++++++++++++++++ 15 files changed, 865 insertions(+), 865 deletions(-) delete mode 100644 nuttx/netutils/uiplib/uip-gethostaddr.c delete mode 100644 nuttx/netutils/uiplib/uip-getmacaddr.c delete mode 100644 nuttx/netutils/uiplib/uip-server.c delete mode 100644 nuttx/netutils/uiplib/uip-setdraddr.c delete mode 100644 nuttx/netutils/uiplib/uip-sethostaddr.c delete mode 100644 nuttx/netutils/uiplib/uip-setmacaddr.c delete mode 100644 nuttx/netutils/uiplib/uip-setnetmask.c create mode 100644 nuttx/netutils/uiplib/uip_gethostaddr.c create mode 100644 nuttx/netutils/uiplib/uip_getmacaddr.c create mode 100644 nuttx/netutils/uiplib/uip_server.c create mode 100644 nuttx/netutils/uiplib/uip_setdraddr.c create mode 100644 nuttx/netutils/uiplib/uip_sethostaddr.c create mode 100644 nuttx/netutils/uiplib/uip_setmacaddr.c create mode 100644 nuttx/netutils/uiplib/uip_setnetmask.c (limited to 'nuttx/netutils/uiplib') diff --git a/nuttx/netutils/uiplib/Make.defs b/nuttx/netutils/uiplib/Make.defs index 8acb0218d..f72c651fd 100644 --- a/nuttx/netutils/uiplib/Make.defs +++ b/nuttx/netutils/uiplib/Make.defs @@ -34,5 +34,5 @@ ############################################################################ UIPLIB_ASRCS = -UIPLIB_CSRCS = uiplib.c uip-setmacaddr.c uip-getmacaddr.c uip-sethostaddr.c \ - uip-gethostaddr.c uip-setdraddr.c uip-setnetmask.c uip-server.c +UIPLIB_CSRCS = uiplib.c uip_setmacaddr.c uip_getmacaddr.c uip_sethostaddr.c \ + uip_gethostaddr.c uip_setdraddr.c uip_setnetmask.c uip_server.c diff --git a/nuttx/netutils/uiplib/uip-gethostaddr.c b/nuttx/netutils/uiplib/uip-gethostaddr.c deleted file mode 100644 index d20344d8c..000000000 --- a/nuttx/netutils/uiplib/uip-gethostaddr.c +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * netutils/uiplib/uip-gethostaddr.c - * - * Copyright (C) 2007 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 - * 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 -#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 - -#include -#include -#include - -#include -#include - -#include -#include - -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: uip_gethostaddr - * - * Description: - * Get the network driver IP address - * - * Parameters: - * ifname The name of the interface to use - * ipaddr The location to return the IP address - * - * Return: - * 0 on sucess; -1 on failure - * - ****************************************************************************/ - -#ifdef CONFIG_NET_IPv6 -int uip_gethostaddr(const char *ifname, struct in6_addr *addr) -#else -int uip_gethostaddr(const char *ifname, struct in_addr *addr) -#endif -{ - int ret = ERROR; - if (ifname && addr) - { - int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); - if (sockfd >= 0) - { - struct ifreq req; - strncpy(req.ifr_name, ifname, IFNAMSIZ); - ret = ioctl(sockfd, SIOCGIFADDR, (unsigned long)&req); - 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)); -#endif - } - } - } - return ret; -} - -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip-getmacaddr.c b/nuttx/netutils/uiplib/uip-getmacaddr.c deleted file mode 100644 index c45072c86..000000000 --- a/nuttx/netutils/uiplib/uip-getmacaddr.c +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - * netutils/uiplib/uip-getmacaddr.c - * - * Copyright (C) 2007 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 - * 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 -#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 - -#include -#include -#include - -#include -#include - -#include -#include - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: uip_getmacaddr - * - * Description: - * Get the network driver IP address - * - * Parameters: - * ifname The name of the interface to use - * macaddr The location to return the MAC address - * - * Return: - * 0 on sucess; -1 on failure - * - ****************************************************************************/ - -int uip_getmacaddr(const char *ifname, uint8 *macaddr) -{ - int ret = ERROR; - if (ifname && macaddr) - { - /* Get a socket (only so that we get access to the INET subsystem) */ - - int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); - if (sockfd >= 0) - { - struct ifreq req; - memset (&req, 0, sizeof(struct ifreq)); - - /* Put the driver name into the request */ - - strncpy(req.ifr_name, ifname, IFNAMSIZ); - - /* Perform the ioctl to get the MAC address */ - - ret = ioctl(sockfd, SIOCGIFHWADDR, (unsigned long)&req); - if (!ret) - { - /* Return the MAC address */ - - memcpy(macaddr, &req.ifr_hwaddr.sa_data, IFHWADDRLEN); - } - } - } - return ret; -} - -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip-server.c b/nuttx/netutils/uiplib/uip-server.c deleted file mode 100644 index 38b5e6ae8..000000000 --- a/nuttx/netutils/uiplib/uip-server.c +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** - * netutils/uiplib/uip-server.c - * - * Copyright (C) 2007 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 - * 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 Gregory Nutt 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 -#include -#include - -#include -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: uip_server - * - * Description: - * Implement basic server logic - * - * Parameters: - * portno The port to listen on (in network byte order) - * handler The entrypoint of the task to spawn when a new connection is - * accepted. - * stacksize The stack size needed by the spawned task - * - * Return: - * Does not return unless an error occurs. - * - ****************************************************************************/ - -void uip_server(uint16 portno, pthread_startroutine_t handler, int stacksize) -{ - struct sockaddr_in myaddr; -#ifdef CONFIG_NET_HAVE_SOLINGER - struct linger ling; -#endif - pthread_t child; - pthread_attr_t attr; - socklen_t addrlen; - int listensd; - int acceptsd; -#ifdef CONFIG_NET_HAVE_REUSEADDR - int optval; -#endif - - /* Create a new TCP socket to use to listen for connections */ - - listensd = socket(PF_INET, SOCK_STREAM, 0); - if (listensd < 0) - { - dbg("socket failure: %d\n", errno); - return; - } - - /* Set socket to reuse address */ - -#ifdef CONFIG_NET_HAVE_REUSEADDR - optval = 1; - if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) - { - dbg("setsockopt SO_REUSEADDR failure: %d\n", errno); - goto errout_with_socket; - } -#endif - - /* Bind the socket to a local address */ - - myaddr.sin_family = AF_INET; - myaddr.sin_port = portno; - myaddr.sin_addr.s_addr = INADDR_ANY; - - if (bind(listensd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0) - { - dbg("bind failure: %d\n", errno); - goto errout_with_socket; - } - - /* Listen for connections on the bound TCP socket */ - - if (listen(listensd, 5) < 0) - { - dbg("listen failure %d\n", errno); - goto errout_with_socket; - } - - /* Begin accepting connections */ - - dbg("Accepting connections on port %d\n", ntohs(portno)); - for (;;) - { - addrlen = sizeof(struct sockaddr_in); - acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen); - if (acceptsd < 0) - { - dbg("accept failure: %d\n", errno); - break;; - } - dbg("Connection accepted -- spawning sd=%d\n", acceptsd); - - /* Configure to "linger" until all data is sent when the socket is closed */ - -#ifdef CONFIG_NET_HAVE_SOLINGER - ling.l_onoff = 1; - ling.l_linger = 30; /* timeout is seconds */ - if (setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)) < 0) - { - close(acceptsd); - dbg("setsockopt SO_LINGER failure: %d\n", errno); - break;; - } -#endif - - /* Create a thread to handle the connection. The socket descriptor is - * provided in as the single argument to the new thread. - */ - - (void)pthread_attr_init(&attr); - (void)pthread_attr_setstacksize(&attr, stacksize); - - if (pthread_create(&child, &attr, handler, (void*)acceptsd) != 0) - { - close(acceptsd); - dbg("create_create failed\n"); - break; - } - - /* We don't care when/how the child thread exits so detach from it now - * in order to avoid memory leaks. - */ - - (void)pthread_detach(child); - } - -errout_with_socket: - close(listensd); -} diff --git a/nuttx/netutils/uiplib/uip-setdraddr.c b/nuttx/netutils/uiplib/uip-setdraddr.c deleted file mode 100644 index 6d61f2d5d..000000000 --- a/nuttx/netutils/uiplib/uip-setdraddr.c +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** - * netutils/uiplib/uip-setdraddr.c - * - * Copyright (C) 2007 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 - * 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 -#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 - -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: uip_setdraddr - * - * Description: - * Set the default router IP address - * - * Parameters: - * ifname The name of the interface to use - * ipaddr The address to set - * - * Return: - * 0 on sucess; -1 on failure - * - ****************************************************************************/ - -#ifdef CONFIG_NET_IPv6 -int uip_setdraddr(const char *ifname, const struct in6_addr *addr) -#else -int uip_setdraddr(const char *ifname, const struct in_addr *addr) -#endif -{ - int ret = ERROR; - if (ifname && addr) - { - int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); - if (sockfd >= 0) - { - struct ifreq req; -#ifdef CONFIG_NET_IPv6 - struct sockaddr_in6 *inaddr; -#else - struct sockaddr_in *inaddr; -#endif - /* Add the device name to the request */ - - strncpy(req.ifr_name, ifname, IFNAMSIZ); - - /* 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; - memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr)); -#else - inaddr = (struct sockaddr_in *)&req.ifr_addr; - inaddr->sin_family = AF_INET; - inaddr->sin_port = 0; - memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr)); -#endif - ret = ioctl(sockfd, SIOCSIFDSTADDR, (unsigned long)&req); - close(sockfd); - } - } - return ret; -} - -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip-sethostaddr.c b/nuttx/netutils/uiplib/uip-sethostaddr.c deleted file mode 100644 index 3f3cd7a6d..000000000 --- a/nuttx/netutils/uiplib/uip-sethostaddr.c +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** - * netutils/uiplib/uip-sethostaddr.c - * - * Copyright (C) 2007 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 - * 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 -#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 - -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: uip_sethostaddr - * - * Description: - * Set the network driver IP address - * - * Parameters: - * ifname The name of the interface to use - * ipaddr The address to set - * - * Return: - * 0 on sucess; -1 on failure - * - ****************************************************************************/ - -#ifdef CONFIG_NET_IPv6 -int uip_sethostaddr(const char *ifname, const struct in6_addr *addr) -#else -int uip_sethostaddr(const char *ifname, const struct in_addr *addr) -#endif -{ - int ret = ERROR; - if (ifname && addr) - { - int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); - if (sockfd >= 0) - { - struct ifreq req; -#ifdef CONFIG_NET_IPv6 - struct sockaddr_in6 *inaddr; -#else - struct sockaddr_in *inaddr; -#endif - /* Add the device name to the request */ - - strncpy(req.ifr_name, ifname, IFNAMSIZ); - - /* 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; - memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr)); -#else - inaddr = (struct sockaddr_in *)&req.ifr_addr; - inaddr->sin_family = AF_INET; - inaddr->sin_port = 0; - memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr)); -#endif - ret = ioctl(sockfd, SIOCSIFADDR, (unsigned long)&req); - close(sockfd); - } - } - return ret; -} - -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip-setmacaddr.c b/nuttx/netutils/uiplib/uip-setmacaddr.c deleted file mode 100644 index 969238362..000000000 --- a/nuttx/netutils/uiplib/uip-setmacaddr.c +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** - * netutils/uiplib/uip-setmacaddr.c - * - * Copyright (C) 2007 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 - * 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 -#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 - -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -#ifdef CONFIG_NET_IPv6 -# define AF_INETX AF_INET6 -#else -# define AF_INETX AF_INET -#endif - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: uip_setmacaddr - * - * Description: - * Set the network driver MAC address - * - * Parameters: - * ifname The name of the interface to use - * macaddr MAC address to set, size must be IFHWADDRLEN - * - * Return: - * 0 on sucess; -1 on failure - * - ****************************************************************************/ - -int uip_setmacaddr(const char *ifname, const uint8 *macaddr) -{ - int ret = ERROR; - if (ifname && macaddr) - { - /* Get a socket (only so that we get access to the INET subsystem) */ - - int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); - if (sockfd >= 0) - { - struct ifreq req; - - /* Put the driver name into the request */ - - strncpy(req.ifr_name, ifname, IFNAMSIZ); - - /* Put the new MAC address into the request */ - - req.ifr_hwaddr.sa_family = AF_INETX; - memcpy(&req.ifr_hwaddr.sa_data, macaddr, IFHWADDRLEN); - - /* Perforom the ioctl to set the MAC address */ - - ret = ioctl(sockfd, SIOCSIFHWADDR, (unsigned long)&req); - close(sockfd); - } - } - return ret; -} - -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip-setnetmask.c b/nuttx/netutils/uiplib/uip-setnetmask.c deleted file mode 100644 index 619a5e8fa..000000000 --- a/nuttx/netutils/uiplib/uip-setnetmask.c +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** - * netutils/uiplib/uip-setnetmask.c - * - * Copyright (C) 2007 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 - * 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 -#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 - -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: uip_setnetmask - * - * Description: - * Set the netmask - * - * Parameters: - * ifname The name of the interface to use - * ipaddr The address to set - * - * Return: - * 0 on sucess; -1 on failure - * - ****************************************************************************/ - -#ifdef CONFIG_NET_IPv6 -int uip_setnetmask(const char *ifname, const struct in6_addr *addr) -#else -int uip_setnetmask(const char *ifname, const struct in_addr *addr) -#endif -{ - int ret = ERROR; - if (ifname && addr) - { - int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); - if (sockfd >= 0) - { - struct ifreq req; -#ifdef CONFIG_NET_IPv6 - struct sockaddr_in6 *inaddr; -#else - struct sockaddr_in *inaddr; -#endif - /* Add the device name to the request */ - - strncpy(req.ifr_name, ifname, IFNAMSIZ); - - /* 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; - memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr)); -#else - inaddr = (struct sockaddr_in *)&req.ifr_addr; - inaddr->sin_family = AF_INET; - inaddr->sin_port = 0; - memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr)); -#endif - ret = ioctl(sockfd, SIOCSIFNETMASK, (unsigned long)&req); - close(sockfd); - } - } - return ret; -} - -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip_gethostaddr.c b/nuttx/netutils/uiplib/uip_gethostaddr.c new file mode 100644 index 000000000..abbdc7b72 --- /dev/null +++ b/nuttx/netutils/uiplib/uip_gethostaddr.c @@ -0,0 +1,107 @@ +/**************************************************************************** + * netutils/uiplib/uip_gethostaddr.c + * + * Copyright (C) 2007, 2008 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 + * 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 +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +#include +#include +#include + +#include +#include + +#include +#include + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_gethostaddr + * + * Description: + * Get the network driver IP address + * + * Parameters: + * ifname The name of the interface to use + * ipaddr The location to return the IP address + * + * Return: + * 0 on sucess; -1 on failure + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +int uip_gethostaddr(const char *ifname, struct in6_addr *addr) +#else +int uip_gethostaddr(const char *ifname, struct in_addr *addr) +#endif +{ + int ret = ERROR; + if (ifname && addr) + { + int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + struct ifreq req; + strncpy(req.ifr_name, ifname, IFNAMSIZ); + ret = ioctl(sockfd, SIOCGIFADDR, (unsigned long)&req); + 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)); +#endif + } + } + } + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip_getmacaddr.c b/nuttx/netutils/uiplib/uip_getmacaddr.c new file mode 100644 index 000000000..d4deff15e --- /dev/null +++ b/nuttx/netutils/uiplib/uip_getmacaddr.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * netutils/uiplib/uip_getmacaddr.c + * + * Copyright (C) 2007, 2008 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 + * 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 +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +#include +#include +#include + +#include +#include + +#include +#include + +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_getmacaddr + * + * Description: + * Get the network driver IP address + * + * Parameters: + * ifname The name of the interface to use + * macaddr The location to return the MAC address + * + * Return: + * 0 on sucess; -1 on failure + * + ****************************************************************************/ + +int uip_getmacaddr(const char *ifname, uint8 *macaddr) +{ + int ret = ERROR; + if (ifname && macaddr) + { + /* Get a socket (only so that we get access to the INET subsystem) */ + + int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + struct ifreq req; + memset (&req, 0, sizeof(struct ifreq)); + + /* Put the driver name into the request */ + + strncpy(req.ifr_name, ifname, IFNAMSIZ); + + /* Perform the ioctl to get the MAC address */ + + ret = ioctl(sockfd, SIOCGIFHWADDR, (unsigned long)&req); + if (!ret) + { + /* Return the MAC address */ + + memcpy(macaddr, &req.ifr_hwaddr.sa_data, IFHWADDRLEN); + } + } + } + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip_server.c b/nuttx/netutils/uiplib/uip_server.c new file mode 100644 index 000000000..f0729a853 --- /dev/null +++ b/nuttx/netutils/uiplib/uip_server.c @@ -0,0 +1,182 @@ +/**************************************************************************** + * netutils/uiplib/uip_server.c + * + * Copyright (C) 2007, 2008 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 + * 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 Gregory Nutt 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 +#include +#include + +#include +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_server + * + * Description: + * Implement basic server logic + * + * Parameters: + * portno The port to listen on (in network byte order) + * handler The entrypoint of the task to spawn when a new connection is + * accepted. + * stacksize The stack size needed by the spawned task + * + * Return: + * Does not return unless an error occurs. + * + ****************************************************************************/ + +void uip_server(uint16 portno, pthread_startroutine_t handler, int stacksize) +{ + struct sockaddr_in myaddr; +#ifdef CONFIG_NET_HAVE_SOLINGER + struct linger ling; +#endif + pthread_t child; + pthread_attr_t attr; + socklen_t addrlen; + int listensd; + int acceptsd; +#ifdef CONFIG_NET_HAVE_REUSEADDR + int optval; +#endif + + /* Create a new TCP socket to use to listen for connections */ + + listensd = socket(PF_INET, SOCK_STREAM, 0); + if (listensd < 0) + { + dbg("socket failure: %d\n", errno); + return; + } + + /* Set socket to reuse address */ + +#ifdef CONFIG_NET_HAVE_REUSEADDR + optval = 1; + if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) + { + dbg("setsockopt SO_REUSEADDR failure: %d\n", errno); + goto errout_with_socket; + } +#endif + + /* Bind the socket to a local address */ + + myaddr.sin_family = AF_INET; + myaddr.sin_port = portno; + myaddr.sin_addr.s_addr = INADDR_ANY; + + if (bind(listensd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0) + { + dbg("bind failure: %d\n", errno); + goto errout_with_socket; + } + + /* Listen for connections on the bound TCP socket */ + + if (listen(listensd, 5) < 0) + { + dbg("listen failure %d\n", errno); + goto errout_with_socket; + } + + /* Begin accepting connections */ + + dbg("Accepting connections on port %d\n", ntohs(portno)); + for (;;) + { + addrlen = sizeof(struct sockaddr_in); + acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen); + if (acceptsd < 0) + { + dbg("accept failure: %d\n", errno); + break;; + } + dbg("Connection accepted -- spawning sd=%d\n", acceptsd); + + /* Configure to "linger" until all data is sent when the socket is closed */ + +#ifdef CONFIG_NET_HAVE_SOLINGER + ling.l_onoff = 1; + ling.l_linger = 30; /* timeout is seconds */ + if (setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)) < 0) + { + close(acceptsd); + dbg("setsockopt SO_LINGER failure: %d\n", errno); + break;; + } +#endif + + /* Create a thread to handle the connection. The socket descriptor is + * provided in as the single argument to the new thread. + */ + + (void)pthread_attr_init(&attr); + (void)pthread_attr_setstacksize(&attr, stacksize); + + if (pthread_create(&child, &attr, handler, (void*)acceptsd) != 0) + { + close(acceptsd); + dbg("create_create failed\n"); + break; + } + + /* We don't care when/how the child thread exits so detach from it now + * in order to avoid memory leaks. + */ + + (void)pthread_detach(child); + } + +errout_with_socket: + close(listensd); +} diff --git a/nuttx/netutils/uiplib/uip_setdraddr.c b/nuttx/netutils/uiplib/uip_setdraddr.c new file mode 100644 index 000000000..cfff9ebfd --- /dev/null +++ b/nuttx/netutils/uiplib/uip_setdraddr.c @@ -0,0 +1,118 @@ +/**************************************************************************** + * netutils/uiplib/uip_setdraddr.c + * + * Copyright (C) 2007, 2008 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 + * 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 +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_setdraddr + * + * Description: + * Set the default router IP address + * + * Parameters: + * ifname The name of the interface to use + * ipaddr The address to set + * + * Return: + * 0 on sucess; -1 on failure + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +int uip_setdraddr(const char *ifname, const struct in6_addr *addr) +#else +int uip_setdraddr(const char *ifname, const struct in_addr *addr) +#endif +{ + int ret = ERROR; + if (ifname && addr) + { + int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + struct ifreq req; +#ifdef CONFIG_NET_IPv6 + struct sockaddr_in6 *inaddr; +#else + struct sockaddr_in *inaddr; +#endif + /* Add the device name to the request */ + + strncpy(req.ifr_name, ifname, IFNAMSIZ); + + /* 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; + memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr)); +#else + inaddr = (struct sockaddr_in *)&req.ifr_addr; + inaddr->sin_family = AF_INET; + inaddr->sin_port = 0; + memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr)); +#endif + ret = ioctl(sockfd, SIOCSIFDSTADDR, (unsigned long)&req); + close(sockfd); + } + } + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip_sethostaddr.c b/nuttx/netutils/uiplib/uip_sethostaddr.c new file mode 100644 index 000000000..3c28ee02f --- /dev/null +++ b/nuttx/netutils/uiplib/uip_sethostaddr.c @@ -0,0 +1,118 @@ +/**************************************************************************** + * netutils/uiplib/uip_sethostaddr.c + * + * Copyright (C) 2007, 2008 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 + * 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 +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_sethostaddr + * + * Description: + * Set the network driver IP address + * + * Parameters: + * ifname The name of the interface to use + * ipaddr The address to set + * + * Return: + * 0 on sucess; -1 on failure + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +int uip_sethostaddr(const char *ifname, const struct in6_addr *addr) +#else +int uip_sethostaddr(const char *ifname, const struct in_addr *addr) +#endif +{ + int ret = ERROR; + if (ifname && addr) + { + int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + struct ifreq req; +#ifdef CONFIG_NET_IPv6 + struct sockaddr_in6 *inaddr; +#else + struct sockaddr_in *inaddr; +#endif + /* Add the device name to the request */ + + strncpy(req.ifr_name, ifname, IFNAMSIZ); + + /* 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; + memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr)); +#else + inaddr = (struct sockaddr_in *)&req.ifr_addr; + inaddr->sin_family = AF_INET; + inaddr->sin_port = 0; + memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr)); +#endif + ret = ioctl(sockfd, SIOCSIFADDR, (unsigned long)&req); + close(sockfd); + } + } + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip_setmacaddr.c b/nuttx/netutils/uiplib/uip_setmacaddr.c new file mode 100644 index 000000000..7e817cb3a --- /dev/null +++ b/nuttx/netutils/uiplib/uip_setmacaddr.c @@ -0,0 +1,115 @@ +/**************************************************************************** + * netutils/uiplib/uip_setmacaddr.c + * + * Copyright (C) 2007, 2008 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 + * 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 +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +# define AF_INETX AF_INET6 +#else +# define AF_INETX AF_INET +#endif + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_setmacaddr + * + * Description: + * Set the network driver MAC address + * + * Parameters: + * ifname The name of the interface to use + * macaddr MAC address to set, size must be IFHWADDRLEN + * + * Return: + * 0 on sucess; -1 on failure + * + ****************************************************************************/ + +int uip_setmacaddr(const char *ifname, const uint8 *macaddr) +{ + int ret = ERROR; + if (ifname && macaddr) + { + /* Get a socket (only so that we get access to the INET subsystem) */ + + int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + struct ifreq req; + + /* Put the driver name into the request */ + + strncpy(req.ifr_name, ifname, IFNAMSIZ); + + /* Put the new MAC address into the request */ + + req.ifr_hwaddr.sa_family = AF_INETX; + memcpy(&req.ifr_hwaddr.sa_data, macaddr, IFHWADDRLEN); + + /* Perforom the ioctl to set the MAC address */ + + ret = ioctl(sockfd, SIOCSIFHWADDR, (unsigned long)&req); + close(sockfd); + } + } + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/netutils/uiplib/uip_setnetmask.c b/nuttx/netutils/uiplib/uip_setnetmask.c new file mode 100644 index 000000000..4c77cf22a --- /dev/null +++ b/nuttx/netutils/uiplib/uip_setnetmask.c @@ -0,0 +1,118 @@ +/**************************************************************************** + * netutils/uiplib/uip_setnetmask.c + * + * Copyright (C) 2007, 2008 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 + * 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 +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_setnetmask + * + * Description: + * Set the netmask + * + * Parameters: + * ifname The name of the interface to use + * ipaddr The address to set + * + * Return: + * 0 on sucess; -1 on failure + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +int uip_setnetmask(const char *ifname, const struct in6_addr *addr) +#else +int uip_setnetmask(const char *ifname, const struct in_addr *addr) +#endif +{ + int ret = ERROR; + if (ifname && addr) + { + int sockfd = socket(PF_INET, UIPLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + struct ifreq req; +#ifdef CONFIG_NET_IPv6 + struct sockaddr_in6 *inaddr; +#else + struct sockaddr_in *inaddr; +#endif + /* Add the device name to the request */ + + strncpy(req.ifr_name, ifname, IFNAMSIZ); + + /* 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; + memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr)); +#else + inaddr = (struct sockaddr_in *)&req.ifr_addr; + inaddr->sin_family = AF_INET; + inaddr->sin_port = 0; + memcpy(&inaddr->sin_addr, addr, sizeof(struct in_addr)); +#endif + ret = ioctl(sockfd, SIOCSIFNETMASK, (unsigned long)&req); + close(sockfd); + } + } + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ -- cgit v1.2.3