Print ipv6 address in weblog and tcp_stats cgi

This commit is contained in:
dak664 2009-08-12 18:23:37 +00:00
parent 3847927a43
commit 0798c56899
4 changed files with 75 additions and 43 deletions

View file

@ -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(),
"<tr align=\"center\"><td>%d</td><td>%u.%u.%u.%u:%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\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))? '!':' ');
"<tr align=\"center\"><td>%d</td><td>%s:%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\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(),
"<tr align=\"center\"><td>%d</td><td>%u.%u.%u.%u:%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\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

View file

@ -30,9 +30,10 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $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 <stdio.h>
#include <string.h>
#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 */
/*---------------------------------------------------------------------------*/

View file

@ -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__ */

View file

@ -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],