diff options
Diffstat (limited to 'nuttx/examples/wget')
-rw-r--r-- | nuttx/examples/wget/host.c | 30 | ||||
-rwxr-xr-x | nuttx/examples/wget/hostdefs.h | 3 | ||||
-rw-r--r-- | nuttx/examples/wget/target.c | 10 |
3 files changed, 39 insertions, 4 deletions
diff --git a/nuttx/examples/wget/host.c b/nuttx/examples/wget/host.c index 600f83c29..1ada4cea4 100644 --- a/nuttx/examples/wget/host.c +++ b/nuttx/examples/wget/host.c @@ -38,6 +38,10 @@ ****************************************************************************/ #include <net/uip/webclient.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> /**************************************************************************** * Private Data @@ -47,20 +51,42 @@ * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: callback + ****************************************************************************/ + static void callback(FAR char **buffer, int offset, int datend, FAR int *buflen) { + (void)write(1, &((*buffer)[offset]), datend - offset); +} + +/**************************************************************************** + * Name: show_usage + ****************************************************************************/ + +static void show_usage(const char *progname, int exitcode) +{ + fprintf(stderr, "USAGE: %s <host> <filename>\n", progname); + exit(exitcode); } /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * main + * Name: main ****************************************************************************/ int main(int argc, char **argv, char **envp) { char buffer[1024]; - wget(argv[0], 80, argv[1], buffer, 1024, callback); + + if (argc != 3) + { + show_usage(argv[0], 1); + } + + printf("WGET: Getting %s from %s\n", argv[2], argv[1]); + wget(80, argv[1], argv[2], buffer, 1024, callback); return 0; } diff --git a/nuttx/examples/wget/hostdefs.h b/nuttx/examples/wget/hostdefs.h index 2dd472114..c37c65e24 100755 --- a/nuttx/examples/wget/hostdefs.h +++ b/nuttx/examples/wget/hostdefs.h @@ -10,7 +10,8 @@ typedef unsigned char boolean; # define HTONS(a) htons(a)
# define HTONL(a) htonl(a)
-# define CONFIG_CPP_HAVE_WARNING 1
+# define CONFIG_CPP_HAVE_WARNING 1
+# define CONFIG_HAVE_GETHOSTBYNAME 1
# define FAR
# define ndbg(...) printf(__VA_ARGS__)
diff --git a/nuttx/examples/wget/target.c b/nuttx/examples/wget/target.c index 00d56f750..68bd47f4a 100644 --- a/nuttx/examples/wget/target.c +++ b/nuttx/examples/wget/target.c @@ -38,11 +38,16 @@ ****************************************************************************/ #include <nuttx/config.h> + #include <sys/types.h> + #include <netinet/in.h> #include <arpa/inet.h> #include <net/if.h> + +#include <net/uip/uip.h> #include <net/uip/uip-lib.h> +#include <net/uip/resolv.h> #include <net/uip/webclient.h> /**************************************************************************** @@ -79,6 +84,8 @@ * Private Data ****************************************************************************/ +static char g_iobuffer[512]; + /**************************************************************************** * user_initialize ****************************************************************************/ @@ -99,6 +106,7 @@ void user_initialize(void) int user_start(int argc, char *argv[]) { struct in_addr addr; + static uip_ipaddr_t addr; #if defined(CONFIG_EXAMPLE_WGET_NOMAC) uint8 mac[IFHWADDRLEN]; #endif @@ -132,6 +140,6 @@ int user_start(int argc, char *argv[]) /* Then start the server */ - wget(Needs more work); + wget(80, CONFIG_EXAMPLE_WGET_HOSTNAME, CONFIG_EXAMPLE_WGET_FILENAME, g_iobuffer, 512, callback); return 0; } |