Unix Socket IP Address Functions - Unix socket

How IP Address Functions used in Unix Socket?

Unix provides a variety of useful functions for manipulating IP addresses. These functions can convert Internet addresses between ASCII strings (what humans want to use) and network byte binary values (stored in the socket address structure).

For IPv4 addressing, the following three function calls are used:

  • int inet_aton(const char *strptr, struct in_addr *addrptr)
  • in_addr_t inet_addr(const char *strptr)
  • char *inet_ntoa(struct in_addr inaddr)

int inet_aton(const char *strptr, struct in_addr *addrptr)

This function call converts the string specified by the Internet standard point symbol to a network address and stores the address in the provided structure. The translated address is the network byte order (the number of bytes arranged from left to right). Returns 1 if the string is valid, 0 if it is an error.

Use examples as follows:

in_addr_t inet_addr(const char *strptr)

This function call converts the string specified by the Internet standard point notation into an integer value suitable for use as an Internet address. The translated addresses are in the order of network bytes (bytes from left to right). It returns an ordered IPv4 address and an INADDR_NONE error of 32-bit binary network byte.

The following is an example of usage

char *inet_ntoa(struct in_addr inaddr)

This function call converts the specified Internet host address to a string in the Internet standard point symbol.

Use examples as follows:

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Unix socket Topics