Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
rcdiscover::SocketLinux Class Reference

Socket implementation for Linux. More...

#include <socket_linux.h>

Inheritance diagram for rcdiscover::SocketLinux:
Inheritance graph
[legend]

Public Types

typedef int SocketType
 Type representing the native socket handle type. More...
 

Public Member Functions

const sockaddr_in & getDestSockAddr () const
 Returns the sockaddr to which the socket is bound. More...
 
SocketLinuxoperator= (SocketLinux &&other)
 
 SocketLinux (int domain, int type, int protocol, in_addr_t dst_ip, uint16_t port, std::string iface_name)
 Constructor. More...
 
 SocketLinux (SocketLinux &&other)
 
 ~SocketLinux ()
 
- Public Member Functions inherited from rcdiscover::Socket< SocketLinux >
void bind (const sockaddr_in &addr)
 Binds the socket to an interface. More...
 
void enableBroadcast ()
 Enables broadcast for this socket. More...
 
void enableNonBlocking ()
 Enables non-blocking operation for this socket. More...
 
const T & getHandle () const
 Returns the native socket handle. More...
 
const std::string & getIfaceName () const
 Returns the interface name. More...
 
Socketoperator= (const Socket &)=delete
 
Socketoperator= (Socket &&)=default
 
void send (const std::vector< uint8_t > &sendbuf)
 Sends data. More...
 
 Socket (std::string iface_name)
 
 Socket (const Socket &)=delete
 
 Socket (Socket &&)=default
 

Static Public Member Functions

static SocketLinux create (in_addr_t dst_ip, uint16_t port, std::string iface_name)
 Create a new socket. More...
 
static std::vector< SocketLinuxcreateAndBindForAllInterfaces (uint16_t port)
 Creates sockets for all interfaces and binds them to the respective interface. More...
 
static const in_addr_t & getBroadcastAddr ()
 Returns the broadcast address. More...
 

Protected Member Functions

void bindImpl (const sockaddr_in &addr)
 Binds the socket to a specific sockaddr. More...
 
void enableBroadcastImpl ()
 Enables broadcast for this socket. More...
 
void enableNonBlockingImpl ()
 Enables non-blocking operation for this socket. More...
 
const int & getHandleImpl () const
 Returns the native socket handle. More...
 
void sendImpl (const std::vector< uint8_t > &sendbuf)
 Sends data. More...
 

Private Member Functions

void bindToDevice (const std::string &device)
 Binds this socket to a specific device (root privileges are required). More...
 

Private Attributes

sockaddr_in dst_addr_
 
int sock_
 

Friends

class Socket< SocketLinux >
 

Detailed Description

Socket implementation for Linux.

Definition at line 51 of file socket_linux.h.

Member Typedef Documentation

Type representing the native socket handle type.

Definition at line 59 of file socket_linux.h.

Constructor & Destructor Documentation

rcdiscover::SocketLinux::SocketLinux ( int  domain,
int  type,
int  protocol,
in_addr_t  dst_ip,
uint16_t  port,
std::string  iface_name 
)

Constructor.

Parameters
domaindomain of socket()
typetype of socket()
protocolprotocol of socket()
dst_ipdestination IP address
portdestination port
iface_namename of the interface

Definition at line 162 of file socket_linux.cc.

rcdiscover::SocketLinux::SocketLinux ( SocketLinux &&  other)

Definition at line 195 of file socket_linux.cc.

rcdiscover::SocketLinux::~SocketLinux ( )

Definition at line 209 of file socket_linux.cc.

Member Function Documentation

void rcdiscover::SocketLinux::bindImpl ( const sockaddr_in &  addr)
protected

Binds the socket to a specific sockaddr.

Parameters
addrsockaddr_in to which to bind the socket

Definition at line 222 of file socket_linux.cc.

void rcdiscover::SocketLinux::bindToDevice ( const std::string &  device)
private

Binds this socket to a specific device (root privileges are required).

Parameters
devicedevice name to bind the socket to
Exceptions
OperationNotPermittedin case this function is called without root privileges

Definition at line 273 of file socket_linux.cc.

SocketLinux rcdiscover::SocketLinux::create ( in_addr_t  dst_ip,
uint16_t  port,
std::string  iface_name 
)
static

Create a new socket.

Parameters
dst_ipdestination IP address
portdestination port
iface_namename of the interface
Returns
the created socket

Definition at line 69 of file socket_linux.cc.

std::vector< SocketLinux > rcdiscover::SocketLinux::createAndBindForAllInterfaces ( uint16_t  port)
static

Creates sockets for all interfaces and binds them to the respective interface.

Parameters
portdestination port
Returns
vector of sockets

Definition at line 76 of file socket_linux.cc.

void rcdiscover::SocketLinux::enableBroadcastImpl ( )
protected

Enables broadcast for this socket.

Definition at line 251 of file socket_linux.cc.

void rcdiscover::SocketLinux::enableNonBlockingImpl ( )
protected

Enables non-blocking operation for this socket.

Definition at line 264 of file socket_linux.cc.

const in_addr_t & rcdiscover::SocketLinux::getBroadcastAddr ( )
static

Returns the broadcast address.

Returns
broadcast address

Definition at line 58 of file socket_linux.cc.

const sockaddr_in & rcdiscover::SocketLinux::getDestSockAddr ( ) const

Returns the sockaddr to which the socket is bound.

Returns
sockaddr to which the socket is bound.

Definition at line 64 of file socket_linux.cc.

const int & rcdiscover::SocketLinux::getHandleImpl ( ) const
protected

Returns the native socket handle.

Returns
native socket handle.

Definition at line 217 of file socket_linux.cc.

SocketLinux & rcdiscover::SocketLinux::operator= ( SocketLinux &&  other)

Definition at line 203 of file socket_linux.cc.

void rcdiscover::SocketLinux::sendImpl ( const std::vector< uint8_t > &  sendbuf)
protected

Sends data.

Parameters
sendbufdata buffer

Definition at line 232 of file socket_linux.cc.

Friends And Related Function Documentation

friend class Socket< SocketLinux >
friend

Definition at line 53 of file socket_linux.h.

Member Data Documentation

sockaddr_in rcdiscover::SocketLinux::dst_addr_
private

Definition at line 148 of file socket_linux.h.

int rcdiscover::SocketLinux::sock_
private

Definition at line 147 of file socket_linux.h.


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


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Sun Apr 18 2021 02:16:32