1 #include <sys/socket.h>
2 #include <netinet/in.h>
11 int __inet_aton(const char *, struct in_addr *);
13 int __lookup_ipliteral(struct address buf[static 1], const char *name, int family)
17 if (family != AF_INET6 && __inet_aton(name, &a4)>0) {
18 memcpy(&buf[0].addr, &a4, sizeof a4);
19 buf[0].family = AF_INET;
23 if (family != AF_INET) {
25 char *p = strchr(name, '%'), *z;
26 unsigned long long scopeid;
27 if (p && p-name < 64) {
28 memcpy(tmp, name, p-name);
32 if (inet_pton(AF_INET6, name, &a6)<=0) return 0;
33 memcpy(&buf[0].addr, &a6, sizeof a6);
34 buf[0].family = AF_INET6;
36 if (isdigit(*++p)) scopeid = strtoull(p, &z, 10);
39 if (!IN6_IS_ADDR_LINKLOCAL(&a6) &&
40 !IN6_IS_ADDR_MC_LINKLOCAL(&a6))
42 scopeid = if_nametoindex(p);
43 if (!scopeid) return EAI_NONAME;
45 if (scopeid > UINT_MAX) return EAI_NONAME;
46 buf[0].scopeid = scopeid;