From c099737f809c1d2730af9cffcdecea4d700f4c4e Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 26 Mar 2009 23:45:24 +0000 Subject: wget bugfixes (still lots of problems) git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1645 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/examples/wget/host.c | 30 ++++++++++++++++++++++++++++-- nuttx/examples/wget/hostdefs.h | 3 ++- nuttx/examples/wget/target.c | 10 +++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) (limited to 'nuttx/examples') 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 +#include +#include +#include +#include /**************************************************************************** * 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 \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 + #include + #include #include #include + +#include #include +#include #include /**************************************************************************** @@ -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; } -- cgit v1.2.3