Esempio n. 1
0
/*---------------------------------------------------------------------------*/
static unsigned short
make_tcp_stats(void *arg)
{
  static const char httpd_cgi_tcpstat1[] HTTPD_STRING_ATTR = "<tr align=\"center\"><td>%d</td><td>";
  static const char httpd_cgi_tcpstat2[] HTTPD_STRING_ATTR = "-%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n";
  static const char httpd_cgi_tcpstat3[] HTTPD_STRING_ATTR = "[Room for %d more]";

  struct uip_conn *conn;
  struct httpd_state *s = (struct httpd_state *)arg;
  char tstate[20];
  uint16_t numprinted;
  
  if (s->u.count==UIP_CONNS){
    for(numprinted = 0; numprinted < UIP_CONNS; numprinted++ ) {
	    if((uip_conns[numprinted].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) s->u.count--;
	}
    return(httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_tcpstat3, s->u.count));
  }

  conn = &uip_conns[s->u.count];

  numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_tcpstat1, uip_htons(conn->lport));
  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,
                 uip_htons(conn->rport),
                 tstate,
                 conn->nrtx,
                 conn->timer,
                 (uip_outstanding(conn))? '*':' ',
                 (uip_stopped(conn))? '!':' ');

  return numprinted;
}
Esempio n. 2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_netstat_process, ev, data)
{
  char buf[BUFLEN];
  int i;
  struct uip_conn *conn;
  PROCESS_BEGIN();

  for(i = 0; i < UIP_CONNS; ++i) {
    conn = &uip_conns[i];
    snprintf(buf, BUFLEN,
	     "%d, %u.%u.%u.%u:%u, %s, %u, %u, %c %c",
	     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))? '!':' ');
    shell_output_str(&netstat_command, "TCP ", buf);
  }
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
static unsigned short
make_tcp_stats(void *arg)
{
  struct uip_conn *conn;
  struct httpd_state *s = (struct httpd_state *)arg;
    
  uint16_t numprinted;

  conn = &uip_conns[s->u.count];

  numprinted = snprintf((char *)uip_appdata, uip_mss(),
                 "<tr align=\"center\"><td>%d</td><td>", 
                 htons(conn->lport));
                 
  numprinted += sprint_ip6(conn->ripaddr, uip_appdata + numprinted);             
  numprinted +=  snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted,              
                 "-%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n",
                 htons(conn->rport),
                 states[conn->tcpstateflags & UIP_TS_MASK],
                 conn->nrtx,
                 conn->timer,
                 (uip_outstanding(conn))? '*':' ',
                 (uip_stopped(conn))? '!':' ');

  return numprinted;
}
Esempio n. 4
0
static unsigned short function_tcp_connections(char* buffer, int bufsize) {
    unsigned short len = 0;
    // list as many connections as fit into the buffer
    for (int i = 0; len < bufsize && i<UIP_CONF_MAX_CONNECTIONS; i++) {
        len+=snprintf_P(buffer+len, bufsize-len, tcp_conn_formatter1,
                htons(uip_conns[i].lport),
                htons(uip_conns[i].ripaddr[0]) >> 8,
                htons(uip_conns[i].ripaddr[0]) & 0xff,
                htons(uip_conns[i].ripaddr[1]) >> 8,
                htons(uip_conns[i].ripaddr[1]) & 0xff,
                htons(uip_conns[i].rport));
        switch (uip_conns[i].tcpstateflags & UIP_TS_MASK) {
            case UIP_CLOSED:
                strncpy_P(buffer+len,tcp_closed,bufsize-len);
                len+=sizeof(tcp_closed)-1;
                break;
            case UIP_SYN_RCVD:
                strncpy_P(buffer+len,tcp_syn_rcvd,bufsize-len);
                len+=sizeof(tcp_syn_rcvd)-1;
                break;
            case UIP_SYN_SENT:
                strncpy_P(buffer+len,tcp_syn_sent,bufsize-len);
                len+=sizeof(tcp_syn_sent)-1;
                break;
            case UIP_ESTABLISHED:
                strncpy_P(buffer+len,tcp_established,bufsize-len);
                len+=sizeof(tcp_established)-1;
                break;
            case UIP_FIN_WAIT_1:
                strncpy_P(buffer+len,tcp_fin_wait_1,bufsize-len);
                len+=sizeof(tcp_fin_wait_1)-1;
                break;
            case UIP_FIN_WAIT_2:
                strncpy_P(buffer+len,tcp_fin_wait_2,bufsize-len);
                len+=sizeof(tcp_fin_wait_1)-1;
                break;
            case UIP_CLOSING:
                strncpy_P(buffer+len,tcp_closing,bufsize-len);
                len+=sizeof(tcp_closing);
                break;
            case UIP_TIME_WAIT:
                strncpy_P(buffer+len,tcp_time_wait,bufsize-len);
                len+=sizeof(tcp_time_wait)-1;
                break;
            case UIP_LAST_ACK:
                strncpy_P(buffer+len,tcp_last_ack,bufsize-len);
                len+=sizeof(tcp_last_ack)-1;
                break;
        }
        len+=snprintf_P(buffer+len, bufsize-len, tcp_conn_formatter2,
                uip_conns[i].nrtx,
                uip_conns[i].timer,
                (uip_outstanding(&uip_conns[i])) ? '*' : ' ',
                (uip_stopped(&uip_conns[i])) ? '!' : ' ');
    }
    return len;
}
Esempio n. 5
0
static unsigned short generate_tcp_stats( void *arg )
{
    struct uip_conn		*conn;
    struct httpd_state	*s = ( struct httpd_state * ) arg;

    conn = &uip_conns[s->count];
    return snprintf( ( char * ) uip_appdata, UIP_APPDATA_SIZE,
                     "<tr><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),
                     htons(conn->ripaddr[0]) >> 8, htons(conn->ripaddr[0]) & 0xff, htons(conn->ripaddr[1]) >> 8,
                     htons(conn->ripaddr[1]) & 0xff, htons(conn->rport), states[conn->tcpstateflags & UIP_TS_MASK], conn->nrtx, conn->timer,
                     (uip_outstanding(conn)) ? '*' : ' ', (uip_stopped(conn)) ? '!' : ' ' );
}
Esempio n. 6
0
/*---------------------------------------------------------------------------*/
static unsigned short
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><td>%d</td><td>%s:%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n",
                  uip_htons(conn->lport),
                  buf,
                  uip_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><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",
                  uip_htons(conn->lport),
                  conn->ripaddr.u8[0],
                  conn->ripaddr.u8[1],
                  conn->ripaddr.u8[2],
                  conn->ripaddr.u8[3],
                  uip_htons(conn->rport),
                  states[conn->tcpstateflags & UIP_TS_MASK],
                  conn->nrtx,
                  conn->timer,
                  (uip_outstanding(conn)) ? '*' : ' ',
                  (uip_stopped(conn)) ? '!' : ' ');
