inet_pton()
PROTOTYPE
#include <sockets.h>
int inet_pton(int family, const char strptr, void *addrptr);
DESCRIPTION
inet_pton() converts an IPv4 or IPv6 address from a string form (Internet dotted notation for IPv4 or colon delimited for IPv6) to an integer form in network byte order. family is AF_INET or AF_INET6. strptr points to a buffer where the input is stored. addrptr points to a buffer where the output is stored. The input should have one of the following formats:
"a.b.c.d" - where a, b, c, and d are 8-bit numbers and **family** is AF_INET, or
"ab:cd:ef:gh:ij:kl:mn:op" - where a-p are 8-bit hex numbers and **family** is AF_INET6.
For AF_INET6, preceding zero’s can be eliminated and each sequence of zero’s represented as ‘::’ to simplify presentation. For example, “FE80::200:ff:fe54:8500” is a valid string for the literal address FE80:0000:0000:0000:0200:00FF:FE54:8500.
inet_pton() returns 1 if the conversion is successful, 0 if the string format is invalid, or -1 with errno set.
ERROR CODES
| EAFNOSUPPORT | family is not supported. |
EXAMPLE
/*-----------------------------------------------------------------*/
/* Check if conversion from dotted IPv4 address is successful. */
/*-----------------------------------------------------------------*/
if (inet_pton(AF_INET, host, &addr4) == 1)
{
/*---------------------------------------------------------------*/
/* Connect to the remote FTP server. */
/*---------------------------------------------------------------*/
if (ftp_open(FtpCli, addr4.s_addr, name, pw))
puts("Could not connect to FTP server using those credentials");
else
puts("Connected with IPv4");
return;
}