Jetson Inference
DNN Vision Library

TCP/UDP sockets and IP address manipulation. More...

Classes

struct  NetworkInterface
 Info about a particular network interface. More...
 
class  RTSPServer
 RTSP server for transmitting encoded GStreamer pipelines to client devices. More...
 
class  Socket
 The Socket class provides TCP or UDP ethernet networking. More...
 
struct  WebRTCPeer
 Remote peer that has connected. More...
 
class  WebRTCServer
 WebRTC signalling server for establishing and negotiating connections with peers for bi-directional media streaming. More...
 

Macros

#define INET4_ADDRLEN   4
 The size in bytes of an IPv4 address (4 bytes) This is meant to compliment POSIX's INET4_ADDRSTRLEN (16) More...
 
#define INET6_ADDRLEN   16
 The size in bytes of an IPv6 address (16 bytes) This is meant to compliment POSIX's INET6_ADDRSTRLEN (46) More...
 
#define LOG_NETWORK   "[network] "
 LOG_NETWORK logging string. More...
 
#define RTSP_DEFAULT_PORT   8554
 Default port used by RTSP server. More...
 
#define LOG_RTSP   "[rtsp] "
 RTSP logging prefix. More...
 
#define WEBRTC_DEFAULT_PORT   41567
 Default HTTP/websocket port used by the WebRTC server. More...
 
#define WEBRTC_DEFAULT_STUN_SERVER   "stun.l.google.com:19302"
 Default STUN server used for WebRTC. More...
 
#define LOG_WEBRTC   "[webrtc] "
 WebRTC logging prefix. More...
 

Enumerations

enum  SocketType { SOCKET_UDP = 0, SOCKET_TCP = 1 }
 TCP/UDP enumeration. More...
 
enum  WebRTCFlags {
  WEBRTC_PRIVATE = 0, WEBRTC_PUBLIC = (1 << 1), WEBRTC_AUDIO = (1 << 0), WEBRTC_VIDEO = (1 << 1),
  WEBRTC_SEND = (1 << 2), WEBRTC_RECEIVE = (1 << 3), WEBRTC_MULTI_CLIENT = (1 << 4), WEBRTC_PEER_CONNECTING = (1 << 5),
  WEBRTC_PEER_CONNECTED = (1 << 6), WEBRTC_PEER_STREAMING = (1 << 7), WEBRTC_PEER_CLOSED = (1 << 8)
}
 Flags for route decorators or peer state. More...
 

Functions

bool IPv4AddressFromStr (const char *str, uint32_t *ipAddress)
 Convert an IPv4 address string in "xxx.xxx.xxx.xxx" format to binary representation. More...
 
std::string IPv4AddressToStr (uint32_t ipAddress)
 Return text string of IPv4 address in "xxx.xxx.xxx.xxx" format. More...
 
bool IPv6AddressFromStr (const char *str, void *ipAddress)
 Convert an IPv6 address string in "x:x:x:x:x:x:x:x" hexadecimal format to 128-bit binary representation. More...
 
std::string IPv6AddressToStr (void *ipAddress)
 Return text string of IPv6 address in "x:x:x:x:x:x:x:x" hexadecimal format. More...
 
std::string getHostname ()
 Retrieve the host system's network hostname. More...
 
std::string getHostByName (const char *name, uint32_t retries=10)
 Resolve the IP address of a given hostname or domain using DNS lookup, and return it as a string. More...
 
uint32_t getHostByName (const char *name, void *ipAddress, uint32_t size, uint32_t retries=10)
 Resolve the IP address of a given hostname or domain using DNS lookup. More...
 
std::vector< NetworkInterfacegetNetworkInterfaces ()
 Retrieve info about the different IPv4/IPv6 network interfaces of the system. More...
 
void printNetworkInterfaces (const std::vector< NetworkInterface > &interfaces)
 Print out a list of network interfaces. More...
 

Detailed Description

TCP/UDP sockets and IP address manipulation.


Class Documentation

◆ NetworkInterface

struct NetworkInterface

Info about a particular network interface.

The IPv6 information will be filled out if it's enabled on the interface.

Public Attributes

