本文整理汇总了C++中Packet::AddV2TrapVarbinds方法的典型用法代码示例。如果您正苦于以下问题:C++ Packet::AddV2TrapVarbinds方法的具体用法?C++ Packet::AddV2TrapVarbinds怎么用?C++ Packet::AddV2TrapVarbinds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet::AddV2TrapVarbinds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memset
//.........这里部分代码省略.........
///////////////////////////////////////////////////
// new to version 2.7
#ifdef _WIN32
NtSysUpTime sysUpTime;
#endif
#ifdef _LINUX
LinuxSysUpTime sysUpTime;
#endif
#ifdef _SOLARIS
SolarisSysUpTime sysUpTime;
#endif
#ifdef _IRIX
IrixSysUptime sysUpTime;
#endif
#ifdef _HPUX
HpuxSysUpTime sysUpTime;
#endif
#ifdef _FREEBSD
FreeBSDSysUptime sysUpTime;
#endif
gTimeTicks = sysUpTime.SysUpTime();
///////////////////////////////////////////////////
// figure out the ip address if not specified (V1 only)
if (gSenderIP == NULL && gVersion == 0)
{
char buf[255];
unsigned long len = 255;
memset(buf, 0, len);
if (gethostname(buf, len))
if (gDoLogging)
gOfile << "gethostname failed with error " << WSAGetLastError() << endl;
HOSTENT* h = gethostbyname(buf);
if (h != NULL)
{
struct in_addr in;
memcpy(&in.s_addr, *(h->h_addr_list), sizeof(in.s_addr));
gSenderIP = inet_ntoa(in);
}
else
{
gSenderIP = "240.30.20.10";
if (gDoLogging)
gOfile << "gethostbyname failed with error " << WSAGetLastError() << endl;
}
}
// build the packet
gPacket.Version(gVersion);
gPacket.Community(gCommunity);
if (gVersion == 0)
{
gPacket.Type(V1TRAP);
gPacket.SenderOID(gSenderOID);
gPacket.SenderIP(gSenderIP);
gPacket.TimeTicks(gTimeTicks);
gPacket.GenericTrapType(gGenericTrapType);
gPacket.SpecificTrapType(gSpecificTrapType);
}
else
{
if (!gInform)
gPacket.Type(V2TRAP);
else
gPacket.Type(INFORMPDU);
gPacket.RequestId(gRequestId);
gPacket.ErrorStatus(0);
gPacket.ErrorIndex(0);
gPacket.AddV2TrapVarbinds(gTimeTicks,
gSenderOID,
gGenericTrapType,
gSpecificTrapType,
gNoSubIds);
}
// send away
retVal = Send();
}
catch (SnmpException* se)
{
retVal = -1;
}
catch (...)
{
retVal = -2;
}
#ifdef _WIN32
WSACleanup();
#endif
if (gDoLogging)
gOfile.close();
return retVal;
}