inet_aton()
PROTOTYPE
#include <sockets.h>
int inet_aton(const char strptr, struct in_addr *addrptr);
DESCRIPTION
inet_aton() converts an IPv4 address from an Internet dotted notation string to an integer address in network byte order. addrptr points to a buffer where the converted address is stored. strptr points to the string to be converted, which should have one of the following formats:
"a" - where a is a 32-bit number,
"a.b" - where a is an 8-bit number and b is a 24-bit number,
"a.b.c" - where a and b are 8-bit numbers and c is a 16-bit number, or
"a.b.c.d" - where a, b, c, and d are 8-bit numbers.
If there is a leading “0x” or “0X”, the numbers are interpreted as hexadecimal. If there is a leading “0”, they are interpreted as octal. Otherwise, the numbers are interpreted as decimal.
inet_aton() returns 1 if the conversion is successful or 0 if it failed.
EXAMPLE
/***********************************************************************/
/* getHostByName: Request IP address resolution from DNS server */
/* */
/* Input: name = NULL-terminated host name */
/* */
/* Returns: IP address if no errors, else 0 */
/* */
/***********************************************************************/
in_addr_t getHostByName(const char *name)
{
uint dotted;
const char *np;
struct in_addr addr;
/*-------------------------------------------------------------------*/
/* Check if name is just address in Internet dotted notation. */
/*-------------------------------------------------------------------*/
if (inet_aton(name, &addr))
return addr.s_addr;