|
PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
|
A minimal RAII wrapper around a Linux AF_PACKET raw socket bound to an interface. More...
#include <util.h>
Inheritance diagram for profinet::EthernetSocket:
Collaboration diagram for profinet::EthernetSocket:Public Member Functions | |
| EthernetSocket (const std::string &interface, std::uint16_t ethertype=0) | |
| Bind a raw socket to an interface. | |
| ~EthernetSocket () | |
| Close the underlying socket. | |
| EthernetSocket (const EthernetSocket &)=delete | |
| Not copyable (owns a raw socket file descriptor). | |
| EthernetSocket & | operator= (const EthernetSocket &)=delete |
| Not copyable (owns a raw socket file descriptor). | |
| EthernetSocket (EthernetSocket &&other) noexcept | |
| Move-construct, transferring ownership of the underlying socket. | |
| EthernetSocket & | operator= (EthernetSocket &&other) noexcept |
| Move-assign, transferring ownership of the underlying socket. | |
| void | Send (const std::vector< std::uint8_t > &frame) const override |
| Send a raw Ethernet frame. | |
| void | SetTimeout (std::chrono::milliseconds timeout) const override |
| Set the receive timeout. | |
| std::vector< std::uint8_t > | Recv () const override |
| Receive up to MAX_ETHERNET_FRAME bytes. | |
| int | Fd () const |
| The underlying file descriptor. | |
Public Member Functions inherited from profinet::IRawEthernetSocket | |
| virtual | ~IRawEthernetSocket ()=default |
| Virtual destructor for polymorphic use. | |
Private Attributes | |
| int | fd = -1 |
| Underlying socket file descriptor, or -1 if closed/moved-from. | |
A minimal RAII wrapper around a Linux AF_PACKET raw socket bound to an interface.
Mirrors util.py's ethernet_socket(). Uses ETH_P_ALL by default so VLAN-tagged responses (some devices, e.g. Siemens S7-1200, reply with an 802.1Q tag even to untagged requests) are still received.
|
explicit |
Bind a raw socket to an interface.
| interface | Interface name to bind to, e.g. "eth0". |
| ethertype | EtherType filter for received frames; 0 (default) means ETH_P_ALL. |
Throws PermissionDeniedError if not running with sufficient privilege, or SocketError on other failures.
Definition at line 295 of file util.cpp.
References profinet::ETH_P_ALL, and fd.
| profinet::EthernetSocket::~EthernetSocket | ( | ) |
|
delete |
Not copyable (owns a raw socket file descriptor).
|
noexcept |
|
inline |
|
delete |
Not copyable (owns a raw socket file descriptor).
|
noexcept |
|
overridevirtual |
Receive up to MAX_ETHERNET_FRAME bytes.
Implements profinet::IRawEthernetSocket.
Definition at line 386 of file util.cpp.
References fd, and profinet::MAX_ETHERNET_FRAME.
Referenced by profinet::dcp::ReadResponse(), and profinet::dcp::ReceiveHello().
Here is the caller graph for this function:
|
overridevirtual |
Send a raw Ethernet frame.
| frame | Complete frame bytes (destination MAC .. payload, no FCS). |
Implements profinet::IRawEthernetSocket.
Definition at line 366 of file util.cpp.
References fd.
Referenced by profinet::dcp::GetParam(), profinet::dcp::ResetToFactory(), profinet::dcp::SendDiscover(), profinet::dcp::SendHello(), profinet::dcp::SendRequest(), profinet::dcp::SetIp(), profinet::dcp::SetParam(), and profinet::dcp::SignalDevice().
Here is the caller graph for this function:
|
overridevirtual |
Set the receive timeout.
| timeout | Timeout duration; a zero duration blocks forever. |
Sets SO_RCVTIMEO. Marked const: this only changes a kernel-side socket option, not the object's own identity, which lets read-only call sites keep a const&.
Implements profinet::IRawEthernetSocket.
Definition at line 375 of file util.cpp.
References fd.
Referenced by profinet::dcp::ReadResponse(), and profinet::dcp::ReceiveHello().
Here is the caller graph for this function:
|
private |
Underlying socket file descriptor, or -1 if closed/moved-from.
Definition at line 248 of file util.h.
Referenced by EthernetSocket(), ~EthernetSocket(), Fd(), Recv(), Send(), and SetTimeout().