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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*_############################################################################
  _##
  _##  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, specify community default is 'public' /n";
   cout << "         -rN , retries default is N = 1 retry/n";
   cout << "         -tN , timeout in hundredths of seconds; default is N = 100/n";
#ifdef _SNMPv3
          cout << "         -snSecurityName, " << endl;
          cout << "         -slN , securityLevel to use, default N = 3 = authPriv" << endl;
          cout << "         -smN , securityModel to use, only default N = 3 = USM possible/n";
          cout << "         -cnContextName, default empty string" << endl;
    &nb

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值