5.4. inet — Internet utilities

Source code: src/inet/inet.h, src/inet/inet.c

Test code: tst/inet/inet/inet.c

Test coverage: src/inet/inet.c


int inet_module_init(void)

Initialize the inet module. This function must be called before calling any other function in this module.

The module will only be initialized once even if this function is called multiple times.

zero(0) or negative error code.

int inet_aton(const char *src_p, struct inet_ip_addr_t *dst_p)

Convert the Internet host address src_p from the IPv4 numbers-and-dots notation into binary form (in network byte order) and stores it in the structure that dst_p points to.

The address supplied in src_p can have one of the following forms:

  • a.b.c.d Each of the four numeric parts specifies a byte of the address; the bytes are assigned in left-to-right order to produce the binary address.

zero(0) or negative error code.
  • src_p: Address a.b.c.d to convert into a number.
  • dst_p: Converted address.

char *inet_ntoa(const struct inet_ip_addr_t *src_p, char *dst_p)

Convert the Internet host src_p from the IPv4 binary form (in network byte order) to numbers-and-dots notation and stores it in the structure that dst_p points to.

Converted address pointer or NULL on failure.
  • src_p: Address to convert into a string.
  • dst_p: Converted address as a string.

uint16_t inet_checksum(void *buf_p, size_t size)

Calculate the internet checksum of given buffer.

Calculated checksum.
  • buf_p: Buffer to calculate the chechsum of.
  • size: Size of the buffer.

struct inet_ip_addr_t

Public Members

uint32_t number

IPv4 address.

struct inet_addr_t

Public Members

struct inet_ip_addr_t ip

IPv4 address.

uint16_t port


struct inet_if_ip_info_t
#include <inet.h>

Interface IP information.

Public Members

struct inet_ip_addr_t address
struct inet_ip_addr_t netmask
struct inet_ip_addr_t gateway