scan_ip6if - Man Page

parse an IPv6 number and interface in ASCII representation

Syntax

#include <ip6.h>

int scan_ip6if(const char *src,char ip[16],uint32* scope_id);

Description

scan_ip6if parses an IPv6 number in RFC1884 ASCII representation from src and writes the result into ip. If the IPv6 number is followed by the percent sign, scan_ip6if takes the word following that, tries to parse it as network interface and writes the result to scope_id.

It returns the number of bytes read from src or 0 if the parsing failed.

scan_ip6if accepts upper and lower case hex letters, it understands "::" compression and partial IPv4 addresses as in "::FFFF:129.144.52.38".

To allow transparent usage of IPv4 in IPv6 applications, scan_ip6if also understands IPv4 addresses in dotted-decimal notation and will return an IPv4-mapped IPv6 address (i.e. "127.0.0.1" will be parsed as "::FFFF:127.0.0.1".

Unlike many other IP parsing routines, scan_ip6if does not recognize octal (like 0177.0.0.1) or hexadecimal numbers (like 0x7f000001) in the IPv4 part.

Example

#include <str.h>
#include <ip6.h>

 char buf[]="::1%lo";
 char ip[16];
 uint32 scope_id;
 if (scan_ip6if(buf,ip,&scope_id) != str_len(buf))
   parse_error();

See Also

fmt_ip6(3), scan_ip4(3), fmt_ip6if(3)

Referenced By

scan_ip6(3).