senf::PacketSocketProtocol Class Reference
[Protocol Implementations (Concrete Protocol Classes)]

Raw Packet-Socket access (Linux). More...

#include <senf/Socket/Protocols/Raw/PacketSocketHandle.hh>

Inheritance diagram for senf::PacketSocketProtocol:
Inheritance graph
[legend]

List of all members.


Detailed Description

Raw Packet-Socket access (Linux).
Socket Handle typedefs:
PacketSocketHandle (ProtocolClientSocketHandle)
Policy Interface:
ClientSocketHandle::read(), ClientSocketHandle::readfrom(), ClientSocketHandle::writeto(), ClientSocketHandle::bind(), ClientSocketHandle::local()
Address Type:
LLSocketAddress
The PacketSocketProtocol provides access to the linux packet socket API. This API gives access to the low level network packets. The packet socket allows read() and write() operations. The PacketSocketProtocol has no concept of a server socket.

This class is utilized as the protocol class of the ProtocolClientSocketHandle via the Socket Handle typedefs above.

Definition at line 77 of file PacketSocketHandle.hh.


Public Types

enum   SocketType { RawSocket, DatagramSocket }

Constructors

void  init_client (SocketType type=RawSocket, int protocol=-1) const
  Create packet socket.

Protocol Interface

void  mcAdd (std::string const &interface, MACAddress const &address) const
  Enable reception of a multicast group.
void  mcDrop (std::string const &interface, MACAddress const &address) const
  Disable reception of a multicast group.
void  promisc (std::string const &interface, bool mode) const
  enable/disable promiscuous mode

Abstract Interface Implementation

unsigned  available () const
  Return (maximum) number of bytes available for reading < without < blocking.
bool  eof () const
  Check for end-of-file condition.

Member Enumeration Documentation

enum senf::PacketSocketProtocol::
SocketType
Enumerator:
RawSocket 
DatagramSocket 

Definition at line 83 of file PacketSocketHandle.hh.


Member Function Documentation

unsigned senf::PacketSocketProtocol::
available ()

Return (maximum) number of bytes available for reading < without < blocking.

This member will check in a (very, sigh) protocol dependent way, how many bytes may be read from a socket in a single (non-blocking) read operation. If the socket does not support reading (viz. NotReadablePolicy is set), this member should always return 0.

Depending on the protocol, it may not be possible to return a good value. In this case, an upper bound may be returned (e.g.: When reading from a socket which returns ethernet frames, returning 1500 from available() is ok). However, this should only be done as a last resort. Also beware, that this number should not be too large since the socket layer will always need to allocate that number of bytes for the data to be read.

Implements senf::SocketProtocol.

Definition at line 57 of file PacketSocketHandle.cc.

bool senf::PacketSocketProtocol::
eof ()

Check for end-of-file condition.

This is another check which (like available()) is extremely protocol dependent. This member will return true only, if at end-of-file. If the protocol does not support the notion of EOF, this member should always return false.

Implements senf::SocketProtocol.

Definition at line 68 of file PacketSocketHandle.cc.

void senf::PacketSocketProtocol::
init_client ( SocketType  type = RawSocket,
int  protocol = -1 )

Create packet socket.

The new socket will receive all packets of the given IEEE 802.3 protocol. The socket will receive all packets, if protocol is -1.

If type is RawSocket, the packet will include the link-level header (the Ethernet header). Sent packets must already include a well formed ll header.

If type is DatagramSocket, the link level header will not be part of the packet data. The ll header will be removed from received packets and a correct ll header will be created on sent packets.

Parameters:
[in]  type  socket type
[in]  protocol  IEEE 802.3 protocol number
Note:
This member is implicitly called from the ProtocolClientSocketHandle::ProtocolClientSocketHandle() constructor

Definition at line 43 of file PacketSocketHandle.cc.

void senf::PacketSocketProtocol::
mcAdd ( std::string const &  interface,
MACAddress const &  address )

Enable reception of a multicast group.

mcAdd will join a new multicast group.

Parameters:
[in]  interface  interface with which to join
[in]  address  multicast address to join
See also:
LLSocketAddress

Definition at line 93 of file PacketSocketHandle.cc.

void senf::PacketSocketProtocol::
mcDrop ( std::string const &  interface,
MACAddress const &  address )

Disable reception of a multicast group.

See also:
mcAdd()

Definition at line 100 of file PacketSocketHandle.cc.

void senf::PacketSocketProtocol::
promisc ( std::string const &  interface,
bool  mode )

enable/disable promiscuous mode

Definition at line 107 of file PacketSocketHandle.cc.


The documentation for this class was generated from the following files: