⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inet.c

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 C
📖 第 1 页 / 共 2 页
字号:
            if (sp->entry == 0)                break;        }        if (sp->entry > stat)            continue;        /* Skip exceptions or missing values */        if ( !vp->val.integer )            continue;        /*         * If '-Cs' was specified twice,         *   then only display non-zero stats.         */        if ( *vp->val.integer > 0 || sflag == 1 ) {            putchar('\t');            printf(sp->description, *vp->val.integer,                             plural(*vp->val.integer));            putchar('\n');        }    }    snmp_free_varbind( var );}/* * Dump IP statistics. */voidip_stats(const char *name){    oid               ipstats_oid[] = { 1, 3, 6, 1, 2, 1, 4, 0, 0 };    size_t            ipstats_len   = OID_LENGTH( ipstats_oid );    struct stat_table ipstats_tbl[] = {        {3, "%d total datagram%s received"},        {4, "%d datagram%s with header errors"},        {5, "%d datagram%s with an invalid destination address"},        {6, "%d datagram%s forwarded"},        {7, "%d datagram%s with unknown protocol"},        {8, "%d datagram%s discarded"},        {9, "%d datagram%s delivered"},        {10, "%d output datagram request%s"},        {11, "%d output datagram%s discarded"},        {12, "%d datagram%s with no route"},        {14, "%d fragment%s received"},        {15, "%d datagram%s reassembled"},        {16, "%d reassembly failure%s"},        {17, "%d datagram%s fragmented"},        {18, "%d fragmentation failure%s"},        {19, "%d fragment%s created"},        {23, "%d route%s discarded"},        {0, ""}    };    _dump_stats( name, ipstats_oid, ipstats_len, ipstats_tbl );}/* * Dump ICMP statistics. */voidicmp_stats(const char *name){    oid               icmpstats_oid[] = { 1, 3, 6, 1, 2, 1, 5, 0, 0 };    size_t            icmpstats_len   = OID_LENGTH( icmpstats_oid );    struct stat_table icmpstats_tbl[] = {        {1, "%d total message%s received"},        {2, "%d message%s dropped due to errors"},        {14, "%d ouput message request%s"},        {15, "%d output message%s discarded"},        {0, ""}    };    struct stat_table icmp_inhistogram[] = {        {3, "Destination unreachable: %d"},        {4, "Time Exceeded: %d"},        {5, "Parameter Problem: %d"},        {6, "Source Quench: %d"},        {7, "Redirect: %d"},        {8, "Echo Request: %d"},        {9, "Echo Reply: %d"},        {10, "Timestamp Request: %d"},        {11, "Timestamp Reply: %d"},        {12, "Address Mask Request: %d"},        {13, "Address Mask Reply: %d"},        {0, ""}    };    struct stat_table icmp_outhistogram[] = {        {16, "Destination unreachable: %d"},        {17, "Time Exceeded: %d"},        {18, "Parameter Problem: %d"},        {19, "Source Quench: %d"},        {20, "Redirect: %d"},        {21, "Echo Request: %d"},        {22, "Echo Reply: %d"},        {23, "Timestamp Request: %d"},        {24, "Timestamp Reply: %d"},        {25, "Address Mask Request: %d"},        {26, "Address Mask Reply: %d"},        {0, ""}    };    _dump_stats( name, icmpstats_oid, icmpstats_len, icmpstats_tbl );    _dump_stats( "    Input Histogram",                       icmpstats_oid, icmpstats_len, icmp_inhistogram );    _dump_stats( "    Output Histogram",                       icmpstats_oid, icmpstats_len, icmp_outhistogram );}/* * Dump TCP statistics. */voidtcp_stats(const char *name){    oid               tcpstats_oid[] = { 1, 3, 6, 1, 2, 1, 6, 0, 0 };    size_t            tcpstats_len   = OID_LENGTH( tcpstats_oid );    struct stat_table tcpstats_tbl[] = {        {5, "%d active open%s"},        {6, "%d passive open%s"},        {7, "%d failed attempt%s"},        {8, "%d reset%s of established connections"},        {9, "%d current established connection%s"},        {10, "%d segment%s received"},        {11, "%d segment%s sent"},        {12, "%d segment%s retransmitted"},        {14, "%d invalid segment%s received"},        {15, "%d reset%s sent"},        {0, ""}    };    _dump_stats( name, tcpstats_oid, tcpstats_len, tcpstats_tbl );}/* * Dump UDP statistics. */voidudp_stats(const char *name){    oid               udpstats_oid[] = { 1, 3, 6, 1, 2, 1, 7, 0, 0 };    size_t            udpstats_len   = OID_LENGTH( udpstats_oid );    struct stat_table udpstats_tbl[] = {        {1, "%d total datagram%s received"},        {2, "%d datagram%s to invalid port"},        {3, "%d datagram%s dropped due to errors"},        {4, "%d output datagram request%s"},        {0, ""}    };    _dump_stats( name, udpstats_oid, udpstats_len, udpstats_tbl );}/* * Omitted: *     Dump IGMP     statistics *     Dump PIM      statistics *     Dump AH       statistics *     Dump etherip  statistics *     Dump ESP      statistics *     Dump IP-in-IP statistics *     Dump CARP     statistics *     Dump pfsync   statistics *     Dump IPCOMP   statistics */	/*	 * Utility routines	 *//* * Translation of RPC service names - Omitted *//* * Pretty print an Internet address (net address + port). * If the nflag was specified, use numbers instead of names. */voidinetprint(struct in_addr *in, int port, const char *proto, int local){	struct servent *sp = 0;	char line[80], *cp;	int width;	snprintf(line, sizeof line, "%.*s.", (Aflag && !nflag) ? 12 : 16,	    inetname(in));	cp = strchr(line, '\0');	if (!nflag && port)		sp = getservbyport((int)port, proto);	if (sp || port == 0)		snprintf(cp, line + sizeof line - cp, "%.8s",		    sp ? sp->s_name : "*");     /*      * Translation of RPC service names - Omitted      */	else		snprintf(cp, line + sizeof line - cp, "%d", ntohs(port));	width = Aflag ? 18 : 22;	printf(" %-*.*s", width, width, line);}/* * Construct an Internet address representation. * If the nflag has been supplied, give * numeric value, otherwise try for symbolic name. */char *inetname(struct in_addr *inp){	char *cp;	static char line[50];	struct hostent *hp;	struct netent *np;	static char domain[MAXHOSTNAMELEN];	static int first = 1;#if defined (WIN32) || defined (cygwin)        char host_temp[] = "localhost";#endif	if (first && !nflag) {		first = 0;		if (gethostname(domain, sizeof(domain)) == 0 &&		    (cp = strchr(domain, '.')))			(void) strlcpy(domain, cp + 1, sizeof domain);		else			domain[0] = '\0';	}	cp = NULL;	if (!nflag && inp->s_addr != INADDR_ANY) {		int net = inet_netof(*inp);		int lna = inet_lnaof(*inp);		if (lna == INADDR_ANY) {			np = getnetbyaddr(net, AF_INET);			if (np)				cp = np->n_name;		}		if (cp == NULL) {			hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET);			if (hp) {				if ((cp = strchr(hp->h_name, '.')) &&				    !strcmp(cp + 1, domain))					*cp = '\0';#if defined (WIN32) || defined (cygwin)                                        /* Windows insists on returning the computer name for 127.0.0.1                                         * even if the hosts file lists something else such as 'localhost'.                                         * If we are trying to look up 127.0.0.1, just return 'localhost'   */                                        if (!strcmp(inet_ntoa(*inp),"127.0.0.1"))                                             cp = host_temp;                                        else#endif                                                                          				cp = hp->h_name;			}		}	}	if (inp->s_addr == INADDR_ANY)		snprintf(line, sizeof line, "*");	else if (cp)		snprintf(line, sizeof line, "%s", cp);	else {		inp->s_addr = ntohl(inp->s_addr);#define C(x)	((x) & 0xff)		snprintf(line, sizeof line, "%u.%u.%u.%u",		    C(inp->s_addr >> 24), C(inp->s_addr >> 16),		    C(inp->s_addr >> 8), C(inp->s_addr));	}	return (line);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -