NetworkIpInterface Class Reference

#include <network_ip.h>

Detailed Description

Static interface to access network functionality.

Public Member Functions

 MAXON_OBSERVABLE_STATIC (void, ObservableNetworkInterfaceChanged,(), ObservableCombinerRunAllComponent)
 

Static Public Member Functions

static MAXON_METHOD Result< NetworkConnectionRef > OpenListener (const NetworkIpAddrPort &address, const ThreadRef &thread, TimeValue connectionTimeout, Bool useNagleAlgorithm)
 
static MAXON_METHOD Result< NetworkConnectionRef > OpenListener (const String &address, const ThreadRef &thread, TimeValue connectionTimeout, Bool useNagleAlgorithm)
 
static MAXON_METHOD Result< NetworkConnectionRef > OpenWaitForIncoming (const NetworkConnectionRef &listener, const ThreadRef &connection, TimeValue connectionTimeout, Bool fullDuplex)
 
static MAXON_METHOD Result< NetworkConnectionRef > OpenOutgoing (const NetworkIpAddrPort &address, const ThreadRef &thread, TimeValue connectTimeout, TimeValue sessionTimeout, Bool useNagleAlgorithm, Bool fullDuplex)
 
static MAXON_METHOD Result< NetworkConnectionRef > OpenOutgoing (const String &address, const ThreadRef &thread, TimeValue connectTimeout, TimeValue sessionTimeout, Bool useNagleAlgorithm, Bool fullDuplex)
 
static MAXON_METHOD Result< StringGetHostname ()
 
static MAXON_METHOD Result< StringGetHostname (const NetworkIpAddr &ipAddr, Bool useShortHostname=false)
 
static MAXON_METHOD ReturnResolveError ResolveHostname (const String &address, PROTOCOL ptype, BaseArray< NetworkIpAddr > &arr, Bool firstMatch=true, Bool forceResolve=false)
 
static MAXON_METHOD Result< void > SplitAddress (const String &address, String *scheme, String *host, Int32 *port)
 
static MAXON_METHOD Result< BoolSocketIOWait (SOCKET socket, SOCKETMODE mode, TimeValue timeoutMode, const ThreadRef &bt)
 
static MAXON_METHOD Result< NetworkIpAddrGetIpAddress (const String &address, Bool resolve=true, Bool forceResolve=false)
 
static MAXON_METHOD Result< NetworkIpAddrPortGetIpAddressAndPort (const String &address, Bool resolve=true, Bool forceResolve=false)
 
static MAXON_METHOD Result< void > WakeOnLan (const BaseArray< UChar > &macAddress, const NetworkIpAddr &broadcastAddress)
 
static MAXON_METHOD String GetTimeString ()
 
static MAXON_METHOD NetworkIpAddr GetBroadcastAddress (const NetworkIpAddr &ipAddress, const NetworkIpAddr &subnetMask)
 
static MAXON_METHOD Result< BaseArray< UChar > > GetMacAddress ()
 
static MAXON_METHOD String MacAddressToString (const BaseArray< UChar > &macAddress)
 
static MAXON_METHOD Result< IntGetAdapterIndex (const String &adapterName)
 
static MAXON_METHOD Result< NetworkAdapter > GetBestNetworkAdapter (PROTOCOL protocol=PROTOCOL::IPV4)
 
static MAXON_METHOD Result< BaseArray< NetworkAdapter > > GetAllNetworkAdapters ()
 
