当前位置: 首页>>代码示例>>C++>>正文


C++ Packet::GenericTrapType方法代码示例

本文整理汇总了C++中Packet::GenericTrapType方法的典型用法代码示例。如果您正苦于以下问题:C++ Packet::GenericTrapType方法的具体用法?C++ Packet::GenericTrapType怎么用?C++ Packet::GenericTrapType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Packet的用法示例。


在下文中一共展示了Packet::GenericTrapType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
开发者ID:bigmacd,项目名称:trapgen,代码行数:101,代码来源:TrapGen.cpp

示例2: udp

int
Send()
{
  int retVal = 1;

  if (gIpAddress == NULL)
  {
    cout << "Must specify at least a -d \"destination IP Address\"" << endl;
    cout << "e.g., trapgen -d 244.0.2.43" << endl;
    return 0;
  }
    
  if (gDump == ' ')
  {
    UdpClient udp(gPort, gIpAddress);
    if (gDoLogging)
      if (!udp.IsReady())
	gOfile << "udp failed to initialize with error " << udp.ErrorCode() << endl;
    udp.Send(&gPacket);
    if (gInform)
    {
      udp.Timeout(gTimeout);
      Packet* p = udp.Receive(0);

      if (p != NULL && 
	  (p->RequestId() == gRequestId) && 
	  (p->Type() == V1RESPONSE))
	retVal = 0;
      else
	if (gDoLogging)
	  gOfile << "Sent INFORM but response timed out (timeout = " << gTimeout << ')' << endl;
    }
    else
      retVal = 0;
  }
  else
  {
    if (gDump == 'a' || gDump == 'b')
    {
      cout << "Length: " << gPacket.TotalLength() << endl;
      int version = gPacket.Version();
      cout << "Version: ";
      if (version == 0)
	cout << "SNMPv1";
      else
	if (version == 1)
	  cout << "SNMPv2";
      cout << endl;

      cout << "Community: " << gPacket. Community() << endl;

      if (version == 0)
      {
	cout << "Generic: " << gPacket.GenericTrapType() << endl;
	cout << "Specific: " << gPacket.SpecificTrapType() << endl;
	////////////////////////////////////////////////////////
	int tTime = gPacket.TimeTicks();
	tTime /= 100;
	int days = tTime/(60*60*24);
	tTime -= days * (60*60*24);
	int hrs = tTime/(60*60);
	tTime -= hrs*(60*60);
	int mins = tTime/(60);
	tTime -= mins*(60);
	char newcTime[128];
#ifdef _WIN32
	sprintf_s(newcTime, 128, "%d days %02dh:%02dm:%02ds", days, hrs, mins, tTime);
#else
	sprintf(newcTime, "%d days %02dh:%02dm:%02ds", days, hrs, mins, tTime);
#endif
	cout << "TimeStamp: " << newcTime << " (" << gPacket.TimeTicks() << ")" << endl;
	// cout << "TimeStamp: " << gPacket.TimeTicks() << endl;
	////////////////////////////////////////////////////////
	cout << "SenderIP: " << gPacket.SenderIP() << endl;
      }

      if (version == 0)
	cout << "SenderOID: " << gPacket.SenderOID() << endl;

      int vblen = gPacket.VbListLength();
      for (int x = 1; x <= vblen; x++)
      {
	cout << "Varbind Number " << x << ' ' << endl;
	cout << '\t' << "Oid: " << gPacket.VbOID(x) << endl;
	cout << '\t' << "Type: " << gPacket.VbType(x) << endl;
	cout << '\t' << "Data: " << gPacket.VbData(x) << endl;
      }
      cout << endl;
    }

    if (gDump == 'h' || gDump == 'b')
    {
      unsigned int l = gPacket.TotalLength();
      unsigned char* pdu = new unsigned char[l];
      gPacket.Build(pdu);
      for (unsigned int asdf = 0; asdf < l; asdf++)
      {
	if (asdf && !(asdf % 10))
	  printf("\n");
	printf("%02x ", pdu[asdf]);
//.........这里部分代码省略.........
开发者ID:bigmacd,项目名称:trapgen,代码行数:101,代码来源:TrapGen.cpp


注:本文中的Packet::GenericTrapType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。