snmp++中的snmpGet例子,在ipv4下运行可以,ipv6下出错

本文档提供了一个使用snmp++库的snmpGet实例代码,该代码在IPv4环境下运行正常,但在IPv6环境下出现错误。代码中包含了如何设置SNMP版本、重试次数、超时时间、社区名等参数,并提供了错误处理和使用说明。在IPv6环境下运行失败的原因可能涉及到地址解析、端口配置或SNMP版本不兼容等问题。
摘要由CSDN通过智能技术生成

/*_############################################################################
  _##
  _##  snmpGet.cpp 
  _##
  _##  SNMP++v3.2.24
  _##  -----------------------------------------------
  _##  Copyright (c) 2001-2009 Jochen Katz, Frank Fock
  _##
  _##  This software is based on SNMP++2.6 from Hewlett Packard:
  _## 
  _##    Copyright (c) 1996
  _##    Hewlett-Packard Company
  _## 
  _##  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  _##  Permission to use, copy, modify, distribute and/or sell this software
  _##  and/or its documentation is hereby granted without fee. User agrees
  _##  to display the above copyright notice and this license notice in all
  _##  copies of the software and any documentation of the software. User
  _##  agrees to assume all liability for the use of the software;
  _##  Hewlett-Packard and Jochen Katz make no representations about the
  _##  suitability of this software for any purpose. It is provided
  _##  "AS-IS" without warranty of any kind, either express or implied. User
  _##  hereby grants a royalty-free license to any and all derivatives based
  _##  upon this software code base.
  _## 
  _##  Stuttgart, Germany, Fri May 29 22:35:14 CEST 2009
  _## 
  _##########################################################################*/
/*
  snmpGet.cpp

  Copyright (c) 1996
  Hewlett-Packard Company

  ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  Permission to use, copy, modify, distribute and/or sell this software
  and/or its documentation is hereby granted without fee. User agrees
  to display the above copyright notice and this license notice in all
  copies of the software and any documentation of the software. User
  agrees to assume all liability for the use of the software; Hewlett-Packard
  makes no representations about the suitability of this software for any
  purpose. It is provided "AS-IS" without warranty of any kind,either express
  or implied. User hereby grants a royalty-free license to any and all
  derivatives based upon this software code base.

  Peter E. Mellquist
*/
char snmpget_cpp_version[]="@(#) SNMP++ $Id: snmpGet.cpp 1534 2009-05-27 22:07:17Z katz $";

#include "snmp_pp/snmp_pp.h"
#include <stdlib.h>
#include <stdio.h>
#define  strcasecmp stricmp

#ifdef SNMP_PP_NAMESPACE
using namespace Snmp_pp;
#endif

#if (__GNUC__ > 2)
#include <iostream>
using std::cerr;
using std::cout;
using std::endl;
using std::flush;
#else
#include <iostream.h>
#endif

int main(int argc, char **argv)
{
   //---------[ check the arg count ]----------------------------------------
   if ( argc < 2) {
   cout << "Usage:/n";
   cout << argv[0] << " IpAddress | DNSName [Oid] [options]/n";
   cout << "Oid: sysDescr object is default/n";
   cout << "options: -vN , use SNMP version 1, 2 or 3, default is 1/n";
   cout << "         -PPort , remote port to use/n";
   cout << "         -CCommunity_name, s

在Linux下编译SNMP '../include/system/libsnmp.h' 需要遵循以下步骤: 1. 确保已经安装了所需的编译工具和依赖库。这些工具包括gcc编译器、make工具和SNMP的依赖库,如libsnmp-dev。 2. 下载SNMP软件包的源代码。可以从SNMP官方网站或其他可靠的软件源获取。 3. 解压源代码文件。使用tar命令解压下载的源代码文件,例如:tar -xzvf snmp.tar.gz。 4. 进入解压后的目录。使用cd命令切换到解压后的源代码目录。 5. 创建构建目录。在源代码目录,使用mkdir命令创建一个构建目录,例如:mkdir build。 6. 进入构建目录。使用cd命令进入构建目录。 7. 运行配置脚本。在构建目录运行配置脚本,该脚本会检查系统依赖性并为编译过程做准备。运行命令为:../configure。 8. 编译SNMP。在构建目录,使用make命令开始编译SNMP软件包。运行命令为:make。 9. 安装SNMP。在构建目录,使用sudo make install命令安装SNMP软件包。这将把编译后的二进制文件和库文件复制到系统的标准位置。 10. 检查安装结果。编译和安装完成后,可以使用命令snmpget或snmpwalk等SNMP命令来验证安装是否成功。例如,运行snmpget -v2c -c public localhost sysDescr.0命令来获取设备的系统描述信息。 完成以上步骤后,应该成功编译并安装了SNMP软件包,并可以在Linux系统上使用SNMP功能。请注意,具体的步骤可能会因不同的Linux发行版和SNMP软件包版本而有所差异,所以建议参考相应的文档或网站来获取更准确的指导。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值