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


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

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


在下文中一共展示了Packet::Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: switch

void
InitOption(char opt, 
   char* optionValue, 
   char* secondValue, 
   char* thirdValue)
{
  switch (opt)
  {
#ifdef _WIN32
    case 'z':
    case 'Z':
    {
      gFreeConsole = TRUE;
      break;
    }
#endif

    case 'x':
      gNoSubIds = TRUE;
      break;

    case 'd':
    case 'D':
    {
      char* colon = strchr(optionValue, ':');
      if (colon)
      {
	*colon++ = 0;
	gPort = atoi(colon);
      }
      gIpAddress = _strdup(optionValue);
      break;
    }
    
    case 'c':
    case 'C':
    {
      gCommunity = _strdup(optionValue);
      break;
    }
    
    case 'o':
    case 'O':
    {
      gSenderOID = _strdup(optionValue);
      break;
    }
    
    case 'i':
    case 'I':
    {
      gSenderIP = _strdup(optionValue);
      break;
    }

    case 'l':
    case 'L':
    {
      gLogFileName = _strdup(optionValue);
      break;
    }

    case 'm':
    case 'M':
    {
      gTimeout = atoi(optionValue);
      break;
    }
    
    case 'g':
    case 'G':
    {
      gGenericTrapType = atoi(optionValue);
      break;
    }
    
    case 'p':
    case 'P':
    {
      gDump = *optionValue;
      break;
    }

    case 'r':
    case 'R':
    {
      gRequestId = atoi(optionValue);
      break;
    }


    case 's':
    case 'S':
    {
      gSpecificTrapType = atoi(optionValue);
      break;
    }
    
    case 't':
    case 'T':
//.........这里部分代码省略.........
开发者ID:bigmacd,项目名称:trapgen,代码行数:101,代码来源:TrapGen.cpp

示例2: tokens

// this function does not send events
bool
Connection::ReceiveHandShake()
{
	// TODO check the banned list!

	/*
	Get the SYN or JOIN packet.
	*/
	Packet* rcv;
	if (!Receive(rcv) || rcv == 0)
	{
	   LogError(wxString().Format(wxT("Receive failed on incomming con id %d"), id_));
		return FALSE;
	}

	switch(rcv->Type())
	{
	// node is a network node and wants to handshake
	case Packet::TYPE_SYN:
	{

#ifdef ENABLE_ENCRYPTION
		rsaPub_ = rcv->Get(Packet::HEADER_PUBLIC_KEY);

		if (rsaPub_ == wxT(""))
		{
		   LogError(wxString().Format(wxT("Got empty RSA public key on incomming con id %d"), id_));
			return false;
		}
#endif

		delete rcv;

#ifdef ENABLE_ENCRYPTION
		/*
		Init encryption.
		*/
		symetric_->Init(crypto::RandomString().c_str()/*,(unsigned char*)"blah"*/);
#endif
		/*
		Send the ACK packet.
		*/
#ifdef ENABLE_ENCRYPTION
		Packet snd = GenPacket_Ack(wxString(symetric_->Key().c_str()),wxString(socket_->GetPeerHost().c_str()));
#else
		Packet snd = GenPacket_Ack(wxString(),wxString(socket_->GetPeerHost().c_str()));
#endif
		if (!Send(snd))
		{
		   LogError(wxString().Format(wxT("ACK send failed on incomming con id %d"),id_));
			return FALSE;
		}

		if (!Receive(rcv) || rcv == 0)
		{
		   LogError(wxString().Format(wxT("Receive confirm packet failed on incomming con id %d"), id_));
			return FALSE;
		}

		if (rcv->Type() != Packet::TYPE_CONFIRM)
		{
		   LogError(wxString().Format(wxT("Did not get confirm packet on incomming con id %d, got packet type %d instead"), id_,rcv->Type()));
			return FALSE;
		}

		// TODO get the correct hostname if none is supplied
		currentAddr_ = rcv->Get(Packet::HEADER_SRC_ADDR);

		currentNid_ = rcv->Get(Packet::HEADER_SRC_NID);
		wxString wrkGrpKey = rcv->Get(Packet::HEADER_WRKGRPKEY);
		Network::Instance()->SetGateway(rcv->Get(Packet::HEADER_DEST_HOST));

		if (Prefs::Instance()->Get(Prefs::WRKGRPKEY) != wxT("")
			&&
			wrkGrpKey != Prefs::Instance()->Get(Prefs::WRKGRPKEY))
		{
		   LogError(wxString().Format(wxT("Node tried to connect with invalid workgroup %s key on incomming con id %d packet: %s"), wrkGrpKey.c_str(),id_,rcv->Raw()));
			delete rcv;
			return FALSE;
		}


		if (currentAddr_ == wxT("") || currentNid_ == wxT(""))
		{
		   LogError(wxString().Format(wxT("(3) Blank address or nid from node when trying to handshake on con id %d"),id_));
			delete rcv;
			return FALSE;
		}

		delete rcv;

		/*
		Now that handshaking is out of the way, lets figure out what this node wants.
		*/
		if (!Receive(rcv) || rcv == 0)
		{
		   LogError(wxString().Format(wxT("Receive failed on incomming con id %d"), id_));
			return FALSE;
		}
//.........这里部分代码省略.........
开发者ID:digitalpeer,项目名称:turnstile,代码行数:101,代码来源:connection.cpp


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