Network Services API  2.10.01.02
Macros | Functions
SlNetUtils group

Sockets related commands and configuration. More...

Macros

#define SLNETUTIL_IPV4_VAL(add_3, add_2, add_1, add_0)   ((((uint32_t)add_3 << 24) & 0xFF000000) | (((uint32_t)add_2 << 16) & 0xFF0000) | (((uint32_t)add_1 << 8) & 0xFF00) | ((uint32_t)add_0 & 0xFF) )
 

Functions

int32_t SlNetUtil_init (int32_t flags)
 Initialize the SlNetUtil module. More...
 
int32_t SlNetUtil_getHostByName (uint32_t ifBitmap, char *name, const uint16_t nameLen, uint32_t *ipAddr, uint16_t *ipAddrLen, const uint8_t family)
 Get host IP by name
Obtain the IP Address of machine on network, by machine name. More...
 
uint32_t SlNetUtil_htonl (uint32_t val)
 Reorder the bytes of a 32-bit unsigned value. More...
 
uint32_t SlNetUtil_ntohl (uint32_t val)
 Reorder the bytes of a 32-bit unsigned value. More...
 
uint16_t SlNetUtil_htons (uint16_t val)
 Reorder the bytes of a 16-bit unsigned value. More...
 
uint16_t SlNetUtil_ntohs (uint16_t val)
 Reorder the bytes of a 16-bit unsigned value. More...
 
const char * SlNetUtil_inetNtop (int16_t addrFamily, const void *binaryAddr, char *strAddr, SlNetSocklen_t strAddrLen)
 Converts IP address in binary representation to string representation. More...
 
int32_t SlNetUtil_inetPton (int16_t addrFamily, const char *strAddr, void *binaryAddr)
 Converts IP address in string representation to binary representation. More...
 

Detailed Description

Sockets related commands and configuration.

Macro Definition Documentation

§ SLNETUTIL_IPV4_VAL

#define SLNETUTIL_IPV4_VAL (   add_3,
  add_2,
  add_1,
  add_0 
)    ((((uint32_t)add_3 << 24) & 0xFF000000) | (((uint32_t)add_2 << 16) & 0xFF0000) | (((uint32_t)add_1 << 8) & 0xFF00) | ((uint32_t)add_0 & 0xFF) )

Function Documentation

§ SlNetUtil_init()

int32_t SlNetUtil_init ( int32_t  flags)

Initialize the SlNetUtil module.

Parameters
[in]flagsReserved
Returns
Zero on success, or negative error code on failure

§ SlNetUtil_getHostByName()

int32_t SlNetUtil_getHostByName ( uint32_t  ifBitmap,
char *  name,
const uint16_t  nameLen,
uint32_t *  ipAddr,
uint16_t *  ipAddrLen,
const uint8_t  family 
)

Get host IP by name
Obtain the IP Address of machine on network, by machine name.

Parameters
[in]ifBitmapSpecifies the interfaces which the the host ip needs to be retrieved from according tothe priority until one of them will return an answer.
Value 0 is used in order to choose automatic interfaces selection according to the priority interface list. Value can be combination of interfaces by OR'ing multiple interfaces bit identifiers (SLNETIFC_IDENT_ defined in slnetif.h) Note: interface identifier bit must be configured prior to this socket creation using SlNetIf_add().
[in]nameHost name
[in]nameLenName length
[out]ipAddrThis parameter is filled in with an array of IP addresses. In case that host name is not resolved, ipAddrLen is zero.
[in,out]ipAddrLenHolds the size of the ipAddr array, when function successful, the ipAddrLen parameter will be updated with the number of the IP addresses found.
[in]familyProtocol family
Returns
The interface ID of the interface which run successfully the function, or negative on failure.
SLNETERR_POOL_IS_EMPTY may be return in case there are no resources in the system
Possible DNS error codes:
Precondition
As with all SlNetUtil API's, SlNetUtil_init() must have previously been called.
Warning
In case an IP address in a string format is set as input, without any prefix (e.g. "1.2.3.4") the device will not try to access the DNS and it will return the input address in the ipAddr field
Example

