예제 #1
0
/*!
    This property holds the message content.

    \par Access function:
    \li QString <b>content</b>() const
 */
QString IrcNoticeMessage::content() const
{
    Q_D(const IrcMessage);
    QString msg = d->param(1);
    if (flags() & (Identified | Unidentified))
        msg.remove(0, 1);
    if (isReply()) {
        msg.remove(0, 1);
        msg.chop(1);
    }
    return msg;
}
예제 #2
0
void CEtherArpHandler::handle(CSmartPtr<CMsgQueue>& queue)
{
    LOG_INFO_FMT("%s recv new msg ..., queue size = %lu", toString().c_str(), queue->size());

    CSmartPtr<CMsg> msg;
    while (queue->try_pop(msg))
    {
    	INT4 sockfd = msg->getSockfd();
    	const CSmartPtr<CSwitch>& srcSw = CServer::getInstance()->getSwitchMgr()->findSwBySockFd(sockfd);

    	// 获取packetin 信息
    	packet_in_info_t* packetIn = msg->getPacketIn();
    	arp_t* pkt = (arp_t*)packetIn->data;

		// 保存源主机信息
		CHost* srcHost = CHostMgr::getInstance()->addHost(srcSw, 0, packetIn->inport, pkt->sendmac, pkt->sendip);

		// 查找目标主机
		CHost* dstHost = CHostMgr::getInstance()->findHostByIp(pkt->targetip);

		// 如果源主机和目标主机都存在
		if ((NULL != srcHost) && (NULL != dstHost))
		{
		    arp_t arp_pkt;

			// 如果是Arp Request
			if (isRequest(pkt))
			{
				LOG_INFO("Create Arp Reply");
				// 创建Arp Reply回应报文并且转发
				create_arp_reply_pkt(&arp_pkt, srcHost, dstHost);
				forward(srcSw, srcHost->getPortNo(), sizeof(arp_pkt), &arp_pkt);
			}

			// 如果是Arp Reply
			if (isReply(pkt))
			{
				LOG_INFO("forward Arp Reply");
				// 转发Arp Reply回应报文
				forward(dstHost->getSw(), dstHost->getPortNo(),  sizeof(arp_pkt), &arp_pkt);
			}
		}
		// 如果不存在
		else
		{
			LOG_INFO("flood Arp request");
			// 将这个包广播
			// flood(packetIn);
		}
		
		
    }
}
예제 #3
0
/*!
    This property holds the message.

    \par Access functions:
    \li QString <b>message</b>() const
 */
