Macros | Functions | Variables
INET: Internet protocol

Internet name resolution, socket and connection handling. More...

Macros

#define MAIN_ERR_PREFIX   "INET: "
 Message prefix for INET module.
 

Functions

int inet_connect (int *sd, int *af, const char *host, const char *service)
 Establish stream oriented connection. More...
 
int inet_set_rx_timeout (int sd, unsigned int rx_to)
 Try to set RX timeout for socket. More...
 
int inet_set_tx_timeout (int sd, unsigned int tx_to)
 Try to set TX timeout for socket. More...
 
void inet_close (int *sd)
 Close connection and destroy socket. More...
 

Variables

int inet_force_ipv4
 
int inet_force_ipv4 = 0
 

Error codes

#define INET_ERR_UNSPEC   -1
 Unspecified error.
 
#define INET_ERR_HNR   -2
 Host name resolution failed.
 
#define INET_ERR_SNR   -3
 Service name resolution failed.
 
#define INET_ERR_AF   -4
 Address family not supported.
 
#define INET_ERR_SOCK   -5
 Socket creation/configuration failed.
 
#define INET_ERR_CONN   -6
 Connection failed.
 
#define INET_ERR_BADF   -7
 Invalid socket descriptor.
 
#define INET_ERR_RX_TO   -8
 Setting RX timeout failed.
 
#define INET_ERR_TX_TO   -9
 Setting TX timeout failed.
 

Socket option actions

#define INET_OPTS_CLEAR   0
 Remove socket options.
 
#define INET_OPTS_SET   1
 Add socket options.
 

Detailed Description

Internet name resolution, socket and connection handling.

Function Documentation

◆ inet_close()

void inet_close ( int *  sd)

Close connection and destroy socket.

Parameters
[in,out]sdPointer to socket descriptor
Note
It is save to call this function with sd pointing to -1 . This will execute as NOP.
The value -1 is present at the location pointed to by sd in any case after return.

Definition at line 524 of file inet.c.

◆ inet_connect()

int inet_connect ( int *  sd,
int *  af,
const char *  host,
const char *  service 
)

Establish stream oriented connection.

Parameters
[out]sdPointer to socket descriptor
[in,out]afAddress family
[in]hostName of host
[in]serviceName of service

On success the socket descriptor of the established connection is written to the location pointed to by sd . If the address family was specified as POSIX_AF_UNSPEC or was enforced by configuration, it is overwritten with the address family that was used to establish the connection.

On error -1 is written to the location pointed to by sd and the value pointed to by af is unchanged.

Note
If the name resolver reports multiple addresses for host , all entries are tried in order. If no connection could be established, error status is returned for the last entry in the list.
Returns
  • Zero if connection was successfully established
  • Negative value on error (use INET_ERR_xxx constants for checks)

Definition at line 254 of file inet.c.

◆ inet_set_rx_timeout()

int inet_set_rx_timeout ( int  sd,
unsigned int  rx_to 
)

Try to set RX timeout for socket.

Parameters
[in]sdSocket descriptor
[in]rx_toRX timeout in seconds (Upper limit: 3600)
Attention
On POSIX systems it is implementation defined whether timeouts on sockets can be set or not. It is no misbehaviour if the OS rejects the requests and this function returns an error.

If rx_to is set to zero this means "no timeout" (an existing timeout setting will be removed).

Note
POSIX offers no way to get the type (integer and floating point allowed) and range of "time_t". We limit the range to [0, 3600], expecting that every sane platform can handle 1 hour (even if this strictly isn't required by C90 and POSIX).
Returns
  • Zero on success
  • Negative value on error (use INET_ERR_xxx constants for checks)

Definition at line 419 of file inet.c.

References INET_ERR_BADF, INET_ERR_RX_TO, INET_ERR_UNSPEC, and PRINT_ERROR.

◆ inet_set_tx_timeout()

int inet_set_tx_timeout ( int  sd,
unsigned int  tx_to 
)

Try to set TX timeout for socket.

Parameters
[in]sdSocket descriptor
[in]tx_toTX timeout in seconds (Upper limit: 3600)
Attention
On POSIX systems it is implementation defined whether timeouts on sockets can be set or not. It is no misbehaviour if the OS rejects the requests and this function returns an error.

If tx_to is set to zero this means "no timeout" (an existing timeout setting will be removed).

Note
POSIX offers no way to get the type (integer and floating point allowed) and range of "time_t". We limit the range to [0, 3600], expecting that every sane platform can handle 1 hour (even if this strictly isn't required by C90 and POSIX).
Returns
  • Zero on success
  • Negative value on error (use INET_ERR_xxx constants for checks)

Definition at line 477 of file inet.c.

References INET_ERR_BADF, INET_ERR_TX_TO, INET_ERR_UNSPEC, and PRINT_ERROR.


Generated at 2024-04-27 using  doxygen