Network Services API  2.75.00.17
Data Structures | Macros | Typedefs | Functions
SlNetUtils group

Sockets related commands and configuration. More...

Data Structures

struct  SlNetUtil_addrInfo_t
 

Macros

#define SLNETUTIL_AI_PASSIVE   0x00000001
 
#define SLNETUTIL_AI_NUMERICHOST   0x00000004
 
#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) )
 

Typedefs

typedef struct SlNetUtil_addrInfo_t SlNetUtil_addrInfo_t
 

Functions

int32_t SlNetUtil_init (int32_t flags)
 Initialize the SlNetUtil module. More...
 
const char * SlNetUtil_gaiStrErr (int32_t errorCode)
 Return text descriptions of getAddrInfo error codes. 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...
 
int32_t SlNetUtil_getAddrInfo (uint16_t ifID, const char *node, const char *service, const struct SlNetUtil_addrInfo_t *hints, struct SlNetUtil_addrInfo_t **res)
 Network address and service translation. More...
 
void SlNetUtil_freeAddrInfo (struct SlNetUtil_addrInfo_t *res)
 Free the results returned from SlNetUtil_getAddrInfo. 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...
 
int SlNetUtil_inetAton (const char *str, struct SlNetSock_InAddr_t *addr)
 Convert an IPv4 address in string format to binary format. 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_AI_PASSIVE

#define SLNETUTIL_AI_PASSIVE   0x00000001

§ SLNETUTIL_AI_NUMERICHOST

#define SLNETUTIL_AI_NUMERICHOST   0x00000004

§ 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) )

Typedef Documentation

§ SlNetUtil_addrInfo_t

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_gaiStrErr()

const char* SlNetUtil_gaiStrErr ( int32_t  errorCode)

Return text descriptions of getAddrInfo error codes.

Parameters
[in]errorCodeA getAddrInfo error code
Returns
Text description of the passed in getAddrInfo error code. If the error code does not exist returns "Unknown Error"

§ 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 host ip needs to be retrieved from according to the 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]ipAddrA buffer used to store the IP address(es) from the resulting DNS resolution. The caller is responsible for allocating this buffer. Upon return, this buffer can be accessed as an array of IPv4 or IPv6 addresses, depending on the protocol passed in for the family parameter. Addresses are stored in host byte order.
[in,out]ipAddrLenInitially holds the number of IP addresses that the ipAddr buffer parameter is capable of storing. Upon successful return, the ipAddrLen parameter contains the number of IP addresses that were actually written into the ipAddr buffer, as a result of successful DNS resolution, or zero if DNS resolution failed.
[in]familyProtocol family
Returns
The interface ID of the interface which was able to successfully run 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_getAddrInfo()

int32_t SlNetUtil_getAddrInfo ( uint16_t  ifID,
const char *  node,
const char *  service,
const struct SlNetUtil_addrInfo_t hints,
struct SlNetUtil_addrInfo_t **  res 
)

Network address and service translation.

Create an IPv4 or IPv6 socket address structure, to be used with bind() and/or connect() to create a client or server socket

This is a "minimal" version for support on embedded devices. Supports a host name or an IPv4 or IPv6 address string passed in via the 'node' parameter for creating a client socket. A value of NULL should be passed for 'node' with AI_PASSIVE flag set to create a (non-loopback) server socket.

The caller is responsible for freeing the allocated results by calling SlNetUtil_freeAddrInfo().

Parameters
[in]ifIDSpecifies the interface which needs to used for socket operations.
The values of the interface identifier is defined with the prefix SLNETIF_ID_ which defined in slnetif.h
[in]nodeAn IP address or a host name.
[in]serviceThe port number of the service to bind or connect to.
[in]hintsAn SlNetUtil_addrInfo_t struct used to filter the results returned.
[out]resone or more SlNetUtil_addrInfo_t structs, each of which can be used to bind or connect a socket.
Returns
Returns 0 on success, or an error code on failure.
See also
SlNetUtil_freeAddrInfo()

§ SlNetUtil_freeAddrInfo()

void SlNetUtil_freeAddrInfo ( struct SlNetUtil_addrInfo_t res)

Free the results returned from SlNetUtil_getAddrInfo.

Free the chain of SlNetUtil_addrInfo_t structs allocated and returned by SlNetUtil_getAddrInfo

Parameters
[in]reslinked list of results returned from SlNetUtil_getAddrInfo
Returns
None.
See also
SlNetUtil_getAddrInfo()

§ 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_inetAton()

int SlNetUtil_inetAton ( const char *  str,
struct SlNetSock_InAddr_t addr 
)

Convert an IPv4 address in string format to binary format.

This function converts an IPv4 address stored as a character string to a 32-bit binary value in network byte order. Note that a leading zero or a "0x" in the address string are interpreted as octal or hexadecimal, respectively. The function stores the IPv4 address in the address structure pointed to by the addr parameter.

Parameters
[in]strIPv4 address string in dotted decimal format
[out]addrpointer to an IPv4 address structure. The converted binary address is stored in this structure upon return (in network byte order)
Returns
returns nonzero if the address string is valid, zero if not

§ 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. The address is assumed to be in network-byte order
[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:
[in]strAddrSpecifies the IP address in string representation for IPv4 or IPv6 according to the address family
[out]binaryAddrPointer to an address structure that will be filled by the IP address in Binary representation. The address is returned in network-byte order
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 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale