From 5b96d86bfb3e9d8abf1ac2b1c129d11bcbd08cec Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 19 Mar 2011 21:04:13 +0000 Subject: [PATCH] Move nuttx/netutils to apps/netutils git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3401 42af7a65-404d-4744-a932-0658087f49c3 --- Makefile | 2 +- README.txt | 4 + netutils/Makefile | 62 + netutils/README.txt | 39 + netutils/dhcpc/Makefile | 94 + netutils/dhcpc/dhcpc.c | 607 +++++ netutils/dhcpd/Makefile | 94 + netutils/dhcpd/dhcpd.c | 1393 +++++++++++ netutils/resolv/Makefile | 94 + netutils/resolv/resolv.c | 440 ++++ netutils/smtp/Makefile | 94 + netutils/smtp/smtp.c | 376 +++ netutils/telnetd/Makefile | 94 + netutils/telnetd/README.txt | 7 + netutils/telnetd/shell.c | 139 ++ netutils/telnetd/shell.h | 97 + netutils/telnetd/telnetd.c | 459 ++++ netutils/tftpc/Makefile | 96 + netutils/tftpc/tftpc_get.c | 328 +++ netutils/tftpc/tftpc_internal.h | 173 ++ netutils/tftpc/tftpc_packets.c | 330 +++ netutils/tftpc/tftpc_put.c | 477 ++++ netutils/thttpd/Makefile | 121 + netutils/thttpd/cgi-src/Makefile | 136 ++ netutils/thttpd/cgi-src/phf.c | 77 + netutils/thttpd/cgi-src/redirect.c | 269 +++ netutils/thttpd/cgi-src/ssi.c | 957 ++++++++ netutils/thttpd/config.h | 253 ++ netutils/thttpd/fdwatch.c | 371 +++ netutils/thttpd/fdwatch.h | 111 + netutils/thttpd/libhttpd.c | 3525 ++++++++++++++++++++++++++++ netutils/thttpd/libhttpd.h | 342 +++ netutils/thttpd/mime_types.h | 279 +++ netutils/thttpd/tdate_parse.c | 341 +++ netutils/thttpd/tdate_parse.h | 41 + netutils/thttpd/thttpd.c | 861 +++++++ netutils/thttpd/thttpd_alloc.c | 199 ++ netutils/thttpd/thttpd_alloc.h | 78 + netutils/thttpd/thttpd_cgi.c | 1080 +++++++++ netutils/thttpd/thttpd_cgi.h | 61 + netutils/thttpd/thttpd_strings.c | 179 ++ netutils/thttpd/thttpd_strings.h | 123 + netutils/thttpd/timers.c | 365 +++ netutils/thttpd/timers.h | 136 ++ netutils/uiplib/Makefile | 103 + netutils/uiplib/uip_gethostaddr.c | 106 + netutils/uiplib/uip_getmacaddr.c | 104 + netutils/uiplib/uip_ipmsfilter.c | 116 + netutils/uiplib/uip_parsehttpurl.c | 149 ++ netutils/uiplib/uip_server.c | 184 ++ netutils/uiplib/uip_setdraddr.c | 117 + netutils/uiplib/uip_sethostaddr.c | 117 + netutils/uiplib/uip_setmacaddr.c | 114 + netutils/uiplib/uip_setnetmask.c | 116 + netutils/uiplib/uiplib.c | 95 + netutils/webclient/Makefile | 94 + netutils/webclient/webclient.c | 583 +++++ netutils/webserver/Makefile | 94 + netutils/webserver/httpd.c | 498 ++++ netutils/webserver/httpd.h | 118 + netutils/webserver/httpd_cgi.c | 170 ++ netutils/webserver/httpd_cgi.h | 69 + netutils/webserver/httpd_fs.c | 155 ++ netutils/webserver/httpd_fsdata.c | 614 +++++ netutils/webserver/httpd_fsdata.h | 79 + netutils/webserver/makefsdata | 75 + nshlib/Makefile | 10 +- vsn/Makefile | 2 +- vsn/free/Makefile | 3 +- vsn/hello/Makefile | 3 +- vsn/poweroff/Makefile | 3 +- vsn/ramtron/Makefile | 3 +- vsn/sdcard/Makefile | 3 +- 73 files changed, 19286 insertions(+), 15 deletions(-) create mode 100644 netutils/Makefile create mode 100644 netutils/README.txt create mode 100644 netutils/dhcpc/Makefile create mode 100644 netutils/dhcpc/dhcpc.c create mode 100644 netutils/dhcpd/Makefile create mode 100644 netutils/dhcpd/dhcpd.c create mode 100644 netutils/resolv/Makefile create mode 100644 netutils/resolv/resolv.c create mode 100644 netutils/smtp/Makefile create mode 100644 netutils/smtp/smtp.c create mode 100644 netutils/telnetd/Makefile create mode 100644 netutils/telnetd/README.txt create mode 100644 netutils/telnetd/shell.c create mode 100644 netutils/telnetd/shell.h create mode 100644 netutils/telnetd/telnetd.c create mode 100644 netutils/tftpc/Makefile create mode 100644 netutils/tftpc/tftpc_get.c create mode 100644 netutils/tftpc/tftpc_internal.h create mode 100644 netutils/tftpc/tftpc_packets.c create mode 100644 netutils/tftpc/tftpc_put.c create mode 100644 netutils/thttpd/Makefile create mode 100644 netutils/thttpd/cgi-src/Makefile create mode 100644 netutils/thttpd/cgi-src/phf.c create mode 100644 netutils/thttpd/cgi-src/redirect.c create mode 100644 netutils/thttpd/cgi-src/ssi.c create mode 100644 netutils/thttpd/config.h create mode 100644 netutils/thttpd/fdwatch.c create mode 100644 netutils/thttpd/fdwatch.h create mode 100644 netutils/thttpd/libhttpd.c create mode 100644 netutils/thttpd/libhttpd.h create mode 100644 netutils/thttpd/mime_types.h create mode 100644 netutils/thttpd/tdate_parse.c create mode 100644 netutils/thttpd/tdate_parse.h create mode 100644 netutils/thttpd/thttpd.c create mode 100755 netutils/thttpd/thttpd_alloc.c create mode 100755 netutils/thttpd/thttpd_alloc.h create mode 100755 netutils/thttpd/thttpd_cgi.c create mode 100755 netutils/thttpd/thttpd_cgi.h create mode 100755 netutils/thttpd/thttpd_strings.c create mode 100755 netutils/thttpd/thttpd_strings.h create mode 100644 netutils/thttpd/timers.c create mode 100644 netutils/thttpd/timers.h create mode 100644 netutils/uiplib/Makefile create mode 100644 netutils/uiplib/uip_gethostaddr.c create mode 100644 netutils/uiplib/uip_getmacaddr.c create mode 100755 netutils/uiplib/uip_ipmsfilter.c create mode 100644 netutils/uiplib/uip_parsehttpurl.c create mode 100644 netutils/uiplib/uip_server.c create mode 100644 netutils/uiplib/uip_setdraddr.c create mode 100644 netutils/uiplib/uip_sethostaddr.c create mode 100644 netutils/uiplib/uip_setmacaddr.c create mode 100644 netutils/uiplib/uip_setnetmask.c create mode 100644 netutils/uiplib/uiplib.c create mode 100644 netutils/webclient/Makefile create mode 100644 netutils/webclient/webclient.c create mode 100644 netutils/webserver/Makefile create mode 100644 netutils/webserver/httpd.c create mode 100644 netutils/webserver/httpd.h create mode 100644 netutils/webserver/httpd_cgi.c create mode 100644 netutils/webserver/httpd_cgi.h create mode 100644 netutils/webserver/httpd_fs.c create mode 100644 netutils/webserver/httpd_fsdata.c create mode 100644 netutils/webserver/httpd_fsdata.h create mode 100755 netutils/webserver/makefsdata diff --git a/Makefile b/Makefile index 7f95c5cd3..d81606a3f 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ APPDIR = ${shell pwd} # SUBDIRS is the list of all directories containing Makefiles. It is used # only for cleaning. -SUBDIRS = nshlib vsn +SUBDIRS = nshlib netutils vsn # we use a non-existing .built_always to guarantee that Makefile # always walks into the sub-directories and asks for build diff --git a/README.txt b/README.txt index 86758dddf..b80393a03 100644 --- a/README.txt +++ b/README.txt @@ -52,6 +52,7 @@ will call: Application skeleton can be found under the hello sub-directory, which shows how an application can be added to the project. One must define: + 1. create sub-directory as: appname 2. provide entry point: appname_main() 3. set the requirements in the file: Makefile, specially the lines: @@ -62,3 +63,6 @@ define: CSRCS = C source file list as foo1.c foo2.c .. 4. add application in the apps/Makefile + + + diff --git a/netutils/Makefile b/netutils/Makefile new file mode 100644 index 000000000..3c3f11c43 --- /dev/null +++ b/netutils/Makefile @@ -0,0 +1,62 @@ +############################################################################ +# apps/netutils/Makefile +# +# Copyright (C) 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. +# +############################################################################ + +-include $(TOPDIR)/.config # Current configuration + +# Sub-directories + +ifeq ($(CONFIG_NET),y) +SUBDIRS = uiplib dhcpc dhcpd resolv smtp telnetd webclient webserver tftpc thttpd +endif + +all: nothing +.PHONY: nothing depend clean distclean + +nothing: + +define DOMAKE + @(MAKE) -C $1 $2 TOPDIR="$(TOPDIR) APPDIR=$(APPDIR)" +endef + +depend: + $(foreach DIR, $(SUBDIRS), $(eval $(call DOMAKE,$(DIR),depend))) + +clean: + $(foreach DIR, $(SUBDIRS), $(eval $(call DOMAKE,$(DIR),clean))) + +distclean: clean + $(foreach DIR, $(SUBDIRS), $(eval $(call DOMAKE,$(DIR),distclean))) + +-include Make.dep diff --git a/netutils/README.txt b/netutils/README.txt new file mode 100644 index 000000000..e4b05eb21 --- /dev/null +++ b/netutils/README.txt @@ -0,0 +1,39 @@ +netutils +^^^^^^^^ + +This directory contains most of the network applications contained +under the uIP-1.0 apps directory. As the uIP apps/README says, +these applications "are not all heavily tested." These uIP apps +include: + + dhcpc - Dynamic Host Configuration Protocol (DHCP) client + resolv - uIP DNS resolver + smtp - Simple Mail Transfer Protocol (SMTP) client + telnetd - TELNET server + webclient - HTTP web client + webserver - HTTP web server + +You may find additional information on these apps in the uIP forum +accessible through: http://www.sics.se/~adam/uip/index.php/Main_Page + +Additional applications that were not part of uIP (but which are +highly influenced by uIP) include: + + dhcpd - Dynamic Host Configuration Protocol (DHCP) server + tftpc - TFTP client + thttpd - This is a port of Jef Poskanzer's THTTPD HTPPD server. + See http://acme.com/software/thttpd/. + +If you use DHCPC/D, then some special configuration network options are +required. These include: + + CONFIG_NET=y Of course + CONFIG_NSOCKET_DESCRIPTORS And, of course, you must allocate some + socket descriptors. + CONFIG_NET_UDP=y UDP support is required for DHCP + (as well as various other UDP-related + configuration settings). + CONFIG_NET_BROADCAST=y UDP broadcast support is needed. + CONFIG_NET_BUFSIZE=650 The client must be prepared to receive + (or larger) DHCP messages of up to 576 bytes (excluding + Ethernet, IP, or UDP headers and FCS). diff --git a/netutils/dhcpc/Makefile b/netutils/dhcpc/Makefile new file mode 100644 index 000000000..7209907de --- /dev/null +++ b/netutils/dhcpc/Makefile @@ -0,0 +1,94 @@ +############################################################################ +# apps/netutils/dhcpc/Makefile +# +# Copyright (C) 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. +# +############################################################################ + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +# DHCP Client Library + +ASRCS = +CSRCS = + +ifeq ($(CONFIG_NET_UDP),y) +CSRCS += dhcpc.c +endif + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +BIN = ../../libapps$(LIBEXT) + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +$(BIN): $(OBJS) + @( for obj in $(OBJS) ; do \ + $(call ARCHIVE, $@, $${obj}); \ + done ; ) + @touch .built + +.built: $(BIN) + +.depend: Makefile $(SRCS) + @$(MKDEP) $(ROOTDEPPATH) \ + $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +# Register application +depend: .depend + +clean: + @rm -f $(BIN) *.o *~ .*.swp .built + $(call CLEAN) + +distclean: clean + @rm -f Make.dep .depend + +-include Make.dep diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c new file mode 100644 index 000000000..dc80988bb --- /dev/null +++ b/netutils/dhcpc/dhcpc.c @@ -0,0 +1,607 @@ +/**************************************************************************** + * netutils/dhcpc/dhcpc.c + * + * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Based heavily on portions of uIP: + * + * Author: Adam Dunkels + * Copyright (c) 2005, Swedish Institute of Computer Science + * All rights reserved. + * + * 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 of the Institute 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 INSTITUTE 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 INSTITUTE 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 + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +#define STATE_INITIAL 0 +#define STATE_HAVE_OFFER 1 +#define STATE_HAVE_LEASE 2 + +#define BOOTP_BROADCAST 0x8000 + +#define DHCP_REQUEST 1 +#define DHCP_REPLY 2 +#define DHCP_HTYPE_ETHERNET 1 +#define DHCP_HLEN_ETHERNET 6 +#define DHCP_MSG_LEN 236 + +#define DHCPC_SERVER_PORT 67 +#define DHCPC_CLIENT_PORT 68 + +#define DHCPDISCOVER 1 +#define DHCPOFFER 2 +#define DHCPREQUEST 3 +#define DHCPDECLINE 4 +#define DHCPACK 5 +#define DHCPNAK 6 +#define DHCPRELEASE 7 + +#define DHCP_OPTION_SUBNET_MASK 1 +#define DHCP_OPTION_ROUTER 3 +#define DHCP_OPTION_DNS_SERVER 6 +#define DHCP_OPTION_REQ_IPADDR 50 +#define DHCP_OPTION_LEASE_TIME 51 +#define DHCP_OPTION_MSG_TYPE 53 +#define DHCP_OPTION_SERVER_ID 54 +#define DHCP_OPTION_REQ_LIST 55 +#define DHCP_OPTION_END 255 + +#define BUFFER_SIZE 256 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct dhcp_msg +{ + uint8_t op; + uint8_t htype; + uint8_t hlen; + uint8_t hops; + uint8_t xid[4]; + uint16_t secs; + uint16_t flags; + uint8_t ciaddr[4]; + uint8_t yiaddr[4]; + uint8_t siaddr[4]; + uint8_t giaddr[4]; + uint8_t chaddr[16]; +#ifndef CONFIG_NET_DHCP_LIGHT + uint8_t sname[64]; + uint8_t file[128]; +#endif + uint8_t options[312]; +}; + +struct dhcpc_state_s +{ + struct uip_udp_conn *ds_conn; + const void *ds_macaddr; + int ds_maclen; + int sockfd; + struct in_addr ipaddr; + struct in_addr serverid; + struct dhcp_msg packet; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const uint8_t xid[4] = {0xad, 0xde, 0x12, 0x23}; +static const uint8_t magic_cookie[4] = {99, 130, 83, 99}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dhcpc_add