[C] Convert number to printable string
#include <stdio.h>
#include <stdlib.h>
/*
* P R _ T Y P E
*
* Convert an ICMP "type" field to a printable string.
*/
char *
pr_type( t )
register int t;
{
static char *ttab[] = {
"Echo Reply",
"ICMP 1",
"ICMP 2",
"Dest Unreachable",
"Source Quench",
"Redirect",
"ICMP 6",
"ICMP 7",
"Echo",
"ICMP 9",
"ICMP 10",
"Time Exceeded",
"Parameter Problem",
"Timestamp",
"Timestamp Reply",
"Info Request",
"Info Reply"
};
if( t < 0 || t > 16 )
return("OUT-OF-RANGE");
return(ttab[t]);
}
int
main(int argc, char *argv[])
{
int ch;
while ((ch = getopt(argc, argv, "c")) != EOF)
switch(ch) {
case 'c':
printf("%s \n",pr_type(1));
break;
default:
exit(2);
}
}
Reference:
Ping Source Code
0 意見:
張貼留言