mirror of
https://github.com/apache/nuttx.git
synced 2026-05-24 16:11:56 +08:00
wget bugfixes (still lots of problems)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1645 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+28
-2
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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__)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -55,10 +55,6 @@
|
||||
* Pre-processor definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NETUTILS_WEBCLIENT_MAXURLLEN
|
||||
# define CONFIG_NETUTILS_WEBCLIENT_MAXURLLEN 100
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NETUTILS_WEBCLIENT_MAXHTTPLINE
|
||||
# define CONFIG_NETUTILS_WEBCLIENT_MAXHTTPLINE 200
|
||||
#endif
|
||||
@@ -71,6 +67,10 @@
|
||||
# define CONFIG_NETUTILS_WEBCLIENT_MAXHOSTNAME 40
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NETUTILS_WEBCLIENT_MAXFILENAME
|
||||
# define CONFIG_NETUTILS_WEBCLIENT_MAXFILENAME 100
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public types
|
||||
****************************************************************************/
|
||||
@@ -122,10 +122,10 @@ extern "C" {
|
||||
* query answer.
|
||||
*
|
||||
* Input Parameters
|
||||
* host - A pointer to a string containing either a host name or
|
||||
* a numerical IP address in dotted decimal notation (e.g., 192.168.23.1).
|
||||
* port - The port number to which to connect, in host byte order.
|
||||
* file - A pointer to the name of the file to get.
|
||||
* hostname - A pointer to a string containing either a host name or
|
||||
* a numerical IP address in dotted decimal notation (e.g., 192.168.23.1).
|
||||
* filename - A pointer to the name of the file to get.
|
||||
* buffer - A user provided buffer to receive the file data (also
|
||||
* used for the outgoing GET request
|
||||
* buflen - The size of the user provided buffer
|
||||
@@ -138,7 +138,8 @@ extern "C" {
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int wget(FAR const char *host, uint16 port, FAR const char *file,
|
||||
EXTERN int wget(uint16 port,
|
||||
FAR const char *hostname, FAR const char *filename,
|
||||
FAR char *buffer, int buflen, wget_callback_t callback);
|
||||
|
||||
#undef EXTERN
|
||||
|
||||
+215
-137
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user