Instrument Neutral Distributed Interface INDI  2.0.2
Typedefs | Functions
gmlc::netif Namespace Reference

Typedefs

using IF_ADDRS = struct ifaddrs *
 
using IF_ADDRS_UNICAST = struct ifaddrs *
 

Functions

std::string addressToString (struct sockaddr *addr, int sa_len)
 
void freeAddresses (IF_ADDRS addrs)
 
auto getAddresses (int family, IF_ADDRS *addrs)
 
auto getSockAddr (IF_ADDRS_UNICAST addr)
 
int getSockAddrLen (IF_ADDRS_UNICAST addr)
 
IF_ADDRS_UNICAST getNextAddress (int family, IF_ADDRS_UNICAST addrs)
 
std::vector< std::string > getInterfaceAddresses (int family)
 
std::vector< std::string > getInterfaceAddressesV4 ()
 
std::vector< std::string > getInterfaceAddressesV6 ()
 
std::vector< std::string > getInterfaceAddressesAll ()
 

Typedef Documentation

◆ IF_ADDRS

using gmlc::netif::IF_ADDRS = typedef struct ifaddrs*

Definition at line 41 of file NetIF.hpp.

◆ IF_ADDRS_UNICAST

using gmlc::netif::IF_ADDRS_UNICAST = typedef struct ifaddrs*

Definition at line 47 of file NetIF.hpp.

Function Documentation

◆ addressToString()

std::string gmlc::netif::addressToString ( struct sockaddr *  addr,
int  sa_len 
)
inline

a helper function to convert the IP address in a sockaddr struct to text

Parameters
addra pointer to a sockaddr struct
sa_lenthe length of the sockaddr (primarily for systems that don't support inet_ntop)
Returns
an IP address in text form, or an empty string if conversion to text failed

Definition at line 61 of file NetIF.hpp.

◆ freeAddresses()

void gmlc::netif::freeAddresses ( IF_ADDRS  addrs)
inline

a helper function to free the memory allocated to store a set of interface addresses

Parameters
addrsa pointer to the allocated address structure (type depends on OS)

Definition at line 97 of file NetIF.hpp.

◆ getAddresses()

auto gmlc::netif::getAddresses ( int  family,
IF_ADDRS addrs 
)
inline

a helper function to get a list of all interface adapters using OS system calls. the returned pointer from addrs must be freed with a call to freeAddresses.

Parameters
familytype of adapter addresses to get on Windows; one of AF_INET (IPv4), AF_INET6 (IPv6), or AF_UNSPEC (both)
[out]addrspointer to a pointer to be filled in with the address of the allocated address structure; must be freed when done by calling freeAddresses
Returns
0 on success, or -1 if an error occurred

Definition at line 115 of file NetIF.hpp.

◆ getInterfaceAddresses()

std::vector<std::string> gmlc::netif::getInterfaceAddresses ( int  family)

get all addresses associated with network interfaces on the system of the address family given.

Parameters
familythe type of IP address to return; one of AF_INET (IPv4), AF_INET6 (IPv6), or AF_UNSPEC (both)
Returns
a list of addresses as text

Definition at line 226 of file NetIF.hpp.

◆ getInterfaceAddressesAll()

std::vector<std::string> gmlc::netif::getInterfaceAddressesAll ( )

returns a list of all IPv4 and IPv6 addresses associated with network interfaces on the system.

Returns
a list of IPv4 and IPv6 addresses as text

Definition at line 282 of file NetIF.hpp.

◆ getInterfaceAddressesV4()

std::vector<std::string> gmlc::netif::getInterfaceAddressesV4 ( )

returns a list of all IPv4 addresses associated with network interfaces on the system.

Returns
a list of IPv4 addresses as text

Definition at line 269 of file NetIF.hpp.

◆ getInterfaceAddressesV6()

std::vector<std::string> gmlc::netif::getInterfaceAddressesV6 ( )

returns a list of all IPv6 addresses associated with network interfaces on the system.

Returns
a list of IPv6 addresses as text

Definition at line 275 of file NetIF.hpp.

◆ getNextAddress()

IF_ADDRS_UNICAST gmlc::netif::getNextAddress ( int  family,
IF_ADDRS_UNICAST  addrs 
)
inline

a helper function to get the next interface/adapter address based on OS

Parameters
familyspecify the type of address desired on non-Windows systems; one of AF_INET (IPv4), AF_INET6 (IPv6), or AF_UNSPEC (both)
addrsa pointer to an addresses structure for an interface/adapter list
Returns
the next interface/adapter in the addresses list (that matches the family given for non-Windows systems), or nullptr if there is no next address

Definition at line 186 of file NetIF.hpp.

◆ getSockAddr()

auto gmlc::netif::getSockAddr ( IF_ADDRS_UNICAST  addr)
inline

a helper function to get the underlying socket address structure based on OS

Parameters
addra pointer to an address structure for an (unicast) interface/adapter
Returns
a socket address structure containing the IP address information for an interface

Definition at line 155 of file NetIF.hpp.

◆ getSockAddrLen()

int gmlc::netif::getSockAddrLen ( IF_ADDRS_UNICAST  addr)
inline

a helper function to get the underlying socket address length on systems where it is needed

Parameters
addra pointer to an address structure for an (unicast) interface/adapter
Returns
the socket address length

Definition at line 169 of file NetIF.hpp.