diff --git a/src/iosource/Component.cc b/src/iosource/Component.cc index f54c212352..20232161cd 100644 --- a/src/iosource/Component.cc +++ b/src/iosource/Component.cc @@ -64,10 +64,9 @@ PktSrcComponent::factory_callback PktSrcComponent::Factory() const return factory; } - -void PktSrcComponent::Describe(ODesc* d) const +void PktSrcComponent::DoDescribe(ODesc* d) const { - iosource::Component::Describe(d); + iosource::Component::DoDescribe(d); string prefs; @@ -77,16 +76,16 @@ void PktSrcComponent::Describe(ODesc* d) const if ( prefs.size() ) prefs += ", "; - prefs += *i; + prefs += '"' + *i + '"'; } - d->Add(" (interface prefix"); + d->Add("interface prefix"); if ( prefixes.size() > 1 ) d->Add("es"); - d->Add(": "); + d->Add(" "); d->Add(prefs); - d->Add("; "); + d->Add("; supports "); switch ( type ) { case LIVE: @@ -105,7 +104,6 @@ void PktSrcComponent::Describe(ODesc* d) const reporter->InternalError("unknown PkrSrc type"); } - d->Add(")"); } PktDumperComponent::PktDumperComponent(const std::string& name, const std::string& arg_prefix, factory_callback arg_factory) @@ -141,9 +139,9 @@ bool PktDumperComponent::HandlesPrefix(const string& prefix) const return false; } -void PktDumperComponent::Describe(ODesc* d) const +void PktDumperComponent::DoDescribe(ODesc* d) const { - plugin::Component::Describe(d); + plugin::Component::DoDescribe(d); string prefs; @@ -156,12 +154,11 @@ void PktDumperComponent::Describe(ODesc* d) const prefs += *i; } - d->Add(" (dumper prefix"); + d->Add("dumper prefix"); if ( prefixes.size() > 1 ) d->Add("es"); d->Add(": "); d->Add(prefs); - d->Add(")"); } diff --git a/src/iosource/Component.h b/src/iosource/Component.h index cef500e52f..35e8f612e6 100644 --- a/src/iosource/Component.h +++ b/src/iosource/Component.h @@ -93,7 +93,7 @@ public: * Generates a human-readable description of the component. This goes * into the output of \c "bro -NN". */ - virtual void Describe(ODesc* d) const; + virtual void DoDescribe(ODesc* d) const; private: std::vector prefixes; @@ -140,7 +140,7 @@ public: * Generates a human-readable description of the component. This goes * into the output of \c "bro -NN". */ - virtual void Describe(ODesc* d) const; + virtual void DoDescribe(ODesc* d) const; private: std::vector prefixes; diff --git a/src/iosource/PktSrc.cc b/src/iosource/PktSrc.cc index acde8d5ff6..902aaa04be 100644 --- a/src/iosource/PktSrc.cc +++ b/src/iosource/PktSrc.cc @@ -89,6 +89,16 @@ double PktSrc::CurrentPacketWallClock() void PktSrc::Opened(const Properties& arg_props) { + if ( arg_props.hdr_size < 0 ) + { + char buf[512]; + safe_snprintf(buf, sizeof(buf), + "unknown data link type 0x%x", props.link_type); + Error(buf); + Close(); + return; + } + props = arg_props; SetClosed(false); @@ -98,6 +108,9 @@ void PktSrc::Opened(const Properties& arg_props) return; } + if ( props.is_live ) + Info(fmt("listening on %s, capture length %d bytes\n", props.path.c_str(), SnapLen())); + DBG_LOG(DBG_PKTIO, "Opened source %s", props.path.c_str()); } @@ -433,6 +446,9 @@ bool PktSrc::ExtractNextPacketInternal() bool PktSrc::PrecompileBPFFilter(int index, const std::string& filter) { + if ( index < 0 ) + return false; + char errbuf[PCAP_ERRBUF_SIZE]; // Compile filter. @@ -465,6 +481,9 @@ bool PktSrc::PrecompileBPFFilter(int index, const std::string& filter) BPF_Program* PktSrc::GetBPFFilter(int index) { + if ( index < 0 ) + return 0; + HashKey* hash = new HashKey(HashKey(bro_int_t(index))); BPF_Program* code = filters.Lookup(hash); delete hash; diff --git a/src/iosource/pcap/Source.cc b/src/iosource/pcap/Source.cc index 7cca94122b..96e0bb48e5 100644 --- a/src/iosource/pcap/Source.cc +++ b/src/iosource/pcap/Source.cc @@ -108,9 +108,8 @@ void PcapSource::OpenLive() return; props.is_live = true; - Opened(props); - Info(fmt("listening on %s, capture length %d bytes\n", props.path.c_str(), SnapLen())); + Opened(props); } void PcapSource::OpenOffline() @@ -264,14 +263,6 @@ void PcapSource::SetHdrSize() props.link_type = pcap_datalink(pd); props.hdr_size = GetLinkHeaderSize(props.link_type); - - if ( props.hdr_size < 0 ) - { - safe_snprintf(errbuf, sizeof(errbuf), - "unknown data link type 0x%x", props.link_type); - Error(errbuf); - Close(); - } } iosource::PktSrc* PcapSource::Instantiate(const std::string& path, bool is_live)