1 #include <sys/socket.h>
2 #include <netinet/in.h>
12 int __inet_aton(const char *, struct in_addr *);
14 int __lookup_ipliteral(struct address buf[static 1], const char *name, int family)
18 if (__inet_aton(name, &a4) > 0) {
19 if (family == AF_INET6) /* wrong family */
21 memcpy(&buf[0].addr, &a4, sizeof a4);
22 buf[0].family = AF_INET;
28 char *p = strchr(name, '%'), *z;
29 unsigned long long scopeid = 0;
30 if (p && p-name < 64) {
31 memcpy(tmp, name, p-name);
36 if (inet_pton(AF_INET6, name, &a6) <= 0)
38 if (family == AF_INET) /* wrong family */
41 memcpy(&buf[0].addr, &a6, sizeof a6);
42 buf[0].family = AF_INET6;
44 if (isdigit(*++p)) scopeid = strtoull(p, &z, 10);
47 if (!IN6_IS_ADDR_LINKLOCAL(&a6) &&
48 !IN6_IS_ADDR_MC_LINKLOCAL(&a6))
50 scopeid = if_nametoindex(p);
51 if (!scopeid) return EAI_NONAME;
53 if (scopeid > UINT_MAX) return EAI_NONAME;
55 buf[0].scopeid = scopeid;