diff --git a/apps/webserver/httpd-cgi.c b/apps/webserver/httpd-cgi.c index fdf4ccd18..b86deaf50 100644 --- a/apps/webserver/httpd-cgi.c +++ b/apps/webserver/httpd-cgi.c @@ -28,7 +28,7 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: httpd-cgi.c,v 1.14 2008/10/14 11:07:57 adamdunkels Exp $ + * $Id: httpd-cgi.c,v 1.15 2009/08/12 18:23:37 dak664 Exp $ * */ @@ -156,21 +156,36 @@ make_tcp_stats(void *arg) { struct uip_conn *conn; struct httpd_state *s = (struct httpd_state *)arg; - conn = &uip_conns[s->u.count]; + + #if UIP_CONF_IPV6 + char buf[48]; + httpd_sprint_ip6(conn->ripaddr, buf); return snprintf((char *)uip_appdata, uip_mss(), - "%d%u.%u.%u.%u:%u%s%u%u%c %c\r\n", - htons(conn->lport), - conn->ripaddr.u8[0], - conn->ripaddr.u8[1], - conn->ripaddr.u8[2], - conn->ripaddr.u8[3], - htons(conn->rport), - states[conn->tcpstateflags & UIP_TS_MASK], - conn->nrtx, - conn->timer, - (uip_outstanding(conn))? '*':' ', - (uip_stopped(conn))? '!':' '); + "%d%s:%u%s%u%u%c %c\r\n", + htons(conn->lport), + buf, + htons(conn->rport), + states[conn->tcpstateflags & UIP_TS_MASK], + conn->nrtx, + conn->timer, + (uip_outstanding(conn))? '*':' ', + (uip_stopped(conn))? '!':' '); +#else + return snprintf((char *)uip_appdata, uip_mss(), + "%d%u.%u.%u.%u:%u%s%u%u%c %c\r\n", + htons(conn->lport), + conn->ripaddr.u8[0], + conn->ripaddr.u8[1], + conn->ripaddr.u8[2], + conn->ripaddr.u8[3], + htons(conn->rport), + states[conn->tcpstateflags & UIP_TS_MASK], + conn->nrtx, + conn->timer, + (uip_outstanding(conn))? '*':' ', + (uip_stopped(conn))? '!':' '); +#endif /* UIP_CONF_IPV6 */ } /*---------------------------------------------------------------------------*/ static diff --git a/apps/webserver/httpd.c b/apps/webserver/httpd.c index e98c474f0..e9e62530f 100644 --- a/apps/webserver/httpd.c +++ b/apps/webserver/httpd.c @@ -30,9 +30,10 @@ * * Author: Adam Dunkels * - * $Id: httpd.c,v 1.11 2008/10/14 11:07:57 adamdunkels Exp $ + * $Id: httpd.c,v 1.12 2009/08/12 18:23:37 dak664 Exp $ */ - + +#include #include #include "contiki-net.h" @@ -336,4 +337,37 @@ httpd_init(void) memb_init(&conns); httpd_cgi_init(); } +#if UIP_CONF_IPV6 +/*---------------------------------------------------------------------------*/ +uint8_t +httpd_sprint_ip6(uip_ip6addr_t addr, char * result) +{ + unsigned char i = 0; + unsigned char zerocnt = 0; + unsigned char numprinted = 0; + char * starting = result; + + *result++='['; + while (numprinted < 8) { + if ((addr.u16[i] == 0) && (zerocnt == 0)) { + while(addr.u16[zerocnt + i] == 0) zerocnt++; + if (zerocnt == 1) { + *result++ = '0'; + numprinted++; + break; + } + i += zerocnt; + numprinted += zerocnt; + } else { + result += sprintf(result, "%x", (unsigned int)(ntohs(addr.u16[i]))); + i++; + numprinted++; + } + if (numprinted != 8) *result++ = ':'; + } + *result++=']'; + *result=0; + return (result - starting); +} +#endif /* UIP_CONF_IPV6 */ /*---------------------------------------------------------------------------*/ diff --git a/apps/webserver/httpd.h b/apps/webserver/httpd.h index 9cc1cdfbf..21a5baf48 100644 --- a/apps/webserver/httpd.h +++ b/apps/webserver/httpd.h @@ -28,7 +28,7 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: httpd.h,v 1.5 2007/05/23 21:35:18 oliverschmidt Exp $ + * $Id: httpd.h,v 1.6 2009/08/12 18:23:37 dak664 Exp $ * */ @@ -60,4 +60,8 @@ struct httpd_state { void httpd_init(void); void httpd_appcall(void *state); +#if UIP_CONF_IPV6 +uint8_t httpd_sprint_ip6(uip_ip6addr_t addr, char * result); +#endif /* UIP_CONF_IPV6 */ + #endif /* __HTTPD_H__ */ diff --git a/apps/webserver/webserver-nogui.c b/apps/webserver/webserver-nogui.c index 99a7eb7ad..37b139f56 100644 --- a/apps/webserver/webserver-nogui.c +++ b/apps/webserver/webserver-nogui.c @@ -29,7 +29,7 @@ * * This file is part of the Contiki OS. * - * $Id: webserver-nogui.c,v 1.6 2009/08/11 16:07:54 dak664 Exp $ + * $Id: webserver-nogui.c,v 1.7 2009/08/12 18:23:37 dak664 Exp $ * */ @@ -68,32 +68,11 @@ webserver_log_file(uip_ipaddr_t *requester, char *file) #if LOG_CONF_ENABLED /* Print out IP address of requesting host. */ - #if UIP_CONF_IPV6 +#if UIP_CONF_IPV6 char buf[48]; - unsigned char i = 0; - unsigned char zerocnt = 0; - unsigned char numprinted = 0; - char *result=buf; - - *result++='['; - while (numprinted < 8) { - if ((requester->u16[i] == 0) && (zerocnt == 0)) { - while(requester->u16[zerocnt + i] == 0) zerocnt++; - if (zerocnt == 1) { - *result++ = '0'; - numprinted++; - break; - } - i += zerocnt; - numprinted += zerocnt; - } else { - result += sprintf(result, "%x", (unsigned int)(ntohs(requester->u16[i]))); - i++; - numprinted++; - } - if (numprinted != 8) *result++ = ':'; - } - result +=sprintf(result, "]: "); + uint8_t j; + j=httpd_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],