simple-socket library 1.2.0
NET Namespace Reference

Classes

struct  can_filter
 Structure of id and mask used by filters. More...
 
struct  can_frame
 Structure to represent a CAN 2.0 Frame. More...
 
struct  can_id
 Represents any possible CAN id or mask. More...
 
class  CANRawSocket
 Raw CAN socket class. More...
 
class  CANSocket
 CAN socket class. More...
 
class  InternetSocket
 Internet socket class. More...
 
class  SCTPSocket
 SCTP socket class. More...
 
class  SimpleSocket
 A socket representing a basic communication endpoint. More...
 
class  SocketException
 Signals a problem with the execution of a socket call. More...
 
class  SocketHandle
 A simple class to provide strict ownership of socket handles. More...
 
class  SocketHandle_Ref
 
class  TCPSocket
 TCP socket class. More...
 
class  UDPSocket
 UDP socket class. More...
 
class  UnixDatagramSocket
 Unix datagram socket class. More...
 
class  UnixSocket
 Unix domain socket class. More...
 

Functions

std::string getBroadcastAddress (std::string_view interface)
 Return the IPv4 broadcast address of the given network interface.
 
std::string getDestinationAddress (std::string_view interface)
 Return the IPv4 destination address of the given network interface.
 
std::string getHardwareAddress (std::string_view interface)
 Return the MAC address of the given network interfaces.
 
std::string getInterfaceAddress (std::string_view interface)
 Return the IPv4 address of the given network interface.
 
int getMTU (std::string_view interface)
 Return the MTU (Maximum Transmission Unit) of the given network interface in bytes.
 
std::string getNetmask (std::string_view interface)
 Return the IPv4 netmask of the given network interface.
 
std::vector< std::string > getNetworkInterfaces ()
 Return a list of available network interfaces.
 
std::string resolveHostname (const std::string &hostname)
 
uint16_t resolveService (const std::string &service, const std::string &protocol="tcp")
 
void setBroadcastAddress (std::string_view interface, std::string_view address)
 Set the IPv4 broadcast address of the given network interface.
 
void setDestinationAddress (std::string_view interface, std::string_view address)
 Set the IPv4 destination address of the given network interface.
 
void setInterfaceAddress (std::string_view interface, std::string_view address)
 Set the IPv4 address of the given network interface.
 
void setMTU (std::string_view interface, int mtu)
 Set the MTU (Maximum Transmission Unit) of the given network interface in bytes.
 
void setNetmask (std::string_view interface, std::string_view address)
 Set the IPv4 netmask of the given network interface.
 

Function Documentation

◆ resolveHostname()

std::string NET::resolveHostname ( const std::string & hostname)

Resolve the specified hostname to a standard IPv4 address. If the operating system doesn't know the hostname yet this means a DNS lookup.

Parameters
hostnamedomain name
Returns
resolved hostname as standard IPv4 address

Definition at line 53 of file SocketUtils.cpp.

◆ resolveService()

uint16_t NET::resolveService ( const std::string & service,
const std::string & protocol = "tcp" )

Resolve the specified service for the specified protocol to the corresponding port number in host byte order.

Parameters
serviceservice to resolve (e.g. "http")
protocolprotocol of service to resolve. Default is "tcp". To match to any protocol, pass an empty string ("").
Returns
port number fetched from the database. 0 if no match found.

Definition at line 68 of file SocketUtils.cpp.

◆ getNetworkInterfaces()

std::vector< std::string > NET::getNetworkInterfaces ( )

Return a list of available network interfaces.

Definition at line 98 of file SocketUtils.cpp.

◆ getInterfaceAddress()

std::string NET::getInterfaceAddress ( std::string_view interface)

Return the IPv4 address of the given network interface.

Call may throw if e.g. the interface it not up or not with an IP address.

Definition at line 135 of file SocketUtils.cpp.

◆ setInterfaceAddress()

void NET::setInterfaceAddress ( std::string_view interface,
std::string_view address )

Set the IPv4 address of the given network interface.

Call may throw if unable to set IP address (e.g. non Ethernet interface, etc.)

Definition at line 147 of file SocketUtils.cpp.

◆ getBroadcastAddress()

std::string NET::getBroadcastAddress ( std::string_view interface)

Return the IPv4 broadcast address of the given network interface.

The IOCTL call SIOCGIFBRDADDR is used on the specified interface. This method only works on AF_INET interfaces, it therefore works only on interfaces returned by ifconfig or getNetworkInterfaces().

The call may throw if e.g no BC address is configured or an interface is used that can not have a broadcast address (e.g. bluetooth).

Parameters
interfacethe interface to query for its broadcast address
Returns
the broadcast address formatted as an ip address

Definition at line 160 of file SocketUtils.cpp.

◆ setBroadcastAddress()

void NET::setBroadcastAddress ( std::string_view interface,
std::string_view address )

Set the IPv4 broadcast address of the given network interface.

This call my throw if e.g. used on an interface that can not have a BC address e.g. a bluetooth device

Parameters
interfaceinterface name
addressIPV4 address to configure the interface to

Definition at line 172 of file SocketUtils.cpp.

◆ getNetmask()

std::string NET::getNetmask ( std::string_view interface)

Return the IPv4 netmask of the given network interface.

This call may throw if the interface e.g. has no netmask configured (e.g. if interface is down) or can't have one (e.g. bluetooth)

Parameters
interfaceinterface name

Definition at line 185 of file SocketUtils.cpp.

◆ setNetmask()

void NET::setNetmask ( std::string_view interface,
std::string_view address )

Set the IPv4 netmask of the given network interface.

This call may throw if the interface e.g. can not have a broadcast address, is down, etc.

Parameters
interfaceinterface name
addressIPV4 address to set the netmask to

Definition at line 197 of file SocketUtils.cpp.

◆ getDestinationAddress()

std::string NET::getDestinationAddress ( std::string_view interface)

Return the IPv4 destination address of the given network interface.

This call may throw if the interface e.g. has no destination address configured (e.g. if interface is down) or can't have one (e.g. bluetooth)

Parameters
interfaceinterface name

Definition at line 210 of file SocketUtils.cpp.

◆ setDestinationAddress()

void NET::setDestinationAddress ( std::string_view interface,
std::string_view address )

Set the IPv4 destination address of the given network interface.

This call may throw if the interface e.g. can not have a destination address, is down, etc.

Parameters
interfaceinterface name
addressIPV4 address to set the netmask to

Definition at line 222 of file SocketUtils.cpp.

◆ getMTU()

int NET::getMTU ( std::string_view interface)

Return the MTU (Maximum Transmission Unit) of the given network interface in bytes.

This call may throw.

Parameters
interfaceinterface name

Definition at line 235 of file SocketUtils.cpp.

◆ setMTU()

void NET::setMTU ( std::string_view interface,
int mtu )

Set the MTU (Maximum Transmission Unit) of the given network interface in bytes.

This call may throw.

Parameters
interfaceinterface name
mtunew mtu in bytes

Definition at line 247 of file SocketUtils.cpp.

◆ getHardwareAddress()

std::string NET::getHardwareAddress ( std::string_view interface)

Return the MAC address of the given network interfaces.

This call may throw if the interface does not have a MAC address.

Parameters
interfaceinterface name

Definition at line 259 of file SocketUtils.cpp.