net-snmp获取各个类型的数据
来源:互联网 发布:yum配置 编辑:程序博客网 时间:2024/06/05 02:13
- 原文地址http://blog.chinaunix.net/uid-17260303-id-3042593.html
- /* manipuate the information ourselves */
- for(vars = response->variables; vars; vars = vars->next_variable) //pdu is a snmp_pdu style variable
- {
- printf("var type is %d\n", vars->type);
- if (vars->type == ASN_OCTET_STR) //vars is a variable_list style variable
- {
- //判断是字符串还是Hex-STRING
- int hex = 0;
- int x;
- u_char * cp;
- int allow_realloc = 1;
- u_char *buf = NULL;
- size_t buf_len = 256, out_len = 0;
- for (cp = vars->val.string, x = 0; x < (int) vars->val_len; x++, cp++)
- {
- if (!isprint(*cp) && !isspace(*cp))
- {
- hex = 1;
- }
- }
- if(!hex) //字符串
- {
- char *sp = (char *)malloc(1 + vars->val_len);
- memcpy(sp, vars->val.string, vars->val_len); //netsnmp_vardata is a netsnmp_vardata style variable
- sp[vars->val_len] = '\0';
- printf("value #%d is a string: %s\n", count++, sp);
- free(sp);
- }
- else //Hex-STRING
- {
- buf = (u_char *) calloc(buf_len, 1);
- snmp_cstrcat(&buf, &buf_len, &out_len, allow_realloc, "");
- sprint_realloc_hexstring(&buf, &buf_len, &out_len, allow_realloc,vars->val.string, vars->val_len);
- printf("value #%d is a hex-string: %s\n", count++, buf);
- free(buf);
- }
- }
- else if(vars->type == ASN_TIMETICKS)
- {
- long timetick = *vars->val.integer;
- printf("value #%d is a timetick: %d\n", count++, timetick);
- }
- else if(vars->type == ASN_OBJECT_ID)
- {
- printf("value #%d is a oid: ", count++);
- for(i=0; i<vars->name_length; i++)
- {
- if(*(vars->name_loc+i) == 0)
- break;
- printf(".%d", *(vars->name_loc+i));
- }
- printf(" and value is ");
- for(i=0; i<(vars->val_len/sizeof(int)); i++)
- {
- printf(".%d", *(vars->val.objid+i));
- }
- printf("\n");
-
- }
- else if(vars->type == ASN_INTEGER)
- {
- printf("value #%d is a integer: %d\n", count++, *(vars->val.integer));
- }
- else if(vars->type == ASN_COUNTER)
- {
- printf("value #%d is a count: %u\n", count++, (unsigned int)(*vars->val.integer & 0xffffffff));
- }
- else if(vars->type == ASN_GAUGE)
- {
- printf("value #%d is a gauge: %u\n", count++, *(vars->val.integer));
- }
- else if(vars->type == ASN_IPADDRESS)
- {
- u_char *ip = vars->val.string;
- printf("value #%d is a ipaddress: %d.%d.%d.%d\n", count++, ip[0], ip[1], ip[2], ip[3]);
- }
- else if(vars->type == ASN_NULL)
- {
- printf("value #%d is a null: \n", count++);
- }
- else
- printf("value #%d is NOT a string! Ack!\n", count++);
- }
- }
阅读全文
0 0
- net-snmp获取各个类型的数据
- 使用snmp协议获取MIB的数据
- net-snmp扩展table类型的私有mib
- net-snmp扩展trap类型的私有mib
- linux下snmp4j获取net-snmp的基本信息
- Net-SNMP的mib2c
- net-snmp的编译
- net-snmp的编译
- net-snmp的编译
- Net-SNMP的mib2c
- Net-SNMP的配置
- Net-snmp总结(一)-snmp的基本概念
- java 各个类型数据的取值范围
- 在Snmp++中处理DateAndTime类型数据
- 获取number数据的类型
- idata的各个类型
- 各个类型的范围
- [OBS] 各个数据源的数据获取方法 & 对应的源文件
- 红黑树
- Linux下用apt-get安装的常用软件
- (182)渐变
- !important的意思与应用实例
- 给定一个整数数组,返回数组中两个元素的和为target的索引
- net-snmp获取各个类型的数据
- Oracle数据库IO问题分析利器(一)
- 内存四区模型
- hadoop学习笔记--7.MapReduce的工作机制
- Android中破解应用签名校验的后续问题处理方案(闪退和重启现象以及无效问题)
- 20170630-leetcode-225 Implement Stack using Queues
- (183)图像调整
- linux:ls、ls -l、ls -al区别
- Postgresql 分布式事务JTA实现Atomikos与Spring集成实践