From 03c02454657a0dd346fc92181caeb2b696efc49f Mon Sep 17 00:00:00 2001 From: dak664 Date: Tue, 9 Feb 2010 14:41:18 +0000 Subject: [PATCH] Expose httpd-cgi ipv6 address print to other modules --- .../apps/raven-webserver/httpd-cgi.c | 9 +++----- .../apps/raven-webserver/httpd-cgi.h | 3 ++- .../apps/raven-webserver/webserver-nogui.c | 23 ++++++++++++++----- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/platform/avr-raven/apps/raven-webserver/httpd-cgi.c b/platform/avr-raven/apps/raven-webserver/httpd-cgi.c index 0afbfb240..801b9fff1 100644 --- a/platform/avr-raven/apps/raven-webserver/httpd-cgi.c +++ b/platform/avr-raven/apps/raven-webserver/httpd-cgi.c @@ -28,7 +28,7 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: httpd-cgi.c,v 1.4 2009/07/24 15:41:52 dak664 Exp $ + * $Id: httpd-cgi.c,v 1.5 2010/02/09 14:41:18 dak664 Exp $ * */ @@ -100,9 +100,6 @@ static const char *states[] = { char sensor_temperature[12]; - uint8_t sprint_ip6(uip_ip6addr_t addr, char * result); - - void web_set_temp(char *s) { @@ -210,7 +207,7 @@ make_tcp_stats(void *arg) conn = &uip_conns[s->u.count]; numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_tcpstat1, htons(conn->lport)); - numprinted += sprint_ip6(conn->ripaddr, uip_appdata + numprinted); + numprinted += httpd_cgi_sprint_ip6(conn->ripaddr, uip_appdata + numprinted); httpd_strcpy(tstate,states[conn->tcpstateflags & UIP_TS_MASK]); numprinted += httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_tcpstat2, @@ -318,7 +315,7 @@ httpd_cgi_init(void) } /*---------------------------------------------------------------------------*/ -uint8_t sprint_ip6(uip_ip6addr_t addr, char * result) +uint8_t httpd_cgi_sprint_ip6(uip_ip6addr_t addr, char * result) { unsigned char zerocnt = 0; unsigned char numprinted = 0; diff --git a/platform/avr-raven/apps/raven-webserver/httpd-cgi.h b/platform/avr-raven/apps/raven-webserver/httpd-cgi.h index d665ecaf8..60cb7c7f6 100644 --- a/platform/avr-raven/apps/raven-webserver/httpd-cgi.h +++ b/platform/avr-raven/apps/raven-webserver/httpd-cgi.h @@ -28,7 +28,7 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: httpd-cgi.h,v 1.1 2009/03/12 19:15:25 adamdunkels Exp $ + * $Id: httpd-cgi.h,v 1.2 2010/02/09 14:41:18 dak664 Exp $ * */ @@ -55,5 +55,6 @@ static struct httpd_cgi_call name = {NULL, str, function} void httpd_cgi_init(void); void web_set_temp(char *s); +uint8_t httpd_cgi_sprint_ip6(uip_ip6addr_t addr, char * result); #endif /* __HTTPD_CGI_H__ */ diff --git a/platform/avr-raven/apps/raven-webserver/webserver-nogui.c b/platform/avr-raven/apps/raven-webserver/webserver-nogui.c index 1ed255ef6..84c93f056 100644 --- a/platform/avr-raven/apps/raven-webserver/webserver-nogui.c +++ b/platform/avr-raven/apps/raven-webserver/webserver-nogui.c @@ -29,7 +29,7 @@ * * This file is part of the Contiki OS. * - * $Id: webserver-nogui.c,v 1.2 2009/06/19 17:11:28 dak664 Exp $ + * $Id: webserver-nogui.c,v 1.3 2010/02/09 14:41:18 dak664 Exp $ * */ @@ -42,6 +42,7 @@ #include "http-strings.h" #include "webserver-nogui.h" #include "httpd.h" +#include "httpd-cgi.h" PROCESS(webserver_nogui_process, "Web server"); @@ -61,19 +62,29 @@ PROCESS_THREAD(webserver_nogui_process, ev, data) PROCESS_END(); } + /*---------------------------------------------------------------------------*/ void webserver_log_file(uip_ipaddr_t *requester, char *file) { -#if LOG_CONF_ENABLED - char buf[18]; - /* Print out IP address of requesting host. */ - sprintf_P(buf, PSTR("%d.%d.%d.%d: "), requester->u8[0], requester->u8[1], - requester->u8[2], requester->u8[3]); +#if LOG_CONF_ENABLED +#if UIP_CONF_IPV6 + char buf[48]; + uint8_t j; + j=httpd_cgi_sprint_ip6((uip_ip6addr_t)*requester, buf); + buf[j]=':';buf[j+1]=' ';buf[j+2]=0; +#else + char buf[20]; + sprintf(buf, "%d.%d.%d.%d: ", requester->u8[0], requester->u8[1], + requester->u8[2], requester->u8[3]); +#endif /* UIP_CONF_IPV6 */ + log_message(buf, file); #endif /* LOG_CONF_ENABLED */ + } + /*---------------------------------------------------------------------------*/ void webserver_log(char *msg)