#endif /* UIP_CONF_IPV6 */
}
Esempio n. 7
0
void srv_waitsend(uint8_t sock) 
{	
	/* Process the stack until data where sent and no pending
		frames are waiting for ack
	*/
	do
	{	
		vNet_uIP();
		delay(uIP_DELAY);
	}
	while((uip_outstanding(&uip_conns[sock])) || (uip_conns[sock].appstate & SENDDATA));
	
	// Reset
	vnetlenght=0;

}
Esempio n. 8
0
/*-----------------------------------------------------------------------------------*/
static u8_t
tcp_stats(void)
{
  struct uip_conn *conn;  

  if(uip_acked()) {
    /* If the previously sent data has been acknowledged, we move
       forward one connection. */
    if(++hs->count == UIP_CONNS) {
      /* If all connections has been printed out, we are done and
	 return 1. */
      return 1;
    }
  }

  conn = &uip_conns[hs->count];
  while((conn->tcpstateflags & TS_MASK) == CLOSED) {
    if(++hs->count == UIP_CONNS) {
      /* If all connections has been printed out, we are done and
	 return 1. */
      return 1;
    }
    conn = &uip_conns[hs->count];
  }

  sprintf((char *)uip_appdata,
	  "<tr><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),
	  htons(conn->ripaddr[0]) >> 8,
	  htons(conn->ripaddr[0]) & 0xff,
	  htons(conn->ripaddr[1]) >> 8,
	  htons(conn->ripaddr[1]) & 0xff,
	  htons(conn->rport),
	  states[conn->tcpstateflags & TS_MASK],
	  conn->nrtx,
	  conn->timer,
	  (uip_outstanding(conn))? '*':' ',
	  (uip_stopped(conn))? '!':' ');
  uip_send(uip_appdata, strlen((char *)uip_appdata));

  return 0;
}
Esempio n. 9
0
static void connections(char *str, Shell *sh)
{
    char istr[128];
    struct uip_conn *connr;
    snprintf(istr, sizeof(istr), "Initial MSS: %d, MSS: %d\n", uip_initialmss(), uip_mss());
    sh->output(istr);
    sh->output("Current connections: \n");

    for (connr = &uip_conns[0]; connr <= &uip_conns[UIP_CONNS - 1]; ++connr) {
        if(connr->tcpstateflags != UIP_CLOSED) {
            snprintf(istr, sizeof(istr), "%d, %u.%u.%u.%u:%u, %s, %u, %u, %c %c\n",
                     HTONS(connr->lport),
                     uip_ipaddr1(connr->ripaddr), uip_ipaddr2(connr->ripaddr),  uip_ipaddr3(connr->ripaddr), uip_ipaddr4(connr->ripaddr),
                     HTONS(connr->rport),
                     states[connr->tcpstateflags & UIP_TS_MASK],
                     connr->nrtx,
                     connr->timer,
                     (uip_outstanding(connr)) ? '*' : ' ',
                     (uip_stopped(connr)) ? '!' : ' ');

            sh->output(istr);
        }
    }
}