?? monitor.c
字號:
*/
if( ioctl( sock, SIOCGIFFLAGS, &ifreq ) >= 0 )
{
html_table_row_begin(client, "" );
fprintf( client, "<td>Flags<td>\n" );
for( i = 0; i < 16; i++ )
{
switch( ifreq.ifr_flags & (1<<i) )
{
default: break;
case IFF_UP: fputs( " UP", client ); break;
case IFF_BROADCAST: fputs( " BROADCAST", client ); break;
case IFF_DEBUG: fputs( " DEBUG", client ); break;
case IFF_LOOPBACK: fputs( " LOOPBACK", client ); break;
case IFF_PROMISC: fputs( " PROMISCUOUS", client ); break;
case IFF_RUNNING: fputs( " RUNNING", client ); break;
case IFF_SIMPLEX: fputs( " SIMPLEX", client ); break;
case IFF_MULTICAST: fputs( " MULTICAST", client ); break;
}
}
html_table_row_end( client );
}
/* Get the interface's address and display it. */
if( ioctl( sock, SIOCGIFADDR, &ifreq ) >= 0 )
{
struct sockaddr_in *inaddr =
(struct sockaddr_in *)&ifreq.ifr_addr;
html_table_row_begin(client, "" );
fprintf( client, "<td>Address<td>%s\n",
inet_ntoa(inaddr->sin_addr));
html_table_row_end( client );
}
/* If there's a netmask, show that. */
if( ioctl( sock, SIOCGIFNETMASK, &ifreq ) >= 0 )
{
struct sockaddr_in *inaddr =
(struct sockaddr_in *)&ifreq.ifr_addr;
html_table_row_begin(client, "" );
fprintf( client, "<td>Mask<td>%s\n",
inet_ntoa(inaddr->sin_addr));
html_table_row_end( client );
}
/* If there's a broadcast address, show that. */
if( ioctl( sock, SIOCGIFBRDADDR, &ifreq ) >= 0 )
{
struct sockaddr_in *inaddr =
(struct sockaddr_in *)&ifreq.ifr_broadaddr;
html_table_row_begin(client, "" );
fprintf( client, "<td>Broadcast Address<td>%s\n",
inet_ntoa(inaddr->sin_addr));
html_table_row_end( client );
}
/* If the ethernet driver collects
* statistics, fetch those and show some
* of them.
*/
ethstats.ifreq = ifreq;
if( ioctl( sock, SIOCGIFSTATS, ðstats ) >= 0 )
{
fprintf( client, "<tr><td>Hardware<td>%s</tr>\n",
ethstats.description );
fprintf( client, "<tr><td>Packets Received<td>%d</tr>\n",
ethstats.rx_count );
fprintf( client, "<tr><td>Packets Sent<td>%d</tr>\n",
ethstats.tx_count );
fprintf( client, "<tr><td>Interrupts<td>%d</tr>\n",
ethstats.interrupts );
}
}
html_table_end( client );
}
html_table_row_end( client );
}
/* Scan the addresses, even if we are not interested
* in this interface, since we must skip to the next.
*/
do
{
sa = &ifrp->ifr_addr;
if (sa->sa_len <= sizeof(*sa)) {
ifrp++;
} else {
ifrp=(struct ifreq *)(sa->sa_len + (char *)sa);
ifconf.ifc_len -= sa->sa_len - sizeof(*sa);
}
ifconf.ifc_len -= sizeof(*ifrp);
} while (!ifrp->ifr_name[0] && ifconf.ifc_len);
}
}
html_table_end( client );
/* Now the protocols. For each of the main protocols: IP,
* ICMP, UDP, TCP print a table of useful information derived
* from the in-kernel data structures. Note that this only
* works for the BSD stacks.
*/
html_para_begin( client, "" );
html_heading(client, 3, "Protocols" );
html_para_begin( client, "" );
html_table_begin( client, "border");
{
html_table_header( client, "IP", "" );
html_table_header( client, "ICMP", "" );
html_table_header( client, "UDP", "" );
html_table_header( client, "TCP", "" );
html_table_row_begin(client, "" );
{
html_table_data_begin( client, "valign=\"top\"" );
html_table_begin( client, "" );
{
fprintf( client, "<tr><td><b>%s:</b><td></tr>\n", "Received" );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Total",
ipstat.ips_total );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Bad",
ipstat.ips_badsum+
ipstat.ips_tooshort+
ipstat.ips_toosmall+
ipstat.ips_badhlen+
ipstat.ips_badlen+
ipstat.ips_noproto+
ipstat.ips_toolong
);
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Reassembled",
ipstat.ips_reassembled );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Delivered",
ipstat.ips_delivered );
fprintf( client, "<tr><td><b>%s:</b><td></tr>\n", "Sent" );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Total",
ipstat.ips_localout );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Raw",
ipstat.ips_rawout );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Fragmented",
ipstat.ips_fragmented );
}
html_table_end( client );
html_table_data_begin( client, "valign=\"top\"" );
html_table_begin( client, "" );
{
fprintf( client, "<tr><td><b>%s:</b><td></tr>\n", "Received" );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "ECHO",
icmpstat.icps_inhist[ICMP_ECHO] );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "ECHO REPLY",
icmpstat.icps_inhist[ICMP_ECHOREPLY] );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "UNREACH",
icmpstat.icps_inhist[ICMP_UNREACH] );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "REDIRECT",
icmpstat.icps_inhist[ICMP_REDIRECT] );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Other",
icmpstat.icps_inhist[ICMP_SOURCEQUENCH]+
icmpstat.icps_inhist[ICMP_ROUTERADVERT]+
icmpstat.icps_inhist[ICMP_ROUTERSOLICIT]+
icmpstat.icps_inhist[ICMP_TIMXCEED]+
icmpstat.icps_inhist[ICMP_PARAMPROB]+
icmpstat.icps_inhist[ICMP_TSTAMP]+
icmpstat.icps_inhist[ICMP_TSTAMPREPLY]+
icmpstat.icps_inhist[ICMP_IREQ]+
icmpstat.icps_inhist[ICMP_IREQREPLY]+
icmpstat.icps_inhist[ICMP_MASKREQ]+
icmpstat.icps_inhist[ICMP_MASKREPLY]
);
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Bad",
icmpstat.icps_badcode+
icmpstat.icps_tooshort+
icmpstat.icps_checksum+
icmpstat.icps_badlen+
icmpstat.icps_bmcastecho
);
fprintf( client, "<tr><td><b>%s:</b><td></tr>\n", "Sent" );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "ECHO",
icmpstat.icps_outhist[ICMP_ECHO] );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "ECHO REPLY",
icmpstat.icps_outhist[ICMP_ECHOREPLY] );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "UNREACH",
icmpstat.icps_outhist[ICMP_UNREACH] );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "REDIRECT",
icmpstat.icps_outhist[ICMP_REDIRECT] );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Other",
icmpstat.icps_inhist[ICMP_SOURCEQUENCH]+
icmpstat.icps_outhist[ICMP_ROUTERADVERT]+
icmpstat.icps_outhist[ICMP_ROUTERSOLICIT]+
icmpstat.icps_outhist[ICMP_TIMXCEED]+
icmpstat.icps_outhist[ICMP_PARAMPROB]+
icmpstat.icps_outhist[ICMP_TSTAMP]+
icmpstat.icps_outhist[ICMP_TSTAMPREPLY]+
icmpstat.icps_outhist[ICMP_IREQ]+
icmpstat.icps_outhist[ICMP_IREQREPLY]+
icmpstat.icps_outhist[ICMP_MASKREQ]+
icmpstat.icps_outhist[ICMP_MASKREPLY]
);
}
html_table_end( client );
html_table_data_begin( client, "valign=\"top\"" );
html_table_begin( client, "" );
{
fprintf( client, "<tr><td><b>%s:</b><td></tr>\n", "Received" );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Total",
udpstat.udps_ipackets );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Bad",
udpstat.udps_hdrops+
udpstat.udps_badsum+
udpstat.udps_badlen+
udpstat.udps_noport+
udpstat.udps_noportbcast+
udpstat.udps_fullsock
);
fprintf( client, "<tr><td><b>%s:</b><td></tr>\n", "Sent" );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Total",
udpstat.udps_opackets );
}
html_table_end( client );
html_table_data_begin( client, "valign=\"top\"" );
html_table_begin( client, "" );
{
fprintf( client, "<tr><td><b>%s:</b><td></tr>\n", "Connections" );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Initiated",
tcpstat.tcps_connattempt );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Accepted",
tcpstat.tcps_accepts );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Established",
tcpstat.tcps_connects );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Closed",
tcpstat.tcps_closed );
fprintf( client, "<tr><td><b>%s:</b><td></tr>\n", "Received" );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Packets",
tcpstat.tcps_rcvtotal );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Data Packets",
tcpstat.tcps_rcvpack );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Bytes",
tcpstat.tcps_rcvbyte );
fprintf( client, "<tr><td><b>%s:</b><td></tr>\n", "Sent" );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Packets",
tcpstat.tcps_sndtotal );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Data Packets",
tcpstat.tcps_sndpack );
fprintf( client, "<tr><td>%s<td>%ld</tr>\n", "Bytes",
tcpstat.tcps_sndbyte );
}
html_table_end( client );
}
html_table_row_end( client );
}
html_table_end( client );
draw_navbar(client);
}
html_body_end(client);
html_end(client);
close( sock );
return 1;
}
CYG_HTTPD_TABLE_ENTRY( cyg_monitor_network_entry,
"/monitor/network.htm*",
cyg_monitor_network,
NULL );
/* ================================================================= */
/* Instrumentation Monitor
*
* If the CYGPKG_KERNEL_INSTRUMENT option is set, we generate a table
* showing the current instrumentation buffer. If the FLAGS option is
* enabled we also print a table giving control of the flags.
*
*/
#ifdef CYGPKG_KERNEL_INSTRUMENT
/* Instrumentation record. */
struct Instrument_Record
{
CYG_WORD16 type; // record type
CYG_WORD16 thread; // current thread id
CYG_WORD timestamp; // 32 bit timestamp
CYG_WORD arg1; // first arg
CYG_WORD arg2; // second arg
};
typedef struct Instrument_Record Instrument_Record;
/* Instrumentation variables, these live in the
* instrumentation files in the kernel
*/
__externC Instrument_Record *instrument_buffer_pointer;
__externC Instrument_Record instrument_buffer[];
__externC cyg_uint32 instrument_buffer_size;
#if defined(CYGDBG_KERNEL_INSTRUMENT_FLAGS) && \
defined(CYGDBG_KERNEL_INSTRUMENT_MSGS)
static cyg_uint32 instrument_flags[(CYG_INSTRUMENT_CLASS_MAX>>8)+1];
#endif
static char cyg_monitor_instrument_blurb1[] =
"<p>Use the checkboxes to enable the events to be recorded. Click
the <em>Submit</em> button to start recording. Click the <em>Clear</em>
button to clear all instrumentation and to stop recording."
;
static cyg_bool cyg_monitor_instrument( FILE * client, char *filename,
char *formdata, void *arg )
{
#if defined(CYGDBG_KERNEL_INSTRUMENT_FLAGS) && \
defined(CYGDBG_KERNEL_INSTRUMENT_MSGS)
/* Disable all instrumentation while we generate the page.
* Otherwise we could swamp the information we are really after.
*/
cyg_scheduler_lock();
{
struct instrument_desc_s *id = instrument_desc;
CYG_WORD cl = 0, ev = 0;
for( ; id->msg != 0; id++ )
{
if( id->num > 0xff )
{
cl = id->num>>8;
instrument_flags[cl] = 0;
}
else
{
ev = id->num;
cyg_instrument_disable( cl<<8, ev );
}
}
}
cyg_scheduler_unlock();
#endif
/* If we have some form data, deal with it.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -