Address Handling Functions

Address Parsing Function.

Functions

int trfCheckIPVersion(char *addr)

Check ip address if it is IPV4 or IPV6.

Parameters:

addr – the ip address string

Returns:

4 if it is ipv4, 6 if it is ipv6, and -1 if it is neither

int trfGetMappedIPv4addr(struct sockaddr_in6 *addr, char *address)

Converts and IPV6-mapped IPV4 address to an IPV4 address.

Parameters:
  • addr – The sockaddr_in6 struct container the ipv6 mapped address

  • address – Char pointer the store the decoded ipv4 address

Returns:

returns 0 on success, negative error code on failure

int trfGetIPaddr(struct sockaddr *sdr, char *addr)

Converts a sockaddr structure to string.

Parameters:
  • sdr – Address sockaddr container the ip address to be decoded

  • addr – Char pointer to store the decoded ip address

Returns:

0 on success, negative error code on failure

int trfConvertCharToAddr(char *addr, struct sockaddr *sdr)

Converts a string to an address structure.

Parameters:
  • addr – Char pointer of the IP Address

  • sdr – Sockaddr struct to be decoded into

Returns:

0 on success, negative error code on failure

int trfGetNodeService(struct sockaddr *sdr, char *addr)

Converts a sockaddr structure into a string containing a node and service name in the format node:service for IPv4 and [node]:service for IPv6.

Parameters:
  • sdr – Address sockaddr containing the ip address to be decoded

  • addr – Pointer to store the decoded ip address

Returns:

0 on success, negative error code on failure

int trfNodeServiceToAddr(const char *addr, struct sockaddr *sdr)

Convert Node service to sockaddr struct.

Parameters:
  • addr – addr

  • sdr – sockadd output

Returns:

0 on success, negative error code on failure

int trfCheckNetwork(struct sockaddr *net1, int8_t net1_sn, struct sockaddr *net2, int8_t net2_sn)

Checks if the 2 addresses are in the same network.

Parameters:
  • net1 – First network addresses to compare

  • net1_sn – Subnet of the first address

  • net2 – Second network address to compare to the first one

  • net2_sn – Subnet of the second address

Returns:

1 if the addresses are in the same network, 0 of they are not, negative error code on failure