コード例 #1
0
ファイル: normalize.cpp プロジェクト: byllyfish/libofp
void Normalize::normalizeMPPortDescReplyV4() {
  using deprecated::PortV2;

  // Verify size of port list.
  size_t portListSize = buf_.size() - sizeof(MultipartReply);
  if ((portListSize % sizeof(PortV2)) != 0) {
    markInputInvalid("MultipartReply.PortDesc has invalid size");
    return;
  }

  // Normalize the port structures from V2 to normal size.
  size_t portCount = portListSize / sizeof(PortV2);
  UInt8 *pkt = buf_.mutableData();
  const PortV2 *portV2 =
      reinterpret_cast<const PortV2 *>(pkt + sizeof(MultipartReply));

  PortList ports;
  for (size_t i = 0; i < portCount; ++i) {
    PortBuilder newPort{*portV2};
    ports.add(newPort);
    ++portV2;
  }

  // Copy new port list into packet.
  buf_.addUninitialized(ports.size() - portListSize);
  pkt = buf_.mutableData();
  assert(buf_.size() == sizeof(MultipartReply) + ports.size());
  std::memcpy(pkt + sizeof(MultipartReply), ports.data(), ports.size());
}
コード例 #2
0
ファイル: normalize.cpp プロジェクト: byllyfish/libofp
void Normalize::normalizeFeaturesReplyV1() {
  using deprecated::PortV1;

  Header *hdr = header();

  // Check minimum size requirement.
  if (hdr->length() < sizeof(FeaturesReply)) {
    markInputInvalid("FeaturesReply is too short");
    return;
  }

  // Verify size of port list.
  size_t portListSize = hdr->length() - sizeof(FeaturesReply);
  if ((portListSize % sizeof(PortV1)) != 0) {
    markInputInvalid("FeaturesReply has invalid port list size");
    return;
  }

  // Normalize the port structures from V1 to normal size.
  size_t portCount = portListSize / sizeof(PortV1);
  UInt8 *pkt = buf_.mutableData();
  const PortV1 *portV1 =
      reinterpret_cast<const PortV1 *>(pkt + sizeof(FeaturesReply));

  PortList ports;
  for (size_t i = 0; i < portCount; ++i) {
    PortBuilder newPort{*portV1};
    ports.add(newPort);
    ++portV1;
  }

  if (ports.size() > 65535 - sizeof(FeaturesReply)) {
    markInputTooBig("FeaturesReply has too many ports");
    return;
  }

  // Copy new port list into packet.
  buf_.addUninitialized(ports.size() - portListSize);
  pkt = buf_.mutableData();
  assert(buf_.size() == sizeof(FeaturesReply) + ports.size());
  std::memcpy(pkt + sizeof(FeaturesReply), ports.data(), ports.size());
}