XPMP2
X-Plane multiplayer library 2 - using instancing
Classes | Namespaces | Typedefs | Functions | Variables
Network.cpp File Reference

Low-level network communications, especially for TCP/UDP. More...

#include "XPMP2.h"
#include <unistd.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <net/if.h>

Classes

struct  XPMP2::LocalIntfAddrTy
 Stores information about local interface addresses. More...
 

Namespaces

 XPMP2
 

Typedefs

typedef std::set< LocalIntfAddrTy > XPMP2::SetLocalIntfAddrTy
 Set of local IP interface addresses. More...
 

Functions

std::string XPMP2::_NetwGetIntfName (uint32_t idx, uint8_t family)
 Get an interface's name. More...
 
LocalIntfAddrTy XPMP2::_NetwFindLocalIntf (const std::string &intf, uint8_t family)
 Find a matching local interface based on name and family. More...
 
void XPMP2::_NetwGetLocalAddresses (bool bForceRefresh=false)
 Fetch all local addresses and cache locally. More...
 
uint32_t XPMP2::_GetIntfNext (const uint32_t prevIdx, SetLocalIntfAddrTy::const_iterator &i, uint8_t family, uint32_t fMust, uint32_t fSkip)
 Internal: Returns the next interface index of a broadcast interface for the given protocol family. More...
 
uint32_t XPMP2::GetIntfFirst (SetLocalIntfAddrTy::const_iterator &i, uint8_t family, uint32_t fMust, uint32_t fSkip=0)
 Returns the first interface index of a broadcast interface for the given protocol family. More...
 
uint32_t XPMP2::GetIntfNext (SetLocalIntfAddrTy::const_iterator &i, uint8_t family, uint32_t fMust, uint32_t fSkip=0)
 Returns the next interface index of a broadcast interface for the given protocol family. More...
 
std::vector< std::string > XPMP2::NetwGetInterfaces (uint8_t family, uint32_t fMust=0, uint32_t fSkip=0)
 Return list of known local interfaces. More...
 
std::string XPMP2::NetwGetInterfaceNames (uint8_t family, uint32_t fMust=0, uint32_t fSkip=0)
 Return comma-separated string will all known local interfaces, calls NetwGetInterfaces() More...
 
bool XPMP2::NetwIsLocalAddr (const InetAddrTy &addr)
 Is given address a local one? More...
 

Variables

constexpr int XPMP2::SERR_LEN = 100
 Maximum length of OS error message. More...
 
SetLocalIntfAddrTy XPMP2::gAddrLocal
 Set of local IP interface addresses. More...
 
std::recursive_mutex XPMP2::mtxAddrLocal
 Mutex to safeguard access to gAddrLocal More...
 
std::recursive_mutex XPMP2::mtxSocketClose
 Mutex to ensure closing is done in one thread only to avoid race conditions on deleting the buffer. More...
 

Detailed Description

Low-level network communications, especially for TCP/UDP.

See also
Some inital ideas and pieces of code take from https://linux.m2osw.com/c-implementation-udp-clientserver

XPMP2::SocketNetworking: Any network socket connection
XPMP2::UDPReceiver: listens to and receives UDP datagram
XPMP2::UDPMulticast: sends and receives multicast UDP datagrams
XPMP2::TCPConnection: receives incoming TCP connection

Author
Birger Hoppe