Example #1
0
  Status comparePackets(std::unique_ptr<PcapPacket> p1, std::unique_ptr<PcapPacket> p2) {
    unsigned p1len = p1->getLength();
    unsigned p2len = p2->getLength();

    if (p1len != p2len)
      return this->reportDifference(std::string("Packet with index ") + std::to_string(this->packetIndex) + " differs in length");
    const char* p1d = p1->getData();
    const char* p2d = p2->getData();

    int cmp = memcmp(p1d, p2d, p1len);
    if (cmp != 0) {
      return this->reportDifference(std::string("Packet with index ") + std::to_string(this->packetIndex) + " differs ");
    }

    return Status::OK;
  }
    sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
                                           const SkFontArguments& args) const override {
        using Scanner = SkTypeface_FreeType::Scanner;
        const size_t length = stream->getLength();
        if (!length) {
            return nullptr;
        }
        if (length >= 1024 * 1024 * 1024) {
            return nullptr;  // don't accept too large fonts (>= 1GB) for safety.
        }

        bool isFixedPitch;
        SkFontStyle style;
        SkString name;
        Scanner::AxisDefinitions axisDefinitions;
        if (!fScanner.scanFont(stream.get(), args.getCollectionIndex(),
                               &name, &style, &isFixedPitch, &axisDefinitions))
        {
            return nullptr;
        }

        SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
        Scanner::computeAxisValues(axisDefinitions, args.getVariationDesignPosition(),
                                   axisValues, name);

        auto fontData = skstd::make_unique<SkFontData>(std::move(stream),
                                                       args.getCollectionIndex(),
                                                       axisValues.get(),
                                                       axisDefinitions.count());
        return sk_sp<SkTypeface>(SkTypeface_FCI::Create(std::move(fontData), std::move(name),
                                                        style, isFixedPitch));
    }
Example #3
0
// if possible, make no copy.
static sk_sp<SkData> stream_to_data(std::unique_ptr<SkStreamAsset> stream) {
    SkASSERT(stream);
    (void)stream->rewind();
    SkASSERT(stream->hasLength());
    size_t size = stream->getLength();
    if (const void* base = stream->getMemoryBase()) {
        SkData::ReleaseProc proc =
            [](const void*, void* ctx) { delete (SkStreamAsset*)ctx; };
        return SkData::MakeWithProc(base, size, proc, stream.release());
    }
    return SkData::MakeFromStream(stream.get(), size);
}
Example #4
0
CGDataProviderRef SkCreateDataProviderFromStream(std::unique_ptr<SkStreamRewindable> stream) {
    // TODO: Replace with SkStream::getData() when that is added. Then we only
    // have one version of CGDataProviderCreateWithData (i.e. same release proc)
    const void* addr = stream->getMemoryBase();
    if (addr) {
        // special-case when the stream is just a block of ram
        size_t size = stream->getLength();
        return CGDataProviderCreateWithData(stream.release(), addr, size, delete_stream_proc);
    }

    CGDataProviderSequentialCallbacks rec;
    sk_bzero(&rec, sizeof(rec));
    rec.version = 0;
    rec.getBytes = get_bytes_proc;
    rec.skipForward = skip_forward_proc;
    rec.rewind = rewind_proc;
    rec.releaseInfo = release_info_proc;
    return CGDataProviderCreateSequential(stream.release(), &rec);
}
    sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
                                            int ttcIndex) const override {
        const size_t length = stream->getLength();
        if (!length) {
            return nullptr;
        }
        if (length >= 1024 * 1024 * 1024) {
            return nullptr;  // don't accept too large fonts (>= 1GB) for safety.
        }

        // TODO should the caller give us the style or should we get it from freetype?
        SkString name;
        SkFontStyle style;
        bool isFixedPitch = false;
        if (!fScanner.scanFont(stream.get(), 0, &name, &style, &isFixedPitch, nullptr)) {
            return nullptr;
        }

        auto fontData = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
        return sk_sp<SkTypeface>(SkTypeface_FCI::Create(std::move(fontData), std::move(name),
                                                        style, isFixedPitch));
    }
Example #6
0
void SwSwitch::handlePacket(std::unique_ptr<RxPacket> pkt) {
  // If we are not fully initialized or are already exiting, don't handle
  // packets since the individual handlers, h/w sdk data structures
  // may not be ready or may already be (partially) destroyed
  if (!isFullyInitialized()) {
    return;
  }
  PortID port = pkt->getSrcPort();
  stats()->port(port)->trappedPkt();

  pcapMgr_->packetReceived(pkt.get());

  // The minimum required frame length for ethernet is 64 bytes.
  // Abort processing early if the packet is too short.
  auto len = pkt->getLength();
  if (len < 64) {
    stats()->port(port)->pktBogus();
    return;
  }

  // Parse the source and destination MAC, as well as the ethertype.
  Cursor c(pkt->buf());
  auto dstMac = PktUtil::readMac(&c);
  auto srcMac = PktUtil::readMac(&c);
  auto ethertype = c.readBE<uint16_t>();
  if (ethertype == 0x8100) {
    // 802.1Q
    c += 2; // Advance over the VLAN tag.  We ignore it for now
    ethertype = c.readBE<uint16_t>();
  }

  VLOG(5) << "trapped packet: src_port=" << pkt->getSrcPort() <<
    " vlan=" << pkt->getSrcVlan() <<
    " length=" << len <<
    " src=" << srcMac <<
    " dst=" << dstMac <<
    " ethertype=0x" << std::hex << ethertype <<
    " :: " << pkt->describeDetails();

  switch (ethertype) {
  case ArpHandler::ETHERTYPE_ARP:
    arp_->handlePacket(std::move(pkt), dstMac, srcMac, c);
    return;
  case LldpManager::ETHERTYPE_LLDP:
    if (lldpManager_) {
      lldpManager_->handlePacket(std::move(pkt), dstMac, srcMac, c);
      return;
    }
    break;
  case IPv4Handler::ETHERTYPE_IPV4:
    ipv4_->handlePacket(std::move(pkt), dstMac, srcMac, c);
    return;
  case IPv6Handler::ETHERTYPE_IPV6:
    ipv6_->handlePacket(std::move(pkt), dstMac, srcMac, c);
    return;
  default:
    break;
  }

  // If we are still here, we don't know what to do with this packet.
  // Increment a counter and just drop the packet on the floor.
  stats()->port(port)->pktUnhandled();
}
Example #7
0
File: main.cpp Project: CCJY/coliru
int IP::getLength() const
{
    return mImpl->getLength();
}