std::string name
 name of the network interface (e.g. More...
 
bool up
 true if the interface is up, false if down More...
 
struct NetworkInterface::IPv4 ipv4
 
struct NetworkInterface::IPv6 ipv6
 

Member Data Documentation

◆ ipv4

struct NetworkInterface::IPv4 NetworkInterface::ipv4

◆ ipv6

struct NetworkInterface::IPv6 NetworkInterface::ipv6

◆ name

std::string NetworkInterface::name

name of the network interface (e.g.

eth0, wlan0, lo)

◆ up

bool NetworkInterface::up

true if the interface is up, false if down

◆ RTSPServer

class RTSPServer

RTSP server for transmitting encoded GStreamer pipelines to client devices.

This is integrated into videoOutput/gstEncoder, but can be used standalone (

See also
rtsp-server example)

Public Member Functions

void Release ()
 Release a reference to the server instance. More...
 
bool AddRoute (const char *path, _GstElement *pipeline)
 Register a GStreamer pipeline to be served at the specified path. More...
 
bool AddRoute (const char *path, const char *pipeline)
 Create a GStreamer pipeline and register it to be served at the specified path. More...
 

Static Public Member Functions

static RTSPServerCreate (uint16_t port=RTSP_DEFAULT_PORT)
 Create a RTSP server on this port. More...
 

Protected Member Functions

 RTSPServer (uint16_t port)
 
 ~RTSPServer ()
 
bool init ()
 

Static Protected Member Functions

static void * runThread (void *user_data)
 

Protected Attributes

uint16_t mPort
 
uint32_t mRefCount
 
ThreadmThread
 
bool mRunning
 
_GMainLoop * mMainLoop
 
_GstRTSPServer * mServer
 

Constructor & Destructor Documentation

◆ RTSPServer()

RTSPServer::RTSPServer ( uint16_t  port)
protected

◆ ~RTSPServer()

RTSPServer::~RTSPServer ( )
protected

Member Function Documentation

◆ AddRoute() [1/2]

bool RTSPServer::AddRoute ( const char *  path,
_GstElement *  pipeline 
)

Register a GStreamer pipeline to be served at the specified path.

It will be able to be viewed from clients at rtsp://hostname:port/path

◆ AddRoute() [2/2]

bool RTSPServer::AddRoute ( const char *  path,
const char *  pipeline 
)

Create a GStreamer pipeline and register it to be served at the specified path.

It will be able to be viewed from clients at rtsp://hostname:port/path

◆ Create()

static RTSPServer* RTSPServer::Create ( uint16_t  port = RTSP_DEFAULT_PORT)
static

Create a RTSP server on this port.

If this port is already in use, the existing server instance will be returned.

◆ init()

bool RTSPServer::init ( )
protected

◆ Release()

void RTSPServer::Release ( )

Release a reference to the server instance.

Server will be shut down when the reference count reaches zero.

◆ runThread()

static void* RTSPServer::runThread ( void *  user_data)
staticprotected

Member Data Documentation

◆ mMainLoop

_GMainLoop* RTSPServer::mMainLoop
protected

◆ mPort

uint16_t RTSPServer::mPort
protected

◆ mRefCount

uint32_t RTSPServer::mRefCount
protected

◆ mRunning

bool RTSPServer::mRunning
protected

◆ mServer

_GstRTSPServer* RTSPServer::mServer
protected

◆ mThread

Thread* RTSPServer::mThread
protected

◆ Socket

class Socket

The Socket class provides TCP or UDP ethernet networking.


To exchange data with a remote IP on the network using UDP, follow these steps:

    1.  Create a Socket instance with the static Create() function.
  1. Bind() the Socket to a host IP address and port
  2. Exchange data with the Send/Recv functions

Public Member Functions

 ~Socket ()
 Destructor. More...
 
bool Accept (uint64_t timeout=0)
 Accept incoming connections (TCP only). More...
 
bool Bind (const char *localIP, uint16_t port)
 Bind the socket to a local host IP address and port. More...
 
bool Bind (uint32_t localIP, uint16_t port)
 Bind the socket to a local host IP address and port. More...
 
bool Bind (uint16_t port=0)
 Bind the socket to a local host port, on any interface (0.0.0.0 INADDR_ANY). More...
 
bool Connect (const char *remoteIP, uint16_t port)
 Connect to a listening server (TCP only). More...
 
bool Connect (uint32_t remoteIP, uint16_t port)
 Connect to a listening server (TCP only). More...
 
size_t Recieve (uint8_t *buffer, size_t size, uint32_t *remoteIP=NULL, uint16_t *remotePort=NULL)
 Wait for a packet to be recieved and dump it into the user-supplied buffer. More...
 
size_t Recieve (uint8_t *buffer, size_t size, uint32_t *remoteIP, uint16_t *remotePort, uint32_t *localIP)
 Recieve packet, with additional address info. More...
 
bool Send (void *buffer, size_t size, uint32_t remoteIP, uint16_t remotePort)
 Send message to remote host. More...
 
bool SetRecieveTimeout (uint64_t timeout)
 Set Receive() timeout (in microseconds). More...
 
bool SetBufferSize (size_t size)
 Set the rx/tx buffer sizes. More...
 
bool EnableJumboBuffer ()
 Enable jumbo buffer. More...
 
int GetFD () const
 Retrieve the socket's file descriptor. More...
 
SocketType GetType () const
 GetType. More...
 
void PrintIP () const
 PrintIP. More...
 
size_t GetMTU ()
 Retrieve the MTU (in bytes). More...
 

Static Public Member Functions

static SocketCreate (SocketType type)
 Create. More...
 

Constructor & Destructor Documentation

◆ ~Socket()

Socket::~Socket ( )

Destructor.

Member Function Documentation

◆ Accept()

bool Socket::Accept ( uint64_t  timeout = 0)

Accept incoming connections (TCP only).

Parameters
timeoutThe timeout (in microseconds) to wait for incoming connections before returning.

◆ Bind() [1/3]

bool Socket::Bind ( const char *  localIP,
uint16_t  port 
)

Bind the socket to a local host IP address and port.

Parameters
ipAddressIPv4 address in string format "xxx.xxx.xxx.xxx"
portthe port number (0-65536), in host byte order. If the port specified is 0, the socket will be bound to any available port.

◆ Bind() [2/3]

bool Socket::Bind ( uint16_t  port = 0)

Bind the socket to a local host port, on any interface (0.0.0.0 INADDR_ANY).

Parameters
portthe port number (0-65536), in host byte order. If the port specified is 0, the socket will be bound to any available port.

◆ Bind() [3/3]

bool Socket::Bind ( uint32_t  localIP,
uint16_t  port 
)

Bind the socket to a local host IP address and port.

Parameters
hostIPIPv4 address, in network byte order. If htonl(INADDR_ANY) is specified for the ipAddress, the socket will be bound to all available interfaces.
portthe port number (0-65536), in host byte order. If the port specified is 0, the socket will be bound to any available port.

◆ Connect() [1/2]

bool Socket::Connect ( const char *  remoteIP,
uint16_t  port 
)

Connect to a listening server (TCP only).

Parameters
remoteIPIP address of the remote host.

◆ Connect() [2/2]

bool Socket::Connect ( uint32_t  remoteIP,
uint16_t  port 
)

Connect to a listening server (TCP only).

Parameters
remoteIPIP address of the remote host.

◆ Create()

static Socket* Socket::Create ( SocketType  type)
static

Create.

◆ EnableJumboBuffer()

bool Socket::EnableJumboBuffer ( )

Enable jumbo buffer.

◆ GetFD()

int Socket::GetFD ( ) const
inline

Retrieve the socket's file descriptor.

◆ GetMTU()

size_t Socket::GetMTU ( )

Retrieve the MTU (in bytes).

Returns 0 on error.

◆ GetType()

SocketType Socket::GetType ( ) const
inline

GetType.

◆ PrintIP()

void Socket::PrintIP ( ) const

PrintIP.

◆ Recieve() [1/2]

size_t Socket::Recieve ( uint8_t *  buffer,
size_t  size,
uint32_t *  remoteIP,
uint16_t *  remotePort,
uint32_t *  localIP 
)

Recieve packet, with additional address info.

In addition to returning the IP and port of the remote host which sent the packet, this function can also return the local IP and port which the packet was sent to.

See also
Recieve()

◆ Recieve() [2/2]

size_t Socket::Recieve ( uint8_t *  buffer,
size_t  size,
uint32_t *  remoteIP = NULL,
uint16_t *  remotePort = NULL 
)

Wait for a packet to be recieved and dump it into the user-supplied buffer.

Optionally return the IP address and port of the remote host which sent the packet.

Parameters
bufferuser-allocated destination for the packet
sizesize of the buffer (in bytes)
remoteIpAddressoptional output, the IPv4 address of where the packet originated (in network byte order).
remotePortoptional output, the port from where the packet originated (in host byte order).
Returns
the size (in bytes) of the packet sucessfully written to buffer.

◆ Send()

bool Socket::Send ( void *  buffer,
size_t  size,
uint32_t  remoteIP,
uint16_t  remotePort 
)

Send message to remote host.

◆ SetBufferSize()

bool Socket::SetBufferSize ( size_t  size)

Set the rx/tx buffer sizes.

◆ SetRecieveTimeout()

bool Socket::SetRecieveTimeout ( uint64_t  timeout)

Set Receive() timeout (in microseconds).

◆ WebRTCPeer

struct WebRTCPeer

Remote peer that has connected.

Public Attributes

SoupWebsocketConnection * connection
 
SoupClientContext * client_context
 
WebRTCServerserver
 
uint32_t ID
 
uint32_t flags
 
std::string path
 
std::string ip_address
 
void * user_data
 

Member Data Documentation

◆ client_context

SoupClientContext* WebRTCPeer::client_context

◆ connection

SoupWebsocketConnection* WebRTCPeer::connection

◆ flags

uint32_t WebRTCPeer::flags

◆ ID

uint32_t WebRTCPeer::ID

◆ ip_address

std::string WebRTCPeer::ip_address

◆ path

std::string WebRTCPeer::path

◆ server

WebRTCServer* WebRTCPeer::server

◆ user_data

void* WebRTCPeer::user_data

◆ WebRTCServer

class WebRTCServer

WebRTC signalling server for establishing and negotiating connections with peers for bi-directional media streaming.

Users can bind routing functions that configure their pipelines dynamically to handle incoming/outgoing streams.

It uses websockets to handle the communication with clients for SDP offers, ICE messages, ect.

See also
https://doc-kurento.readthedocs.io/en/stable/_static/client-javadoc/org/kurento/client/WebRtcEndpoint.html

By default it also serves simple HTML for viewing video streams in browsers, but for full hosting you'll want to run this alongside an actual webserver.

multi-stream :: multi-client :: full-duplex

Public Types

typedef void(* WebsocketListener) (WebRTCPeer *peer, const char *message, size_t message_size, void *user_data)
 Function pointer to a callback for handling websocket requests. More...
 
typedef SoupServerCallback HttpListener
 Function pointer to a callback for handling HTTP requests. More...
 

Public Member Functions

void Release ()
 Release a reference to the server instance. More...
 
void AddRoute (const char *path, HttpListener callback, void *user_data=NULL, uint32_t flags=0)
 Register a function to handle incoming http/www requests at the specified path. More...
 
void AddRoute (const char *path, WebsocketListener callback, void *user_data=NULL, uint32_t flags=0)
 Register a function to handle incoming Websocket requests at the specified path. More...
 
const char * GetSTUNServer () const
 Get the STUN server being used. More...
 
bool HasHTTPS () const
 Return true if the server is using HTTPS. More...
 
bool IsThreaded () const
 Return true if the server is running in it's own thread. More...
 
bool ProcessRequests (bool blocking=false)
 Process incoming requests on the server. More...
 

Static Public Member Functions

static WebRTCServerCreate (uint16_t port=WEBRTC_DEFAULT_PORT, const char *stun_server=WEBRTC_DEFAULT_STUN_SERVER, const char *ssl_cert=NULL, const char *ssl_key=NULL, bool threaded=true)
 Create a WebRTC server on this port. More...
 

Protected Member Functions

 WebRTCServer (uint16_t port, const char *stun_server, const char *ssl_cert_file, const char *ssl_key_file, bool threaded)
 
 ~WebRTCServer ()
 
bool init ()
 
HttpRoutefindHttpRoute (const char *path) const
 
WebsocketRoutefindWebsocketRoute (const char *path) const
 
void freeRoute (HttpRoute *route)
 
void freeRoute (WebsocketRoute *route)
 
std::string printRouteInfo (WebsocketRoute *route) const
 

Static Protected Member Functions

static void * runThread (void *user_data)
 
static void onHttpRequest (SoupServer *soup_server, SoupMessage *message, const char *path, GHashTable *query, SoupClientContext *client_context, void *user_data)
 
static void onHttpDefault (SoupServer *soup_server, SoupMessage *message, const char *path, GHashTable *query, SoupClientContext *client_context, void *user_data)
 
static void onWebsocketOpened (SoupServer *server, SoupWebsocketConnection *connection, const char *path, SoupClientContext *client_context, void *user_data)
 
static void onWebsocketMessage (SoupWebsocketConnection *connection, SoupWebsocketDataType data_type, GBytes *message, void *user_data)
 
static void onWebsocketClosed (SoupWebsocketConnection *connection, void *user_data)
 

Protected Attributes

std::vector< HttpRoute * > mHttpRoutes
 
std::vector< WebsocketRoute * > mWebsocketRoutes
 
SoupServer * mSoupServer
 
std::string mStunServer
 
std::string mSSLCertFile
 
std::string mSSLKeyFile
 
bool mHasHTTPS
 
uint16_t mPort
 
uint32_t mRefCount
 
uint32_t mPeerCount
 
ThreadmThread
 

Member Typedef Documentation

◆ HttpListener

typedef SoupServerCallback WebRTCServer::HttpListener

Function pointer to a callback for handling HTTP requests.

See also
https://developer-old.gnome.org/libsoup/stable/SoupServer.html#SoupServerCallback

◆ WebsocketListener

typedef void(* WebRTCServer::WebsocketListener) (WebRTCPeer *peer, const char *message, size_t message_size, void *user_data)

Function pointer to a callback for handling websocket requests.

See also
AddConnectionListener

Constructor & Destructor Documentation

◆ WebRTCServer()

WebRTCServer::WebRTCServer ( uint16_t  port,
const char *  stun_server,
const char *  ssl_cert_file,
const char *  ssl_key_file,
bool  threaded 
)
protected

◆ ~WebRTCServer()

WebRTCServer::~WebRTCServer ( )
protected

Member Function Documentation

◆ AddRoute() [1/2]

void WebRTCServer::AddRoute ( const char *  path,
HttpListener  callback,
void *  user_data = NULL,
uint32_t  flags = 0 
)

Register a function to handle incoming http/www requests at the specified path.

These are for serving webpages, and should be on different paths than the websockets. If the path is "/" the callback will handle all routes. If the route for this path already exists, it will replace the existing route. To remove a route, set the callback to NULL.

◆ AddRoute() [2/2]

void WebRTCServer::AddRoute ( const char *  path,
WebsocketListener  callback,
void *  user_data = NULL,
uint32_t  flags = 0 
)

Register a function to handle incoming Websocket requests at the specified path.

This path often represents a media stream that can be sent/recieved, or a function for dynamically configuring streams when new clients connect.

If the path is "/" the callback will handle all routes. If the route for this path already exists, it will replace the existing route. To remove a route, set the callback to NULL.

The optional flags are WebRTCFlags OR'd together and are used for describing the stream capabilities for purposes of discovery.

See also
WebRTCFlags

◆ Create()

static WebRTCServer* WebRTCServer::Create ( uint16_t  port = WEBRTC_DEFAULT_PORT,
const char *  stun_server = WEBRTC_DEFAULT_STUN_SERVER,
const char *  ssl_cert = NULL,
const char *  ssl_key = NULL,
bool  threaded = true 
)
static

Create a WebRTC server on this port.

If this port is already in use, the existing server instance will be returned.

◆ findHttpRoute()

HttpRoute* WebRTCServer::findHttpRoute ( const char *  path) const
protected

◆ findWebsocketRoute()

WebsocketRoute* WebRTCServer::findWebsocketRoute ( const char *  path) const
protected

◆ freeRoute() [1/2]

void WebRTCServer::freeRoute ( HttpRoute route)
protected

◆ freeRoute() [2/2]

void WebRTCServer::freeRoute ( WebsocketRoute route)
protected

◆ GetSTUNServer()

const char* WebRTCServer::GetSTUNServer ( ) const
inline

Get the STUN server being used.

STUN servers are used during ICE/NAT and allow a local device to determine its public IP address.

See also
WEBRTC_DEFAULT_STUN_SERVER

◆ HasHTTPS()

bool WebRTCServer::HasHTTPS ( ) const
inline

Return true if the server is using HTTPS.

For HTTPS to be enabled, SSL cert/key files must have been provided to WebRTCServer::Create().

◆ init()

bool WebRTCServer::init ( )
protected

◆ IsThreaded()

bool WebRTCServer::IsThreaded ( ) const
inline

Return true if the server is running in it's own thread.

Otherwise, ProcessRequests() must be called periodically.

◆ onHttpDefault()

static void WebRTCServer::onHttpDefault ( SoupServer *  soup_server,
SoupMessage *  message,
const char *  path,
GHashTable *  query,
SoupClientContext *  client_context,
void *  user_data 
)
staticprotected

◆ onHttpRequest()

static void WebRTCServer::onHttpRequest ( SoupServer *  soup_server,
SoupMessage *  message,
const char *  path,
GHashTable *  query,
SoupClientContext *  client_context,
void *  user_data 
)
staticprotected

◆ onWebsocketClosed()

static void WebRTCServer::onWebsocketClosed ( SoupWebsocketConnection *  connection,
void *  user_data 
)
staticprotected

◆ onWebsocketMessage()

static void WebRTCServer::onWebsocketMessage ( SoupWebsocketConnection *  connection,
SoupWebsocketDataType  data_type,
GBytes *  message,
void *  user_data 
)
staticprotected

◆ onWebsocketOpened()

static void WebRTCServer::onWebsocketOpened ( SoupServer *  server,
SoupWebsocketConnection *  connection,
const char *  path,
SoupClientContext *  client_context,
void *  user_data 
)
staticprotected

◆ printRouteInfo()

std::string WebRTCServer::printRouteInfo ( WebsocketRoute route) const
protected

◆ ProcessRequests()

bool WebRTCServer::ProcessRequests ( bool  blocking = false)

Process incoming requests on the server.

If set to blocking, the function can wait indefinitely for requests. This should only be called externally if the server was created with threaded=false

◆ Release()

void WebRTCServer::Release ( )

Release a reference to the server instance.

Server will be shut down when the reference count reaches zero.

◆ runThread()

static void* WebRTCServer::runThread ( void *  user_data)
staticprotected

Member Data Documentation

◆ mHasHTTPS

bool WebRTCServer::mHasHTTPS
protected

◆ mHttpRoutes

std::vector<HttpRoute*> WebRTCServer::mHttpRoutes
protected

◆ mPeerCount

uint32_t WebRTCServer::mPeerCount
protected

◆ mPort

uint16_t WebRTCServer::mPort
protected

◆ mRefCount

uint32_t WebRTCServer::mRefCount
protected

◆ mSoupServer

SoupServer* WebRTCServer::mSoupServer
protected

◆ mSSLCertFile

std::string WebRTCServer::mSSLCertFile
protected

◆ mSSLKeyFile

std::string WebRTCServer::mSSLKeyFile
protected

◆ mStunServer

std::string WebRTCServer::mStunServer
protected

◆ mThread

Thread* WebRTCServer::mThread
protected

◆ mWebsocketRoutes

std::vector<WebsocketRoute*> WebRTCServer::mWebsocketRoutes
protected

Macro Definition Documentation

◆ INET4_ADDRLEN

#define INET4_ADDRLEN   4

The size in bytes of an IPv4 address (4 bytes) This is meant to compliment POSIX's INET4_ADDRSTRLEN (16)

◆ INET6_ADDRLEN

#define INET6_ADDRLEN   16

The size in bytes of an IPv6 address (16 bytes) This is meant to compliment POSIX's INET6_ADDRSTRLEN (46)

◆ LOG_NETWORK

#define LOG_NETWORK   "[network] "

LOG_NETWORK logging string.

◆ LOG_RTSP

#define LOG_RTSP   "[rtsp] "

RTSP logging prefix.

◆ LOG_WEBRTC

#define LOG_WEBRTC   "[webrtc] "

WebRTC logging prefix.

◆ RTSP_DEFAULT_PORT

#define RTSP_DEFAULT_PORT   8554

Default port used by RTSP server.

◆ WEBRTC_DEFAULT_PORT

#define WEBRTC_DEFAULT_PORT   41567

Default HTTP/websocket port used by the WebRTC server.

◆ WEBRTC_DEFAULT_STUN_SERVER

#define WEBRTC_DEFAULT_STUN_SERVER   "stun.l.google.com:19302"

Default STUN server used for WebRTC.

STUN servers are used during ICE/NAT and allow a local device to determine its public IP address.

Enumeration Type Documentation

◆ SocketType

enum SocketType

TCP/UDP enumeration.

Enumerator
SOCKET_UDP 

flag indicating UDP datagram service (SOCK_DGRAM)

SOCKET_TCP 

flag indicating TCP virtual circuit service (SOCK_STREAM)

◆ WebRTCFlags

Flags for route decorators or peer state.

Enumerator
WEBRTC_PRIVATE 
WEBRTC_PUBLIC 
WEBRTC_AUDIO 
WEBRTC_VIDEO 
WEBRTC_SEND 
WEBRTC_RECEIVE 
WEBRTC_MULTI_CLIENT 
WEBRTC_PEER_CONNECTING 
WEBRTC_PEER_CONNECTED 
WEBRTC_PEER_STREAMING 
WEBRTC_PEER_CLOSED 

Function Documentation

◆ getHostByName() [1/2]

std::string getHostByName ( const char *  name,
uint32_t  retries = 10 
)

Resolve the IP address of a given hostname or domain using DNS lookup, and return it as a string.

This uses the system function gethostbyname() and supports both IPv6/IPv6 addresses.

Parameters
namethe hostname to lookup.
retriesthe number of times to retry the lookup should it fail.
Returns
the IP address in string format, or an empty string if an error occurred.

◆ getHostByName() [2/2]

uint32_t getHostByName ( const char *  name,
void *  ipAddress,
uint32_t  size,
uint32_t  retries = 10 
)

Resolve the IP address of a given hostname or domain using DNS lookup.

This uses the system function gethostbyname() and supports both IPv6/IPv6 addresses.

Parameters
namethe hostname or domain name to lookup.
ipAddressoutput pointer to buffer that the IPv4 or IPv6 address will be written to. this buffer should be up to 16 bytes long for supporting IPv6 addresses, or 4 bytes long for only supporting IPv4 addresses.
sizethe size of the ipAddress buffer (4 bytes for IPv6 or 16 bytes for IPv6)
retriesthe number of times to retry the lookup should it fail.
Returns
the size in bytes of the ipAddress that was written (4 bytes for IPv6 or 16 bytes for IPv6) 0 is returned if an error occurred, or the provided ipAddress buffer was not large enough.

◆ getHostname()

std::string getHostname ( )

Retrieve the host system's network hostname.

Returns
the system hostname, or an empty string on error.

◆ getNetworkInterfaces()

std::vector<NetworkInterface> getNetworkInterfaces ( )

Retrieve info about the different IPv4/IPv6 network interfaces of the system.

Internally this uses the system function getifaddrs()

Returns
a list of network interfaces, or an empty list if an error occurred.

◆ IPv4AddressFromStr()

bool IPv4AddressFromStr ( const char *  str,
uint32_t *  ipAddress 
)

Convert an IPv4 address string in "xxx.xxx.xxx.xxx" format to binary representation.

Parameters
strthe IPv4 string, in "xxx.xxx.xxx.xxx" format
ipAddressoutput pointer to converted IPv4 address, in network byte order.
Returns
true, if str was a valid IPv4 address and the conversion was successful. false, if the conversion failed.

◆ IPv4AddressToStr()

std::string IPv4AddressToStr ( uint32_t  ipAddress)

Return text string of IPv4 address in "xxx.xxx.xxx.xxx" format.

Parameters
ipAddressIPv4 address, supplied in network byte order.

◆ IPv6AddressFromStr()

bool IPv6AddressFromStr ( const char *  str,
void *  ipAddress 
)

Convert an IPv6 address string in "x:x:x:x:x:x:x:x" hexadecimal format to 128-bit binary representation.

Parameters
strthe IPv6 string, in "x:x:x:x:x:x:x:x" hexadecimal format
ipAddressoutput pointer to converted 128-bit IPv6 address (16 bytes long), in network byte order. this buffer can be a variety of representations (commonly uint8[16] or uint16[8]), as long as it's at least 128 bits (16 bytes) long.
Returns
true, if str was a valid IPv6 address and the conversion was successful. false, if the conversion failed.

◆ IPv6AddressToStr()

std::string IPv6AddressToStr ( void *  ipAddress)

Return text string of IPv6 address in "x:x:x:x:x:x:x:x" hexadecimal format.

Parameters
ipAddresspointer to 128-bit IPv6 address (16 bytes long), in network byte order. this buffer can be a variety of representations (commonly uint8[16] or uint16[8]), as long as it's at least 128 bits (16 bytes) long.

◆ printNetworkInterfaces()

void printNetworkInterfaces ( const std::vector< NetworkInterface > &  interfaces)

Print out a list of network interfaces.