From 7f24c737b4d75340484337f5418c08c5de8c981d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 2 Jul 2014 16:16:51 -0600 Subject: Rename files apps/netutils/netlib/uip_*.c to apps/netutils/netlib/netlib_*.c --- apps/netutils/netlib/Makefile | 34 +++--- apps/netutils/netlib/netlib_gethostaddr.c | 107 ++++++++++++++++++ apps/netutils/netlib/netlib_getifflag.c | 107 ++++++++++++++++++ apps/netutils/netlib/netlib_getmacaddr.c | 106 +++++++++++++++++ apps/netutils/netlib/netlib_ipmsfilter.c | 116 +++++++++++++++++++ apps/netutils/netlib/netlib_listenon.c | 131 +++++++++++++++++++++ apps/netutils/netlib/netlib_parsehttpurl.c | 149 ++++++++++++++++++++++++ apps/netutils/netlib/netlib_server.c | 175 +++++++++++++++++++++++++++++ apps/netutils/netlib/netlib_setdraddr.c | 116 +++++++++++++++++++ apps/netutils/netlib/netlib_sethostaddr.c | 116 +++++++++++++++++++ apps/netutils/netlib/netlib_setifflag.c | 145 ++++++++++++++++++++++++ apps/netutils/netlib/netlib_setmacaddr.c | 116 +++++++++++++++++++ apps/netutils/netlib/netlib_setnetmask.c | 115 +++++++++++++++++++ apps/netutils/netlib/uip_gethostaddr.c | 107 ------------------ apps/netutils/netlib/uip_getifflag.c | 107 ------------------ apps/netutils/netlib/uip_getmacaddr.c | 106 ----------------- apps/netutils/netlib/uip_ipmsfilter.c | 116 ------------------- apps/netutils/netlib/uip_listenon.c | 131 --------------------- apps/netutils/netlib/uip_parsehttpurl.c | 149 ------------------------ apps/netutils/netlib/uip_server.c | 175 ----------------------------- apps/netutils/netlib/uip_setdraddr.c | 116 ------------------- apps/netutils/netlib/uip_sethostaddr.c | 116 ------------------- apps/netutils/netlib/uip_setifflag.c | 145 ------------------------ apps/netutils/netlib/uip_setmacaddr.c | 116 ------------------- apps/netutils/netlib/uip_setnetmask.c | 115 ------------------- 25 files changed, 1516 insertions(+), 1516 deletions(-) create mode 100644 apps/netutils/netlib/netlib_gethostaddr.c create mode 100644 apps/netutils/netlib/netlib_getifflag.c create mode 100644 apps/netutils/netlib/netlib_getmacaddr.c create mode 100644 apps/netutils/netlib/netlib_ipmsfilter.c create mode 100644 apps/netutils/netlib/netlib_listenon.c create mode 100644 apps/netutils/netlib/netlib_parsehttpurl.c create mode 100644 apps/netutils/netlib/netlib_server.c create mode 100644 apps/netutils/netlib/netlib_setdraddr.c create mode 100644 apps/netutils/netlib/netlib_sethostaddr.c create mode 100644 apps/netutils/netlib/netlib_setifflag.c create mode 100644 apps/netutils/netlib/netlib_setmacaddr.c create mode 100644 apps/netutils/netlib/netlib_setnetmask.c delete mode 100644 apps/netutils/netlib/uip_gethostaddr.c delete mode 100644 apps/netutils/netlib/uip_getifflag.c delete mode 100644 apps/netutils/netlib/uip_getmacaddr.c delete mode 100644 apps/netutils/netlib/uip_ipmsfilter.c delete mode 100644 apps/netutils/netlib/uip_listenon.c delete mode 100644 apps/netutils/netlib/uip_parsehttpurl.c delete mode 100644 apps/netutils/netlib/uip_server.c delete mode 100644 apps/netutils/netlib/uip_setdraddr.c delete mode 100644 apps/netutils/netlib/uip_sethostaddr.c delete mode 100644 apps/netutils/netlib/uip_setifflag.c delete mode 100644 apps/netutils/netlib/uip_setmacaddr.c delete mode 100644 apps/netutils/netlib/uip_setnetmask.c (limited to 'apps/netutils/netlib') diff --git a/apps/netutils/netlib/Makefile b/apps/netutils/netlib/Makefile index 01157c1dd..b42607134 100644 --- a/apps/netutils/netlib/Makefile +++ b/apps/netutils/netlib/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/netutils/netlib/Makefile # -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012, 2014 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -39,50 +39,50 @@ include $(APPDIR)/Make.defs # UIP Library -ASRCS = -CSRCS = netlib.c uip_sethostaddr.c uip_gethostaddr.c uip_setdraddr.c \ - uip_setnetmask.c uip_parsehttpurl.c uip_setifflag.c \ - uip_getifflag.c +ASRCS = +CSRCS = netlib.c netlib_sethostaddr.c netlib_gethostaddr.c +CSRCS += netlib_setdraddr.c netlib_setnetmask.c netlib_parsehttpurl.c +CSRCS += netlib_setifflag.c netlib_getifflag.c # These require TCP support ifeq ($(CONFIG_NET_TCP),y) -CSRCS += uip_server.c uip_listenon.c +CSRCS += netlib_server.c netlib_listenon.c endif # No MAC address support for SLIP (Ethernet only) ifneq ($(CONFIG_NET_SLIP),y) -CSRCS += uip_setmacaddr.c uip_getmacaddr.c +CSRCS += netlib_setmacaddr.c netlib_getmacaddr.c endif # IGMP support ifeq ($(CONFIG_NET_IGMP),y) -CSRCS += uip_ipmsfilter.c +CSRCS += netlib_ipmsfilter.c endif -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) + BIN = ..\..\libapps$(LIBEXT) else ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) + BIN = ..\\..\\libapps$(LIBEXT) else - BIN = ../../libapps$(LIBEXT) + BIN = ../../libapps$(LIBEXT) endif endif -ROOTDEPPATH = --dep-path . +ROOTDEPPATH = --dep-path . # Common build -VPATH = +VPATH = all: .built .PHONY: context depend clean distclean diff --git a/apps/netutils/netlib/netlib_gethostaddr.c b/apps/netutils/netlib/netlib_gethostaddr.c new file mode 100644 index 000000000..e354ca9de --- /dev/null +++ b/apps/netutils/netlib/netlib_gethostaddr.c @@ -0,0 +1,107 @@ +/**************************************************************************** + * netutils/netlib/uip_gethostaddr.c + * + * Copyright (C) 2007-2009, 2011 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 + +/**************************************************************************** + * Pre-processor 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, NETLIB_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 + memcpy(addr, &req.ifr_addr, sizeof(struct in6_addr)); +#else + memcpy(addr, &req.ifr_addr, sizeof(struct in_addr)); +#endif + } + close(sockfd); + } + } + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/apps/netutils/netlib/netlib_getifflag.c b/apps/netutils/netlib/netlib_getifflag.c new file mode 100644 index 000000000..8e82afe03 --- /dev/null +++ b/apps/netutils/netlib/netlib_getifflag.c @@ -0,0 +1,107 @@ +/**************************************************************************** + * netutils/netlib/uip_getifflag.c + * + * Copyright (C) 2007-2009, 2011, 2014 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 + +#include + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_getifstatus + * + * Description: + * Get the network driver ifup/ifdown status + * + * Parameters: + * ifname The name of the interface to use + * flags The interface flags returned by SIOCGIFFLAGS + * + * Return: + * 0 on sucess; -1 on failure + * + ****************************************************************************/ + +int uip_getifstatus(FAR const char *ifname, FAR uint8_t *flags) +{ + int ret = ERROR; + if (ifname) + { + /* Get a socket (only so that we get access to the INET subsystem) */ + + int sockfd = socket(PF_INET, NETLIB_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 ifup or ifdown status */ + + ret = ioctl(sockfd, SIOCGIFFLAGS, (unsigned long)&req); + if (!ret) + { + *flags = req.ifr_flags; + } + + close(sockfd); + } + } + + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/apps/netutils/netlib/netlib_getmacaddr.c b/apps/netutils/netlib/netlib_getmacaddr.c new file mode 100644 index 000000000..8923f4bb1 --- /dev/null +++ b/apps/netutils/netlib/netlib_getmacaddr.c @@ -0,0 +1,106 @@ +/**************************************************************************** + * netutils/netlib/uip_getmacaddr.c + * + * Copyright (C) 2007-2009, 2011 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_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_t *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, NETLIB_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); + } + close(sockfd); + } + } + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/apps/netutils/netlib/netlib_ipmsfilter.c b/apps/netutils/netlib/netlib_ipmsfilter.c new file mode 100644 index 000000000..1068d0804 --- /dev/null +++ b/apps/netutils/netlib/netlib_ipmsfilter.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * netutils/netlib/uip_setmultiaddr.c + * + * Copyright (C) 2010-2011 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 + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#ifdef CONFIG_NET_IGMP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ipmsfilter + * + * Description: + * Add or remove an IP address from a multicast filter set. + * + * Parameters: + * ifname The name of the interface to use, size must less than IMSFNAMSIZ + * multiaddr Multicast group address to add/remove (network byte order) + * fmode MCAST_INCLUDE: Add multicast address + * MCAST_EXCLUDE: Remove multicast address + * + * Return: + * 0 on sucess; Negated errno on failure + * + ****************************************************************************/ + +int ipmsfilter(FAR const char *ifname, FAR const struct in_addr *multiaddr, + uint32_t fmode) +{ + int ret = ERROR; + + nvdbg("ifname: %s muliaddr: %08x fmode: %ld\n", ifname, *multiaddr, fmode); + if (ifname && multiaddr) + { + /* Get a socket (only so that we get access to the INET subsystem) */ + + int sockfd = socket(PF_INET, NETLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + struct ip_msfilter imsf; + + /* Put the driver name into the request */ + + strncpy(imsf.imsf_name, ifname, IMSFNAMSIZ); + + /* Put the new address into the request */ + + imsf.imsf_multiaddr.s_addr = multiaddr->s_addr; + + /* Perforom the ioctl to set the MAC address */ + + imsf.imsf_fmode = fmode; + ret = ioctl(sockfd, SIOCSIPMSFILTER, (unsigned long)&imsf); + close(sockfd); + } + } + return ret; +} + +#endif /* CONFIG_NET_IGM */ diff --git a/apps/netutils/netlib/netlib_listenon.c b/apps/netutils/netlib/netlib_listenon.c new file mode 100644 index 000000000..cacea174b --- /dev/null +++ b/apps/netutils/netlib/netlib_listenon.c @@ -0,0 +1,131 @@ +/**************************************************************************** + * netutils/netlib/uip_listenon.c + * + * Copyright (C) 2007-2009, 2011 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 + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: uip_listenon + * + * Description: + * Implement basic server listening + * + * Parameters: + * portno The port to listen on (in network byte order) + * + * Return: + * A valid listening socket or -1 on error. + * + ****************************************************************************/ + +int uip_listenon(uint16_t portno) +{ + struct sockaddr_in myaddr; + int listensd; +#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) + { + ndbg("socket failure: %d\n", errno); + return ERROR; + } + + /* Set socket to reuse address */ + +#ifdef CONFIG_NET_HAVE_REUSEADDR + optval = 1; + if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) + { + ndbg("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) + { + ndbg("bind failure: %d\n", errno); + goto errout_with_socket; + } + + /* Listen for connections on the bound TCP socket */ + + if (listen(listensd, 5) < 0) + { + ndbg("listen failure %d\n", errno); + goto errout_with_socket; + } + + /* Begin accepting connections */ + + nvdbg("Accepting connections on port %d\n", ntohs(portno)); + return listensd; + +errout_with_socket: + close(listensd); + return ERROR; +} diff --git a/apps/netutils/netlib/netlib_parsehttpurl.c b/apps/netutils/netlib/netlib_parsehttpurl.c new file mode 100644 index 000000000..efc88956a --- /dev/null +++ b/apps/netutils/netlib/netlib_parsehttpurl.c @@ -0,0 +1,149 @@ +/**************************************************************************** + * netutils/netlib/uip_parsehttpurl.c + * + * Copyright (C) 2009, 2011 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 + +#include +#include +#include + +#include + +/**************************************************************************** + * Private Data + *****************************************************************************/ + +const char g_http[] = "http://"; +#define HTTPLEN 7 + +/**************************************************************************** + * Public Functions + *****************************************************************************/ + +/**************************************************************************** + * Name: uip_parsehttpurl + ****************************************************************************/ + +int uip_parsehttpurl(const char *url, uint16_t *port, + char *hostname, int hostlen, + char *filename, int namelen) +{ + const char *src = url; + char *dest; + int bytesleft; + int ret = OK; + + /* A valid HTTP URL must begin with http:// if it does not, we will assume + * that it is a file name only, but still return an error. wget() depends + * on this strange behavior. + */ + + if (strncmp(src, g_http, HTTPLEN) != 0) + { + ret = -EINVAL; + } + else + { + /* Skip over the http:// */ + + src += HTTPLEN; + + /* Concatenate the hostname following http:// and up to the termnator */ + + dest = hostname; + bytesleft = hostlen; + while (*src != '\0' && *src != '/' && *src != ' ' && *src != ':') + { + /* Make sure that there is space for another character in the hostname. + * (reserving space for the null terminator) + */ + + if (bytesleft > 1) + { + *dest++ = *src++; + bytesleft--; + } + else + { + ret = -E2BIG; + } + } + *dest = '\0'; + + /* Check if the hostname is following by a port number */ + + if (*src == ':') + { + uint16_t accum = 0; + src++; /* Skip over the colon */ + + while (*src >= '0' && *src <= '9') + { + accum = 10*accum + *src - '0'; + src++; + } + *port = accum; + } + } + + /* The rest of the line is the file name */ + + if (*src == '\0' || *src == ' ') + { + ret = -ENOENT; + } + + /* Make sure the file name starts with exactly one '/' */ + + dest = filename; + bytesleft = namelen; + while (*src == '/') + { + src++; + } + *dest++ = '/'; + bytesleft--; + + /* The copy the rest of the file name to the user buffer */ + + strncpy(dest, src, namelen); + filename[namelen-1] = '\0'; + return ret; +} + diff --git a/apps/netutils/netlib/netlib_server.c b/apps/netutils/netlib/netlib_server.c new file mode 100644 index 000000000..c6b3d1631 --- /dev/null +++ b/apps/netutils/netlib/netlib_server.c @@ -0,0 +1,175 @@ +/**************************************************************************** + * netutils/netlib/uip_server.c + * + * Copyright (C) 2007-2009, 2011 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 + +#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_t 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; + int ret; + + /* Create a new TCP socket to use to listen for connections */ + + listensd = uip_listenon(portno); + if (listensd < 0) + { + return; + } + + /* Begin serving connections */ + + for (;;) + { + /* Accept the next connectin */ + + addrlen = sizeof(struct sockaddr_in); + acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen); + if (acceptsd < 0) + { + ndbg("accept failure: %d\n", errno); + break; + } + + nvdbg("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 */ + + ret = setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)); + if (ret < 0) + { + close(acceptsd); + ndbg("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); + + ret = pthread_create(&child, &attr, handler, (void*)acceptsd); + if (ret != 0) + { + /* Close the connection */ + + close(acceptsd); + ndbg("pthread_create failed\n"); + + if (ret == EAGAIN) + { + /* Lacked resources to create a new thread. This is a temporary + * condition, so we close this peer, but keep serving for + * other connections. + */ + + continue; + } + + /* Something is very wrong... Break out and stop serving */ + + 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); + } + + /* Close the listerner socket */ + + close(listensd); +} diff --git a/apps/netutils/netlib/netlib_setdraddr.c b/apps/netutils/netlib/netlib_setdraddr.c new file mode 100644 index 000000000..bdc19d624 --- /dev/null +++ b/apps/netutils/netlib/netlib_setdraddr.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * netutils/netlib/uip_setdraddr.c + * + * Copyright (C) 2007-2009, 2011 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_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, NETLIB_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 + 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/apps/netutils/netlib/netlib_sethostaddr.c b/apps/netutils/netlib/netlib_sethostaddr.c new file mode 100644 index 000000000..ada4431f5 --- /dev/null +++ b/apps/netutils/netlib/netlib_sethostaddr.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * netutils/netlib/uip_sethostaddr.c + * + * Copyright (C) 2007-2009, 2011 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_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, NETLIB_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 + 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/apps/netutils/netlib/netlib_setifflag.c b/apps/netutils/netlib/netlib_setifflag.c new file mode 100644 index 000000000..c7a6dfb73 --- /dev/null +++ b/apps/netutils/netlib/netlib_setifflag.c @@ -0,0 +1,145 @@ +/**************************************************************************** + * netutils/netlib/uip_setifflag.c + * + * Copyright (C) 2007-2009, 2011, 2014 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_ifup + * + * Description: + * Set the network interface UP + * + * Parameters: + * ifname The name of the interface to use + * + * Return: + * 0 on sucess; -1 on failure + * + ****************************************************************************/ + +int uip_ifup(const char *ifname) +{ + int ret = ERROR; + if (ifname) + { + /* Get a socket (only so that we get access to the INET subsystem) */ + + int sockfd = socket(PF_INET, NETLIB_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 ifup flag */ + + req.ifr_flags |= IFF_UP; + + ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&req); + close(sockfd); + } + } + + return ret; +} + +/**************************************************************************** + * Name: uip_ifdown + * + * Description: + * Set the network interface DOWN + * + * Parameters: + * ifname The name of the interface to use + * + * Return: + * 0 on sucess; -1 on failure + * + ****************************************************************************/ + +int uip_ifdown(const char *ifname) +{ + int ret = ERROR; + if (ifname) + { + /* Get a socket (only so that we get access to the INET subsystem) */ + + int sockfd = socket(PF_INET, NETLIB_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 ifup flag */ + + req.ifr_flags |= IFF_DOWN; + + ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&req); + close(sockfd); + } + } + + return ret; +} + +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/apps/netutils/netlib/netlib_setmacaddr.c b/apps/netutils/netlib/netlib_setmacaddr.c new file mode 100644 index 000000000..d35034a69 --- /dev/null +++ b/apps/netutils/netlib/netlib_setmacaddr.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * netutils/netlib/uip_setmacaddr.c + * + * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * 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 + +/**************************************************************************** + * Pre-processor 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_t *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, NETLIB_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); + + /* Perform 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/apps/netutils/netlib/netlib_setnetmask.c b/apps/netutils/netlib/netlib_setnetmask.c new file mode 100644 index 000000000..8b3f9651c --- /dev/null +++ b/apps/netutils/netlib/netlib_setnetmask.c @@ -0,0 +1,115 @@ +/**************************************************************************** + * netutils/netlib/uip_setnetmask.c + * + * Copyright (C) 2007-2009, 2011 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_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, NETLIB_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 + 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/apps/netutils/netlib/uip_gethostaddr.c b/apps/netutils/netlib/uip_gethostaddr.c deleted file mode 100644 index e354ca9de..000000000 --- a/apps/netutils/netlib/uip_gethostaddr.c +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_gethostaddr.c - * - * Copyright (C) 2007-2009, 2011 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 - -/**************************************************************************** - * Pre-processor 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, NETLIB_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 - memcpy(addr, &req.ifr_addr, sizeof(struct in6_addr)); -#else - memcpy(addr, &req.ifr_addr, sizeof(struct in_addr)); -#endif - } - close(sockfd); - } - } - return ret; -} - -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/apps/netutils/netlib/uip_getifflag.c b/apps/netutils/netlib/uip_getifflag.c deleted file mode 100644 index 8e82afe03..000000000 --- a/apps/netutils/netlib/uip_getifflag.c +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_getifflag.c - * - * Copyright (C) 2007-2009, 2011, 2014 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 - -#include - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: uip_getifstatus - * - * Description: - * Get the network driver ifup/ifdown status - * - * Parameters: - * ifname The name of the interface to use - * flags The interface flags returned by SIOCGIFFLAGS - * - * Return: - * 0 on sucess; -1 on failure - * - ****************************************************************************/ - -int uip_getifstatus(FAR const char *ifname, FAR uint8_t *flags) -{ - int ret = ERROR; - if (ifname) - { - /* Get a socket (only so that we get access to the INET subsystem) */ - - int sockfd = socket(PF_INET, NETLIB_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 ifup or ifdown status */ - - ret = ioctl(sockfd, SIOCGIFFLAGS, (unsigned long)&req); - if (!ret) - { - *flags = req.ifr_flags; - } - - close(sockfd); - } - } - - return ret; -} - -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/apps/netutils/netlib/uip_getmacaddr.c b/apps/netutils/netlib/uip_getmacaddr.c deleted file mode 100644 index 8923f4bb1..000000000 --- a/apps/netutils/netlib/uip_getmacaddr.c +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_getmacaddr.c - * - * Copyright (C) 2007-2009, 2011 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_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_t *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, NETLIB_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); - } - close(sockfd); - } - } - return ret; -} - -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/apps/netutils/netlib/uip_ipmsfilter.c b/apps/netutils/netlib/uip_ipmsfilter.c deleted file mode 100644 index 1068d0804..000000000 --- a/apps/netutils/netlib/uip_ipmsfilter.c +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_setmultiaddr.c - * - * Copyright (C) 2010-2011 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 - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#ifdef CONFIG_NET_IGMP - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Global Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ipmsfilter - * - * Description: - * Add or remove an IP address from a multicast filter set. - * - * Parameters: - * ifname The name of the interface to use, size must less than IMSFNAMSIZ - * multiaddr Multicast group address to add/remove (network byte order) - * fmode MCAST_INCLUDE: Add multicast address - * MCAST_EXCLUDE: Remove multicast address - * - * Return: - * 0 on sucess; Negated errno on failure - * - ****************************************************************************/ - -int ipmsfilter(FAR const char *ifname, FAR const struct in_addr *multiaddr, - uint32_t fmode) -{ - int ret = ERROR; - - nvdbg("ifname: %s muliaddr: %08x fmode: %ld\n", ifname, *multiaddr, fmode); - if (ifname && multiaddr) - { - /* Get a socket (only so that we get access to the INET subsystem) */ - - int sockfd = socket(PF_INET, NETLIB_SOCK_IOCTL, 0); - if (sockfd >= 0) - { - struct ip_msfilter imsf; - - /* Put the driver name into the request */ - - strncpy(imsf.imsf_name, ifname, IMSFNAMSIZ); - - /* Put the new address into the request */ - - imsf.imsf_multiaddr.s_addr = multiaddr->s_addr; - - /* Perforom the ioctl to set the MAC address */ - - imsf.imsf_fmode = fmode; - ret = ioctl(sockfd, SIOCSIPMSFILTER, (unsigned long)&imsf); - close(sockfd); - } - } - return ret; -} - -#endif /* CONFIG_NET_IGM */ diff --git a/apps/netutils/netlib/uip_listenon.c b/apps/netutils/netlib/uip_listenon.c deleted file mode 100644 index cacea174b..000000000 --- a/apps/netutils/netlib/uip_listenon.c +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_listenon.c - * - * Copyright (C) 2007-2009, 2011 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 - -#include - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: uip_listenon - * - * Description: - * Implement basic server listening - * - * Parameters: - * portno The port to listen on (in network byte order) - * - * Return: - * A valid listening socket or -1 on error. - * - ****************************************************************************/ - -int uip_listenon(uint16_t portno) -{ - struct sockaddr_in myaddr; - int listensd; -#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) - { - ndbg("socket failure: %d\n", errno); - return ERROR; - } - - /* Set socket to reuse address */ - -#ifdef CONFIG_NET_HAVE_REUSEADDR - optval = 1; - if (setsockopt(listensd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(int)) < 0) - { - ndbg("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) - { - ndbg("bind failure: %d\n", errno); - goto errout_with_socket; - } - - /* Listen for connections on the bound TCP socket */ - - if (listen(listensd, 5) < 0) - { - ndbg("listen failure %d\n", errno); - goto errout_with_socket; - } - - /* Begin accepting connections */ - - nvdbg("Accepting connections on port %d\n", ntohs(portno)); - return listensd; - -errout_with_socket: - close(listensd); - return ERROR; -} diff --git a/apps/netutils/netlib/uip_parsehttpurl.c b/apps/netutils/netlib/uip_parsehttpurl.c deleted file mode 100644 index efc88956a..000000000 --- a/apps/netutils/netlib/uip_parsehttpurl.c +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_parsehttpurl.c - * - * Copyright (C) 2009, 2011 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 - -#include -#include -#include - -#include - -/**************************************************************************** - * Private Data - *****************************************************************************/ - -const char g_http[] = "http://"; -#define HTTPLEN 7 - -/**************************************************************************** - * Public Functions - *****************************************************************************/ - -/**************************************************************************** - * Name: uip_parsehttpurl - ****************************************************************************/ - -int uip_parsehttpurl(const char *url, uint16_t *port, - char *hostname, int hostlen, - char *filename, int namelen) -{ - const char *src = url; - char *dest; - int bytesleft; - int ret = OK; - - /* A valid HTTP URL must begin with http:// if it does not, we will assume - * that it is a file name only, but still return an error. wget() depends - * on this strange behavior. - */ - - if (strncmp(src, g_http, HTTPLEN) != 0) - { - ret = -EINVAL; - } - else - { - /* Skip over the http:// */ - - src += HTTPLEN; - - /* Concatenate the hostname following http:// and up to the termnator */ - - dest = hostname; - bytesleft = hostlen; - while (*src != '\0' && *src != '/' && *src != ' ' && *src != ':') - { - /* Make sure that there is space for another character in the hostname. - * (reserving space for the null terminator) - */ - - if (bytesleft > 1) - { - *dest++ = *src++; - bytesleft--; - } - else - { - ret = -E2BIG; - } - } - *dest = '\0'; - - /* Check if the hostname is following by a port number */ - - if (*src == ':') - { - uint16_t accum = 0; - src++; /* Skip over the colon */ - - while (*src >= '0' && *src <= '9') - { - accum = 10*accum + *src - '0'; - src++; - } - *port = accum; - } - } - - /* The rest of the line is the file name */ - - if (*src == '\0' || *src == ' ') - { - ret = -ENOENT; - } - - /* Make sure the file name starts with exactly one '/' */ - - dest = filename; - bytesleft = namelen; - while (*src == '/') - { - src++; - } - *dest++ = '/'; - bytesleft--; - - /* The copy the rest of the file name to the user buffer */ - - strncpy(dest, src, namelen); - filename[namelen-1] = '\0'; - return ret; -} - diff --git a/apps/netutils/netlib/uip_server.c b/apps/netutils/netlib/uip_server.c deleted file mode 100644 index c6b3d1631..000000000 --- a/apps/netutils/netlib/uip_server.c +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_server.c - * - * Copyright (C) 2007-2009, 2011 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 - -#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_t 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; - int ret; - - /* Create a new TCP socket to use to listen for connections */ - - listensd = uip_listenon(portno); - if (listensd < 0) - { - return; - } - - /* Begin serving connections */ - - for (;;) - { - /* Accept the next connectin */ - - addrlen = sizeof(struct sockaddr_in); - acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen); - if (acceptsd < 0) - { - ndbg("accept failure: %d\n", errno); - break; - } - - nvdbg("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 */ - - ret = setsockopt(acceptsd, SOL_SOCKET, SO_LINGER, &ling, sizeof(struct linger)); - if (ret < 0) - { - close(acceptsd); - ndbg("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); - - ret = pthread_create(&child, &attr, handler, (void*)acceptsd); - if (ret != 0) - { - /* Close the connection */ - - close(acceptsd); - ndbg("pthread_create failed\n"); - - if (ret == EAGAIN) - { - /* Lacked resources to create a new thread. This is a temporary - * condition, so we close this peer, but keep serving for - * other connections. - */ - - continue; - } - - /* Something is very wrong... Break out and stop serving */ - - 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); - } - - /* Close the listerner socket */ - - close(listensd); -} diff --git a/apps/netutils/netlib/uip_setdraddr.c b/apps/netutils/netlib/uip_setdraddr.c deleted file mode 100644 index bdc19d624..000000000 --- a/apps/netutils/netlib/uip_setdraddr.c +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_setdraddr.c - * - * Copyright (C) 2007-2009, 2011 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_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, NETLIB_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 - 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/apps/netutils/netlib/uip_sethostaddr.c b/apps/netutils/netlib/uip_sethostaddr.c deleted file mode 100644 index ada4431f5..000000000 --- a/apps/netutils/netlib/uip_sethostaddr.c +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_sethostaddr.c - * - * Copyright (C) 2007-2009, 2011 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_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, NETLIB_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 - 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/apps/netutils/netlib/uip_setifflag.c b/apps/netutils/netlib/uip_setifflag.c deleted file mode 100644 index c7a6dfb73..000000000 --- a/apps/netutils/netlib/uip_setifflag.c +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_setifflag.c - * - * Copyright (C) 2007-2009, 2011, 2014 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_ifup - * - * Description: - * Set the network interface UP - * - * Parameters: - * ifname The name of the interface to use - * - * Return: - * 0 on sucess; -1 on failure - * - ****************************************************************************/ - -int uip_ifup(const char *ifname) -{ - int ret = ERROR; - if (ifname) - { - /* Get a socket (only so that we get access to the INET subsystem) */ - - int sockfd = socket(PF_INET, NETLIB_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 ifup flag */ - - req.ifr_flags |= IFF_UP; - - ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&req); - close(sockfd); - } - } - - return ret; -} - -/**************************************************************************** - * Name: uip_ifdown - * - * Description: - * Set the network interface DOWN - * - * Parameters: - * ifname The name of the interface to use - * - * Return: - * 0 on sucess; -1 on failure - * - ****************************************************************************/ - -int uip_ifdown(const char *ifname) -{ - int ret = ERROR; - if (ifname) - { - /* Get a socket (only so that we get access to the INET subsystem) */ - - int sockfd = socket(PF_INET, NETLIB_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 ifup flag */ - - req.ifr_flags |= IFF_DOWN; - - ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&req); - close(sockfd); - } - } - - return ret; -} - -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/apps/netutils/netlib/uip_setmacaddr.c b/apps/netutils/netlib/uip_setmacaddr.c deleted file mode 100644 index d35034a69..000000000 --- a/apps/netutils/netlib/uip_setmacaddr.c +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_setmacaddr.c - * - * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * 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 - -/**************************************************************************** - * Pre-processor 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_t *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, NETLIB_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); - - /* Perform 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/apps/netutils/netlib/uip_setnetmask.c b/apps/netutils/netlib/uip_setnetmask.c deleted file mode 100644 index 8b3f9651c..000000000 --- a/apps/netutils/netlib/uip_setnetmask.c +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** - * netutils/netlib/uip_setnetmask.c - * - * Copyright (C) 2007-2009, 2011 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_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, NETLIB_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 - 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