SatCat5
hal_pcap.h
Go to the documentation of this file.
1 // Copyright 2021-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
22 
23 #pragma once
24 
25 #include <deque>
26 #include <string>
27 #include <satcat5/ethernet.h>
28 #include <satcat5/io_buffer.h>
29 #include <satcat5/polling.h>
30 
31 namespace satcat5 {
32  namespace pcap {
34  struct Device;
35 
37  class Socket
39  , protected satcat5::poll::Always
40  {
41  public:
50  explicit Socket(
51  const char* ifname,
52  unsigned bsize=65536,
53  satcat5::eth::MacType filter = satcat5::eth::ETYPE_NONE);
54  virtual ~Socket();
55 
57  bool ok() const;
58 
59  // Other useful info.
60  const char* name() const;
61  const char* desc() const;
62 
63  protected:
64  void data_rcvd(satcat5::io::Readable* src) override;
65  void poll_always() override;
66 
67  satcat5::pcap::Device* const m_device;
68  };
69 
72  struct Descriptor {
73  Descriptor(const char* n, const char* d);
74 
75  std::string name;
76  std::string desc;
77  };
78  typedef std::deque<satcat5::pcap::Descriptor> DescriptorList;
79 
82  satcat5::pcap::DescriptorList list_all_devices();
83 
85  bool is_device(const char* ifname);
86 
90  std::string prompt_for_ifname();
91  }
92 }
Extensible transmit and receive buffer.
Definition: io_buffer.h:42
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Adapter for a PCAP Layer-2 socket.
Definition: hal_pcap.h:40
const char * name() const
Unique interface ID.
Definition: hal_pcap.cc:229
Socket(const char *ifname, unsigned bsize=65536, satcat5::eth::MacType filter=satcat5::eth::ETYPE_NONE)
Open the specified interface by name.
Definition: hal_pcap.cc:206
void poll_always() override
Child class MUST override this method.
Definition: hal_pcap.cc:257
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
Definition: hal_pcap.cc:237
bool ok() const
Is the socket in a usable state?
Definition: hal_pcap.cc:225
const char * desc() const
Human-readable name.
Definition: hal_pcap.cc:233
An "Always" object is polled whenever service() is called.
Definition: polling.h:96
bool is_device(const char *ifname)
Check if a given name is on the list from list_all_devices.
Definition: hal_pcap.cc:119
std::string prompt_for_ifname()
Print a list of Ethernet devices, and select by index.
Definition: hal_pcap.cc:131
satcat5::pcap::DescriptorList list_all_devices()
Fetch a list of Ethernet device descriptors.
Definition: hal_pcap.cc:103
Buffered I/O wrappers for PacketBuffer.
Core event-processing loop for SatCat5 software.
EtherType field (uint16) is used a protocol-ID [1536..65535].
Definition: eth_header.h:96
Structure for holding a device-name and user-readable description.
Definition: hal_pcap.h:72
std::string name
Unique interface ID.
Definition: hal_pcap.h:75
std::string desc
Human-readable name.
Definition: hal_pcap.h:76