Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
Interface - kodi::network

Network functions
The network module offers functions that allow you to control it. More...

Functions

bool ATTR_DLL_LOCAL kodi::network::WakeOnLan (const std::string &mac)
 Send WakeOnLan magic packet.
 
std::string ATTR_DLL_LOCAL kodi::network::GetIPAddress ()
 To the current own ip address as a string.
 
std::string ATTR_DLL_LOCAL kodi::network::GetHostname ()
 Return our hostname.
 
std::string ATTR_DLL_LOCAL kodi::network::GetUserAgent ()
 Returns Kodi's HTTP UserAgent string.
 
bool ATTR_DLL_LOCAL kodi::network::IsLocalHost (const std::string &hostname)
 Check given name or ip address corresponds to localhost.
 
bool ATTR_DLL_LOCAL kodi::network::IsHostOnLAN (const std::string &hostname, bool offLineCheck=false)
 Checks whether the specified path refers to a local network.
 
std::string ATTR_DLL_LOCAL kodi::network::URLEncode (const std::string &url)
 URL encodes the given string.
 
bool ATTR_DLL_LOCAL kodi::network::DNSLookup (const std::string &hostName, std::string &ipAddress)
 Lookup URL in DNS cache.
 

Detailed Description

Network functions
The network module offers functions that allow you to control it.

It has the header #include <kodi/Network.h> be included to enjoy it.

Function Documentation

◆ DNSLookup()

bool ATTR_DLL_LOCAL kodi::network::DNSLookup ( const std::string & hostName,
std::string & ipAddress )
inline

Lookup URL in DNS cache.

This test will get DNS record for a domain. The DNS lookup is done directly against the domain's authoritative name server, so changes to DNS Records should show up instantly. By default, the DNS lookup tool will return an IP address if you give it a name (e.g. www.example.com)

Parameters
[in]hostNameThe code of the message to get.
[out]ipAddressReturned address
Returns
true if successful

Example:

#include <kodi/Network.h>
...
std::string ipAddress;
bool ret = kodi::network::DNSLookup("www.google.com", ipAddress);
fprintf(stderr, "DNSLookup returned for www.google.com the IP '%s', call was %s\n", ipAddress.c_str(), ret ? "ok" : "failed");
...
bool ATTR_DLL_LOCAL DNSLookup(const std::string &hostName, std::string &ipAddress)
Lookup URL in DNS cache.
Definition addons/kodi-dev-kit/include/kodi/Network.h:267

◆ GetHostname()

std::string ATTR_DLL_LOCAL kodi::network::GetHostname ( )
inline

Return our hostname.

Returns
String about hostname, empty in case of error

Example:

#include <kodi/Network.h>
...
std::string hostname = kodi::network::GetHostname();
fprintf(stderr, "My hostname is '%s'\n", hostname.c_str());
...
std::string ATTR_DLL_LOCAL GetHostname()
Return our hostname.
Definition addons/kodi-dev-kit/include/kodi/Network.h:101

◆ GetIPAddress()

std::string ATTR_DLL_LOCAL kodi::network::GetIPAddress ( )
inline

To the current own ip address as a string.

Returns
Own system ip.

Example:

#include <kodi/Network.h>
...
std::string ipAddress = kodi::network::GetIPAddress();
fprintf(stderr, "My IP is '%s'\n", ipAddress.c_str());
...
std::string ATTR_DLL_LOCAL GetIPAddress()
To the current own ip address as a string.
Definition addons/kodi-dev-kit/include/kodi/Network.h:66

◆ GetUserAgent()

std::string ATTR_DLL_LOCAL kodi::network::GetUserAgent ( )
inline

Returns Kodi's HTTP UserAgent string.

Returns
HTTP user agent

Example:

..
std::string agent = kodi::network::GetUserAgent()
..

example output: Kodi/19.0-ALPHA1 (X11; Linux x86_64) Ubuntu/20.04 App_Bitness/64 Version/19.0-ALPHA1-Git:20200522-0076d136d3-dirty

◆ IsHostOnLAN()

bool ATTR_DLL_LOCAL kodi::network::IsHostOnLAN ( const std::string & hostname,
bool offLineCheck = false )
inline

Checks whether the specified path refers to a local network.

Parameters
[in]hostnameHostname to check
[in]offLineCheckCheck if in private range, see https://en.wikipedia.org/wiki/Private_network
Returns
True if host is on a LAN, false otherwise

◆ IsLocalHost()

bool ATTR_DLL_LOCAL kodi::network::IsLocalHost ( const std::string & hostname)
inline

Check given name or ip address corresponds to localhost.

Parameters
[in]hostnameHostname to check
Returns
Return true if given name or ip address corresponds to localhost

Example:

#include <kodi/Network.h>
...
if (kodi::network::IsLocalHost("127.0.0.1"))
fprintf(stderr, "Is localhost\n");
...
bool ATTR_DLL_LOCAL IsLocalHost(const std::string &hostname)
Check given name or ip address corresponds to localhost.
Definition addons/kodi-dev-kit/include/kodi/Network.h:173

◆ URLEncode()

std::string ATTR_DLL_LOCAL kodi::network::URLEncode ( const std::string & url)
inline

URL encodes the given string.

This function converts the given input string to a URL encoded string and returns that as a new allocated string. All input characters that are not a-z, A-Z, 0-9, '-', '.', '_' or '~' are converted to their "URL escaped" version (NN where NN is a two-digit hexadecimal number).

Parameters
[in]urlThe code of the message to get.
Returns
Encoded URL string

Example:

#include <kodi/Network.h>
...
std::string encodedUrl = kodi::network::URLEncode("François");
fprintf(stderr, "Encoded URL is '%s'\n", encodedUrl.c_str());
...
std::string ATTR_DLL_LOCAL URLEncode(const std::string &url)
URL encodes the given string.
Definition addons/kodi-dev-kit/include/kodi/Network.h:224

For example, the string: François ,would be encoded as: FranC3A7ois

◆ WakeOnLan()

bool ATTR_DLL_LOCAL kodi::network::WakeOnLan ( const std::string & mac)
inline

Send WakeOnLan magic packet.

Parameters
[in]macNetwork address of the host to wake.
Returns
True if the magic packet was successfully sent, false otherwise.