static MAXON_METHOD Result< IntGetAdapterIndex (const NetworkIpAddr &address)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (NetworkIpInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.networkip")
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( NetworkIpInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.interface.networkip"   
)
private

◆ OpenListener() [1/2]

static MAXON_METHOD Result<NetworkConnectionRef> OpenListener ( const NetworkIpAddrPort address,
const ThreadRef thread,
TimeValue  connectionTimeout,
Bool  useNagleAlgorithm 
)
static

Creates an NetworkIpConnection listener. When the listener is created use OpenWaitForIncoming() to wait for incoming connections. Shutdown the listener with CloseConnection(). When the machine / device goes into the sleep mode and wakes up again, the listener is still active and ready to accept connections.

Parameters
[in]addressAddresses where the socket is binded to. Pass en empty instance to listen on all adapters.
[in]threadThread object where this function is called from. Used to interrupt a connection on TestBreak()
[in]connectionTimeoutTimeout of the listener object. Use SOCKETTIMEOUT_INDEFINITELY to disable timeout. Use NETWORK_DEFAULT_CONNECTION_TIMEOUT if you want to have the recommended default values.
[in]useNagleAlgorithmSet to true to use the Nagle algorithm, otherwise false.
Returns
Listener object.

◆ OpenListener() [2/2]

static MAXON_METHOD Result<NetworkConnectionRef> OpenListener ( const String address,
const ThreadRef thread,
TimeValue  connectionTimeout,
Bool  useNagleAlgorithm 
)
static

Creates an NetworkIpConnection listener. When the listener is created use OpenWaitForIncoming() to wait for incoming connections. Shutdown the listener with CloseConnection(). When the machine / device goes into the sleep mode and wakes up again, the listener is still active and ready to accept connections.

Parameters
[in]addressAddress as string where the socket is binded to (e.g. "192.168.10.200:1234"). Pass en empty string or "0"
[in]threadThread object where this function is called from. Used to interrupt a connection on TestBreak()
[in]connectionTimeoutTimeout of the listener object. Use SOCKETTIMEOUT_INDEFINITELY to disable timeout. Use NETWORK_DEFAULT_CONNECTION_TIMEOUT if you want to have the recommended default values.
[in]useNagleAlgorithmSet to true to use the Nagle algorithm, otherwise false.
Returns
Listener object.

◆ OpenWaitForIncoming()

static MAXON_METHOD Result<NetworkConnectionRef> OpenWaitForIncoming ( const NetworkConnectionRef &  listener,
const ThreadRef connection,
TimeValue  connectionTimeout,
Bool  fullDuplex 
)
static

Waits for an incoming connection and blocks until a connection was established.

Parameters
[in]listenerListener object from OpenListener().
[in]connectionThread object where this function is called from. Used to interrupt this call on TestBreak().
[in]connectionTimeoutTimeout in seconds for further operations like send or receive. Use SOCKETTIMEOUT_INDEFINITELY to disable timeout. Use NETWORK_DEFAULT_CONNECTION_TIMEOUT if you want to have the recommended default values.
[in]fullDuplexSet the connection to full duplex mode which means that parallel read and write is allowed.
Returns
Incoming connection object or nullptr when an error occured or TestBreak() was called. In this case the content of ferr will be 0.

◆ OpenOutgoing() [1/2]

static MAXON_METHOD Result<NetworkConnectionRef> OpenOutgoing ( const NetworkIpAddrPort address,
const ThreadRef thread,
TimeValue  connectTimeout,
TimeValue  sessionTimeout,
Bool  useNagleAlgorithm,
Bool  fullDuplex 
)
static

Opens a connection. Supports IPv4 and IPv6.

Parameters
[in]addressPass a host name to connect to. Can be an IPv4, IPv6 address or a host name.
[in]threadOptional thread which should be checked for cancellation (see SetThread).
[in]connectTimeoutTimeout in seconds for the initial connection. Use NETWORK_DEFAULT_INITIAL_TIMEOUT if you want to have the recommended default values.
[in]sessionTimeoutTimeout in seconds for further operations like send or receive. Use SOCKETTIMEOUT_INDEFINITELY to disable timeout. Use NETWORK_DEFAULT_CONNECTION_TIMEOUT if you want to have the recommended default values.
[in]useNagleAlgorithmPass true to set the TCP/IP flag for TCP_NODELAY. For more information see: http://msdn.microsoft.com/en-us/library/ms817942.aspx.
[in]fullDuplexSet the connection to full duplex mode which means that parallel read and write is allowed.
Returns
Connection object for the outgoing connection. Must be freed with CloseConnection.

◆ OpenOutgoing() [2/2]

static MAXON_METHOD Result<NetworkConnectionRef> OpenOutgoing ( const String address,
const ThreadRef thread,
TimeValue  connectTimeout,
TimeValue  sessionTimeout,
Bool  useNagleAlgorithm,
Bool  fullDuplex 
)
static

◆ GetHostname() [1/2]

static MAXON_METHOD Result<String> GetHostname ( )
static

Returns the host name of the local machine.

◆ GetHostname() [2/2]

static MAXON_METHOD Result<String> GetHostname ( const NetworkIpAddr ipAddr,
Bool  useShortHostname = false 
)
static

Returns the host name of given ip address.

◆ MAXON_OBSERVABLE_STATIC()

MAXON_OBSERVABLE_STATIC ( void  ,
ObservableNetworkInterfaceChanged  ,
()  ,
ObservableCombinerRunAllComponent   
)

◆ ResolveHostname()

static MAXON_METHOD ReturnResolveError ResolveHostname ( const String address,
PROTOCOL  ptype,
BaseArray< NetworkIpAddr > &  arr,
Bool  firstMatch = true,
Bool  forceResolve = false 
)
static

Resolves a host name. If the address object can be an ip address object, you should use GetIpAddress(address, a, true) instead.

Parameters
[in]addressHost name to resolve.
[in]ptypePass PROTOCOL::IPV4 if the result should just contain IPv4 address, same for PROTOCOL::IPV6 with IPv6 address and PROTOCOL::ALL for all addresses.
[out]arrContains the addresses of the host name when the function succeeded.
[in]firstMatchAddress array has a maximum size of 1 element.
[in]forceResolveSet to true to resolve the address via the DNS system.
Returns
Returns RESOLVERESULT::OK on success, otherwise the resolve operation failed.

◆ SplitAddress()

static MAXON_METHOD Result<void> SplitAddress ( const String address,
String scheme,
String host,
Int32 port 
)
static

Splits a passed address in its elements.

◆ SocketIOWait()

static MAXON_METHOD Result<Bool> SocketIOWait ( SOCKET  socket,
SOCKETMODE  mode,
TimeValue  timeoutMode,
const ThreadRef bt 
)
static

◆ GetIpAddress()

static MAXON_METHOD Result<NetworkIpAddr> GetIpAddress ( const String address,
Bool  resolve = true,
Bool  forceResolve = false 
)
static

Converts a host name, IPv4 or IPv6 address into an ip address object. A port value in the address will be ignored. When the resolve option is enabled, the call blocks and waits for the DNS system when the address is a host name. E.g: address: Sebastians-Macbook-Pro.local (DNS system used, call blocks) address: 192.168.10.1 (no DNS system used, call does not block)

Parameters
[in]addressIP address or host name. If the string is a host name, resolve must be set to true otherwise the function fails.
[in]resolveSet to true to resolve the address via the DNS system.
[in]forceResolveTODO: (Seb) ?
Returns
Assigned ip address object.

◆ GetIpAddressAndPort()

static MAXON_METHOD Result<NetworkIpAddrPort> GetIpAddressAndPort ( const String address,
Bool  resolve = true,
Bool  forceResolve = false 
)
static

Converts a host name, IPv4 or IPv6` address into an ip address object. The address can have a port value. When the resolve option is enabled, the call blocks and waits for the DNS system when the address is a host name. E.g: address: Sebastians-Macbook-Pro.local:1234 (DNS system used, call blocks) address: 192.168.10.1:1234 (no DNS system used, call does not block)

Parameters
[in]addressIP address or host name. If the string is a host name, resolve must be set to true otherwise the function fails.
[in]resolveSet to true to resolve the address via the DNS system.
[in]forceResolveTODO: (Seb) ?
Returns
Assigned ip address object.

◆ WakeOnLan()

static MAXON_METHOD Result<void> WakeOnLan ( const BaseArray< UChar > &  macAddress,
const NetworkIpAddr broadcastAddress 
)
static

Wakes a computer up by WOL (Wake-On-LAN). Currently only IPv4 is supported. To get WOL to work, a broadcast message on port '9' will be sent.

Parameters
[in]macAddressMac-Address of the machine which will be woken up.
[in]broadcastAddressBroadcast address where the message should be send to.
Returns
True on success if the message was sent, otherwise false.

◆ GetTimeString()

static MAXON_METHOD String GetTimeString ( )
static

Create a human-readable time string.

Returns
Time string.

◆ GetBroadcastAddress()

static MAXON_METHOD NetworkIpAddr GetBroadcastAddress ( const NetworkIpAddr ipAddress,
const NetworkIpAddr subnetMask 
)
static

Convert a IPv4 broadcast address by a given ip and subnet address.

Parameters
[in]ipAddressIP address.
[in]subnetMaskSubnet address.
Returns
Broadcast address.

◆ GetMacAddress()

static MAXON_METHOD Result<BaseArray<UChar> > GetMacAddress ( )
static

Get the mac address of the machine. When this function returns false an error occurred, but then macAddress is filled at least with a random-generated macAddress. The random-generated mac address will be changed after a restart of the host application.

Returns
BaseArray with the mac address.

◆ MacAddressToString()

static MAXON_METHOD String MacAddressToString ( const BaseArray< UChar > &  macAddress)
static

Prints a mac address to the debug console. The output is visible in debug builds or in a release build when the debug console with diagnostic output is activated.

Parameters
[in]macAddressThe mac address.

◆ GetAdapterIndex() [1/2]

static MAXON_METHOD Result<Int> GetAdapterIndex ( const String adapterName)
static

Returns the adapter index. The interface name "all" returns 0.

Parameters
[in]adapterNameThe name.
Returns
The index.

◆ GetBestNetworkAdapter()

static MAXON_METHOD Result<NetworkAdapter> GetBestNetworkAdapter ( PROTOCOL  protocol = PROTOCOL::IPV4)
static

Returns the best network adapter to the specified protocol.

Parameters
[in]protocolSpecified protocol.
Returns
The found network adapter.

◆ GetAllNetworkAdapters()

static MAXON_METHOD Result<BaseArray<NetworkAdapter> > GetAllNetworkAdapters ( )
static

Returns all current active network adapter objects.

Returns
Array with all network adapters.

◆ GetAdapterIndex() [2/2]

static MAXON_METHOD Result<Int> GetAdapterIndex ( const NetworkIpAddr address)
static

Returns the interface index of the network adapter that is in the same network as the given address. It's not required that the address is assigned to the adapter itself. If no match was found, -1 is returned.

Returns
Interface index of matching network adapter.