diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-02 21:58:35 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-02 21:58:35 +0000 |
commit | 9a272c38fb40781171f7b4d054430f2c0be730c0 (patch) | |
tree | 892d21bc1008301a5f07a8634cf5cb227f563dc6 /nuttx/netutils/webclient | |
parent | 8e6fadad87d3220628d412fee845ad0b0cfb697f (diff) | |
download | px4-nuttx-9a272c38fb40781171f7b4d054430f2c0be730c0.tar.gz px4-nuttx-9a272c38fb40781171f7b4d054430f2c0be730c0.tar.bz2 px4-nuttx-9a272c38fb40781171f7b4d054430f2c0be730c0.zip |
Implements basic TCP connection logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@326 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/netutils/webclient')
-rw-r--r-- | nuttx/netutils/webclient/webclient.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/nuttx/netutils/webclient/webclient.c b/nuttx/netutils/webclient/webclient.c index 30718e723..a89647ab5 100644 --- a/nuttx/netutils/webclient/webclient.c +++ b/nuttx/netutils/webclient/webclient.c @@ -38,12 +38,13 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: webclient.c,v 1.1.1.1 2007-08-26 23:07:05 patacongo Exp $ + * $Id: webclient.c,v 1.2 2007-09-02 21:58:34 patacongo Exp $ * */ #include <sys/types.h> #include <string.h> +#include <sys/socket.h> #include <net/uip/uip.h> #include <net/uip/resolv.h> @@ -118,24 +119,43 @@ void webclient_close(void) unsigned char webclient_get(char *host, uint16 port, char *file) { - struct uip_conn *conn; uip_ipaddr_t *ipaddr; static uip_ipaddr_t addr; + struct sockaddr_in server; + int sockfd; /* First check if the host is an IP address. */ + ipaddr = &addr; - if (uiplib_ipaddrconv(host, (unsigned char *)addr) == 0) { - ipaddr = (uip_ipaddr_t *)resolv_lookup(host); + if (uiplib_ipaddrconv(host, (unsigned char *)addr) == 0) + { + ipaddr = (uip_ipaddr_t *)resolv_lookup(host); - if (ipaddr == NULL) { - return 0; - } + if (ipaddr == NULL) { + return 0; + } } - conn = uip_connect(ipaddr, htons(port)); + /* Create a socket */ - if (conn == NULL) { - return 0; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) + { + return ERROR; + } + + /* Connect to server. First we have to set some fields in the + * 'server' structure. The system will assign me an arbitrary + * local port that is not in use. + */ + + server.sin_family = AF_INET; + memcpy(&server.sin_addr.s_addr, &host, sizeof(in_addr_t)); + server.sin_port = htons(port); + + if (connect(sockfd, (struct sockaddr *)&server, sizeof(struct sockaddr_in)) < 0) + { + return ERROR; } s.port = port; @@ -143,7 +163,7 @@ unsigned char webclient_get(char *host, uint16 port, char *file) strncpy(s.host, host, sizeof(s.host)); init_connection(); - return 1; + return OK; } static char *copy_string(char *dest, const char *src, int len) |