Sockets related commands and configuration.
More...
|
#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) ) |
|
|
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...
|
|
Sockets related commands and configuration.
§ 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) ) |
§ SlNetUtil_init()
int32_t SlNetUtil_init |
( |
int32_t |
flags | ) |
|
Initialize the SlNetUtil module.
- Parameters
-
- 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] | ifBitmap | Specifies 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] | name | Host name |
[in] | nameLen | Name length |
[out] | ipAddr | This parameter is filled in with an array of IP addresses. In case that host name is not resolved, ipAddrLen is zero. |
[in,out] | ipAddrLen | Holds the size of the ipAddr array, when function successful, the ipAddrLen parameter will be updated with the number of the IP addresses found. |
[in] | family | Protocol 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
- Getting IPv4 using get host by name:
uint16_t DestIPListSize = 1;
uint32_t DestIP[1];
uint32_t ifID;
int16_t SockId;
int32_t LocalAddrSize;
if (SockId >= 0)
{
}
§ SlNetUtil_htonl()
uint32_t SlNetUtil_htonl |
( |
uint32_t |
val | ) |
|
§ SlNetUtil_ntohl()
uint32_t SlNetUtil_ntohl |
( |
uint32_t |
val | ) |
|
§ SlNetUtil_htons()
uint16_t SlNetUtil_htons |
( |
uint16_t |
val | ) |
|
§ SlNetUtil_ntohs()
uint16_t SlNetUtil_ntohs |
( |
uint16_t |
val | ) |
|
§ 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] | addrFamily | Specifies the address family of the created socket For example:
|
[in] | binaryAddr | Pointer to an IP address structure indicating the address in binary representation |
[out] | strAddr | Pointer to the address string representation for IPv4 or IPv6 according to the address family |
[in] | strAddrLen | Specifies 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] | addrFamily | Specifies the address family of the created socket For example:
|
[out] | strAddr | Specifies the IP address in string representation for IPv4 or IPv6 according to the address family |
[in] | binaryAddr | Pointer 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
-