QString IrcNoticeMessage::message() const
{
    Q_D(const IrcMessage);
    QString msg = d->decodeParam(1);
    if (d->flags & (Identified | Unidentified))
        msg.remove(0, 1);
    if (isReply())
    {
        msg.remove(0, 1);
        msg.chop(1);
    }
    return msg;
}
예제 #4
0
파일: packet-lsc.c 프로젝트: flaub/HotFuzz
/* Code to actually dissect the packets */
static void
dissect_lsc_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  proto_item *ti;
  proto_tree *lsc_tree;
  guint8 op_code;
  guint32 stream;
  guint expected_len;

  /* Protocol is LSC, packet summary is not yet known */
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "LSC");
  col_clear(pinfo->cinfo, COL_INFO);

  /* Too little data? */
  if (tvb->length < LSC_MIN_LEN)
  {
    col_set_str(pinfo->cinfo, COL_INFO, "[Too short]");
    return;
  }

  /* Get the op code */
  op_code = tvb_get_guint8(tvb, 2);
  /* And the stream handle */
  stream = tvb_get_ntohl(tvb, 4);

  /* Check the data length against what we actually received */
  switch (op_code)
    {
      case LSC_PAUSE:
        expected_len = LSC_PAUSE_LEN;
        break;
      case LSC_RESUME:
        expected_len = LSC_RESUME_LEN;
        break;
      case LSC_STATUS:
        expected_len = LSC_STATUS_LEN;
        break;
      case LSC_RESET:
        expected_len = LSC_RESET_LEN;
        break;
      case LSC_JUMP:
        expected_len = LSC_JUMP_LEN;
        break;
      case LSC_PLAY:
        expected_len = LSC_PLAY_LEN;
        break;
      case LSC_DONE:
      case LSC_PAUSE_REPLY:
      case LSC_RESUME_REPLY:
      case LSC_STATUS_REPLY:
      case LSC_RESET_REPLY:
      case LSC_JUMP_REPLY:
      case LSC_PLAY_REPLY:
        expected_len = LSC_REPLY_LEN;
        break;
      default:
        /* Unrecognized op code */
        expected_len = LSC_MIN_LEN;
        break;
    }

  /* Display the op code in the summary */
  if (check_col(pinfo->cinfo, COL_INFO)) {
    col_add_fstr(pinfo->cinfo, COL_INFO, "%s, session %.8u",
                 val_to_str(op_code, op_code_vals, "Unknown op code (0x%x)"),
                 stream);

    if (tvb->length < expected_len)
      col_append_str(pinfo->cinfo, COL_INFO, " [Too short]");
    else if (tvb->length > expected_len)
      col_append_str(pinfo->cinfo, COL_INFO, " [Too long]");
  }

  if (tree) {
    /* Create display subtree for the protocol */
    ti = proto_tree_add_item(tree, proto_lsc, tvb, 0, -1, FALSE);
    lsc_tree = proto_item_add_subtree(ti, ett_lsc);

    /* Add already fetched items to the tree */
    proto_tree_add_uint(lsc_tree, hf_lsc_op_code, tvb, 2, 1, op_code);
    proto_tree_add_uint_format_value(lsc_tree, hf_lsc_stream_handle, tvb, 4, 4,
                                     stream, "%.8u", stream);

    /* Add rest of LSC header */
    proto_tree_add_uint(lsc_tree, hf_lsc_version, tvb, 0, 1,
                        tvb_get_guint8(tvb, 0));
    proto_tree_add_uint(lsc_tree, hf_lsc_trans_id, tvb, 1, 1,
                        tvb_get_guint8(tvb, 1));

    /* Only replies contain a status code */
    if (isReply(op_code))
      proto_tree_add_uint(lsc_tree, hf_lsc_status_code, tvb, 3, 1,
                          tvb_get_guint8(tvb, 3));

    /* Add op code specific parts */
    switch (op_code)
      {
        case LSC_PAUSE:
          proto_tree_add_int(lsc_tree, hf_lsc_stop_npt, tvb, 8, 4,
                             tvb_get_ntohl(tvb, 8));
          break;
        case LSC_RESUME:
          proto_tree_add_int(lsc_tree, hf_lsc_start_npt, tvb, 8, 4,
                             tvb_get_ntohl(tvb, 8));
          proto_tree_add_int(lsc_tree, hf_lsc_scale_num, tvb, 12, 2,
                             tvb_get_ntohs(tvb, 12));
          proto_tree_add_uint(lsc_tree, hf_lsc_scale_denom, tvb, 14, 2,
                              tvb_get_ntohs(tvb, 14));
          break;
        case LSC_JUMP:
        case LSC_PLAY:
          proto_tree_add_int(lsc_tree, hf_lsc_start_npt, tvb, 8, 4,
                             tvb_get_ntohl(tvb, 8));
          proto_tree_add_int(lsc_tree, hf_lsc_stop_npt, tvb, 12, 4,
                             tvb_get_ntohl(tvb, 12));
          proto_tree_add_int(lsc_tree, hf_lsc_scale_num, tvb, 16, 2,
                             tvb_get_ntohs(tvb, 16));
          proto_tree_add_uint(lsc_tree, hf_lsc_scale_denom, tvb, 18, 2,
                              tvb_get_ntohs(tvb, 18));
          break;
        case LSC_DONE:
        case LSC_PAUSE_REPLY:
        case LSC_RESUME_REPLY:
        case LSC_STATUS_REPLY:
        case LSC_RESET_REPLY:
        case LSC_JUMP_REPLY:
        case LSC_PLAY_REPLY:
          proto_tree_add_int(lsc_tree, hf_lsc_current_npt, tvb, 8, 4,
                             tvb_get_ntohl(tvb, 8));
          proto_tree_add_int(lsc_tree, hf_lsc_scale_num, tvb, 12, 2,
                             tvb_get_ntohs(tvb, 12));
          proto_tree_add_uint(lsc_tree, hf_lsc_scale_denom, tvb, 14, 2,
                              tvb_get_ntohs(tvb, 14));
          proto_tree_add_uint(lsc_tree, hf_lsc_mode, tvb, 16, 1,
                              tvb_get_guint8(tvb, 16));
          break;
        default:
          break;
      }
  }
}
예제 #5
0
int SIPMessage::replyCode() {
    if (!isReply())
        return 0;
    else
        return atoi( rline.c_str() + 8 );
}
예제 #6
0
bool SIPMessage::isRequest() {
    return !isReply();
}