• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Product
    • Design UI
    • Develop
    • Analyze and test
    • Deploy
    • Framework and toolbox
    • Compatibility
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - CDP Core
  • CDPNetwork
  • 4.11.14

CDPNetwork Class

CDPNetwork has some initialization-functions which are called during application startup, regarding MAC addresses and socket-initialization. CDPNetwork also has some conversion functions and static helper-functions. More...

Header: #include <OSAPI/Network/CDPNetwork.h>
  • List of all members, including inherited members

Public Functions

CDPNetwork()
~CDPNetwork()
void InitMac()
void InitSocketsAndMac()

Static Public Members

void CleanupSockets()
int GetLastError()
int GetLastErrorMessage(char *msgOut, int msgBufferSize, const char *methodName, bool displayMessage)
std::vector<std::string> GetMacAddresses(bool skipAddressNull = false)
int GetThisComputerHostName(char *hostName)
IpAddress GetThisComputerIpAddress()
bool HasNetworkError(int errorVal)
void Init()
bool IsSocketError(SOCKET s, unsigned int timeoutMs = 0)
bool IsSocketReadReady(SOCKET s, unsigned int timeoutMs)
bool IsSocketWriteReady(SOCKET s, unsigned int timeoutMs)
int OSAPIGetSocketPriority()

Related Non-Members

void FFromBigendian(unsigned char *rawdata, float &f)
void FToBigendian(float f, unsigned char *rawdata)
void FromBigendian(unsigned char *rawdata, T &value)
void ToBigendian(T &value, unsigned char *rawdata)
uint64_t htoni64(uint64_t hostValue)
double htond(double hostValue)
float htonf(float hostValue)
uint64_t ntohi64(uint64_t networkValue)
double ntohd(double networkValue)
float ntohf(float networkValue)

Detailed Description

CDPNetwork has some initialization-functions which are called during application startup, regarding MAC addresses and socket-initialization. CDPNetwork also has some conversion functions and static helper-functions.

See also EthernetManager, UdpReceive, UdpSend, UdpSendReceive, and TCPConnection.

Member Function Documentation

CDPNetwork::CDPNetwork()

Default constructs an instance of CDPNetwork.

CDPNetwork::~CDPNetwork()

Destroys the instance of CDPNetwork.

[static] void CDPNetwork::CleanupSockets()

Clean up winsock.

[static] int CDPNetwork::GetLastError()

Return the last error (WSAGetLastError for Windows, errno for Linux)

[static] int CDPNetwork::GetLastErrorMessage(char *msgOut, int msgBufferSize, const char *methodName, bool displayMessage)

Generates / gets the last network-related error-message.

Returns: Error code returned by WSAGetLastError()/xn_getlasterror().

Parameter msgOutBuffer where the error-message will be copied into (if msgOut is different from NULL).
Parameter msgBufferSizeMax number of bytes to be copied into msgOut.
Parameter methodNameMay contain a string telling where GetLastErrorMessage is called from, copied into msgOut/printed by CDPMessage.
Parameter displayMessageIf true, the error-message will be printed by CDPMessage.

Code-example where a CDPMessage containing the last network-related error-message will be printed, if debug-property for m_pParent-component is at least 2:

if (m_sendSocket.SendPacket(m_data, m_packetSize) == UdpSend::ERR)
{
  if ( DebugLevelForComponent(m_pParent, DEBUGLEVEL_EXTENDED))
    CDPNetwork::GetLastErrorMessage(nullptr,0, m_name.ToString().c_str(), true);
}

[static] std::vector<std::string> CDPNetwork::GetMacAddresses(bool skipAddressNull = false)

Get all MAC addresses. Skip null addresses by setting skipAddressNull to true.

See also InitMac().

[static] int CDPNetwork::GetThisComputerHostName(char *hostName)

Get network host name for this computer, copied into hostName. hostName must have pre-allocated memory, at least 32 bytes. Returns 0 if successful, otherwise error code.

[static] IpAddress CDPNetwork::GetThisComputerIpAddress()

Returns 1st network adapter (IP Address) in application.

See also EthernetManager.

[static] bool CDPNetwork::HasNetworkError(int errorVal)

Return true if a network-related error is set. Typically used in conjuction with f.i. TCPException.GetErrorCode() or CDPNetwork::GetLastError().

[static] void CDPNetwork::Init()

Convenience function for executing InitSocketsAndMac().

void CDPNetwork::InitMac()

Initialize MAC addresses, called by CDP during startup. MAC addresses are retrieved and stored. They can be fetched by calling GetMacAddresses().

void CDPNetwork::InitSocketsAndMac()

Initializes winsock and global MAC addresses.

[static] bool CDPNetwork::IsSocketError(SOCKET s, unsigned int timeoutMs = 0)

Returns true if socket has an error within timeoutMs, false if not.

[static] bool CDPNetwork::IsSocketReadReady(SOCKET s, unsigned int timeoutMs)

Returns true if socket is ready to read data within timeoutMs, false if not.

[static] bool CDPNetwork::IsSocketWriteReady(SOCKET s, unsigned int timeoutMs)

Returns true if socket is ready to write data within timeoutMs, false if not.

[static] int CDPNetwork::OSAPIGetSocketPriority()

Get socket priority. Only supported for linux, otherwise 0 is returned.

This function may be used when setting priority for a socket (setsockopt() with SO_PRIORITY) under linux. It will return a value in range [0..6] depending on thread-priority, with value 6 for highest priority.

Related Non-Members

void FFromBigendian(unsigned char *rawdata, float &f)

Deprecated. Use FromBigendian() instead. This function only calls FromBigendian().

void FToBigendian(float f, unsigned char *rawdata)

Deprecated. Use ToBigendian() instead. This function only calls ToBigendian().

void FromBigendian(unsigned char *rawdata, T &value)

Converts bigendian rawdata in argument buffer that must be at least sizeof(T) bytes to fit type T.

The passed pointer rawdata can not represent or be made to represent floating point number on this system due to IEEE 754 standard and NaN handling to avoid unwanted datamangling. The function assumes value T endianness to match system endianness.

void ToBigendian(T &value, unsigned char *rawdata)

Converts type T to bigendian format in rawdata argument that must be at least sizeof(T) bytes.

The passed pointer rawdata can not represent or be made to represent floating point number on this system due to IEEE 754 standard and NaN handling to avoid unwanted datamangling. The function assumes value T endianness to match system endianness.

uint64_t htoni64(uint64_t hostValue)

Convert uint64_t from host to network byte- ordering.

double htond(double hostValue)

Deprecated, returns only hostValue. Use ToBigendian() instead.

float htonf(float hostValue)

Deprecated, returns only hostValue. Use ToBigendian() instead.

uint64_t ntohi64(uint64_t networkValue)

Convert uint64_t from network to host byte- ordering.

double ntohd(double networkValue)

Deprecated, returns only networkValue. Use FromBigendian() instead.

float ntohf(float networkValue)

Deprecated, returns only networkValue. Use FromBigendian() instead.

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

    © Copyright 2022 CDP Technologies. Privacy and cookie policy.

    Return to top