§ SlNetUtil_htonl()

uint32_t SlNetUtil_htonl ( uint32_t  val)

Reorder the bytes of a 32-bit unsigned value.

This function is used to reorder the bytes of a 32-bit unsigned value from host order to network order.

Parameters
[in]valVariable in host order
Returns
Return the variable in network order
Precondition
As with all SlNetUtil API's, SlNetUtil_init() must have previously been called.
See also
SlNetSock_bind()
SlNetSock_connect()
SlNetSock_recvFrom()
SlNetSock_accept()

§ SlNetUtil_ntohl()

uint32_t SlNetUtil_ntohl ( uint32_t  val)

Reorder the bytes of a 32-bit unsigned value.

This function is used to reorder the bytes of a 32-bit unsigned value from network order to host order.

Parameters
[in]valVariable in network order
Returns
Return the variable in host order
Precondition
As with all SlNetUtil API's, SlNetUtil_init() must have previously been called.
See also
SlNetSock_bind()
SlNetSock_connect()
SlNetSock_recvFrom()
SlNetSock_accept()

§ SlNetUtil_htons()

uint16_t SlNetUtil_htons ( uint16_t  val)

Reorder the bytes of a 16-bit unsigned value.

This functions is used to reorder the bytes of a 16-bit unsigned value from host order to network order.

Parameters
[in]valVariable in host order
Returns
Return the variable in network order
Precondition
As with all SlNetUtil API's, SlNetUtil_init() must have previously been called.
See also
SlNetSock_bind()
SlNetSock_connect()
SlNetSock_recvFrom()
SlNetSock_accept()

§ SlNetUtil_ntohs()

uint16_t SlNetUtil_ntohs ( uint16_t  val)

Reorder the bytes of a 16-bit unsigned value.

This functions is used to reorder the bytes of a 16-bit unsigned value from network order to host order.

Parameters
[in]valVariable in network order
Returns
Return the variable in host order
Precondition
As with all SlNetUtil API's, SlNetUtil_init() must have previously been called.
See also
SlNetSock_bind()
SlNetSock_connect()
SlNetSock_recvFrom()
SlNetSock_accept()

§ SlNetUtil_inetNtop()

const char* SlNetUtil_inetNtop ( int16_t  addrFamily,
const void *  binaryAddr,
char *  strAddr,
SlNetSocklen_t  strAddrLen 
)

Converts IP address in binary representation to string representation.

This functions is used to converts IP address in binary representation to IP address in string representation.

Parameters
[in]addrFamilySpecifies the address family of the created socket For example:
[in]binaryAddrPointer to an IP address structure indicating the address in binary representation
[out]strAddrPointer to the address string representation for IPv4 or IPv6 according to the address family
[in]strAddrLenSpecifies the length of the StrAddress_dst, the maximum length of the address in string representation for IPv4 or IPv6 according to the address family
Returns
strAddr on success, or NULL on failure
Precondition
As with all SlNetUtil API's, SlNetUtil_init() must have previously been called.
Example

§ SlNetUtil_inetPton()

int32_t SlNetUtil_inetPton ( int16_t  addrFamily,
const char *  strAddr,
void *  binaryAddr 
)

Converts IP address in string representation to binary representation.

This functions is used to converts IP address in string representation to IP address in binary representation.

Parameters
[in]addrFamilySpecifies the address family of the created socket For example:
[out]strAddrSpecifies the IP address in string representation for IPv4 or IPv6 according to the address family
[in]binaryAddrPointer to an address structure that will be filled by the IP address in Binary representation
Returns
1 on success, -1 on failure, or 0 if the input isn't a valid IP address
Precondition
As with all SlNetUtil API's, SlNetUtil_init() must have previously been called.
Example
Copyright 2017, Texas Instruments Incorporated