| OLD | NEW |
| 1 #include <sys/socket.h> | 1 #include <sys/socket.h> |
| 2 #include <netinet/in.h> | 2 #include <netinet/in.h> |
| 3 #include <netdb.h> | 3 #include <netdb.h> |
| 4 #include <net/if.h> | 4 #include <net/if.h> |
| 5 #include <arpa/inet.h> | 5 #include <arpa/inet.h> |
| 6 #include <limits.h> | 6 #include <limits.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <ctype.h> | 9 #include <ctype.h> |
| 10 #include "lookup.h" | 10 #include "lookup.h" |
| 11 | 11 |
| 12 int __inet_aton(const char *, struct in_addr *); | 12 int __inet_aton(const char*, struct in_addr*); |
| 13 | 13 |
| 14 int __lookup_ipliteral(struct address buf[static 1], const char *name, int famil
y) | 14 int __lookup_ipliteral(struct address buf[static 1], |
| 15 { | 15 const char* name, |
| 16 » struct in_addr a4; | 16 int family) { |
| 17 » struct in6_addr a6; | 17 struct in_addr a4; |
| 18 » if (__inet_aton(name, &a4) > 0) { | 18 struct in6_addr a6; |
| 19 » » if (family == AF_INET6) /* wrong family */ | 19 if (__inet_aton(name, &a4) > 0) { |
| 20 » » » return EAI_NONAME; | 20 if (family == AF_INET6) /* wrong family */ |
| 21 » » memcpy(&buf[0].addr, &a4, sizeof a4); | 21 return EAI_NONAME; |
| 22 » » buf[0].family = AF_INET; | 22 memcpy(&buf[0].addr, &a4, sizeof a4); |
| 23 » » buf[0].scopeid = 0; | 23 buf[0].family = AF_INET; |
| 24 » » return 1; | 24 buf[0].scopeid = 0; |
| 25 » } | 25 return 1; |
| 26 } |
| 26 | 27 |
| 27 » char tmp[64]; | 28 char tmp[64]; |
| 28 » char *p = strchr(name, '%'), *z; | 29 char *p = strchr(name, '%'), *z; |
| 29 » unsigned long long scopeid = 0; | 30 unsigned long long scopeid = 0; |
| 30 » if (p && p-name < 64) { | 31 if (p && p - name < 64) { |
| 31 » » memcpy(tmp, name, p-name); | 32 memcpy(tmp, name, p - name); |
| 32 » » tmp[p-name] = 0; | 33 tmp[p - name] = 0; |
| 33 » » name = tmp; | 34 name = tmp; |
| 34 » } | 35 } |
| 35 | 36 |
| 36 » if (inet_pton(AF_INET6, name, &a6) <= 0) | 37 if (inet_pton(AF_INET6, name, &a6) <= 0) |
| 37 » » return 0; | 38 return 0; |
| 38 » if (family == AF_INET) /* wrong family */ | 39 if (family == AF_INET) /* wrong family */ |
| 39 » » return EAI_NONAME; | 40 return EAI_NONAME; |
| 40 | 41 |
| 41 » memcpy(&buf[0].addr, &a6, sizeof a6); | 42 memcpy(&buf[0].addr, &a6, sizeof a6); |
| 42 » buf[0].family = AF_INET6; | 43 buf[0].family = AF_INET6; |
| 43 » if (p) { | 44 if (p) { |
| 44 » » if (isdigit(*++p)) scopeid = strtoull(p, &z, 10); | 45 if (isdigit(*++p)) |
| 45 » » else z = p-1; | 46 scopeid = strtoull(p, &z, 10); |
| 46 » » if (*z) { | 47 else |
| 47 » » » if (!IN6_IS_ADDR_LINKLOCAL(&a6) && | 48 z = p - 1; |
| 48 » » » !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) | 49 if (*z) { |
| 49 » » » » return EAI_NONAME; | 50 if (!IN6_IS_ADDR_LINKLOCAL(&a6) && !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) |
| 50 » » » scopeid = if_nametoindex(p); | 51 return EAI_NONAME; |
| 51 » » » if (!scopeid) return EAI_NONAME; | 52 scopeid = if_nametoindex(p); |
| 52 » » } | 53 if (!scopeid) |
| 53 » » if (scopeid > UINT_MAX) return EAI_NONAME; | 54 return EAI_NONAME; |
| 54 » } | 55 } |
| 55 » buf[0].scopeid = scopeid; | 56 if (scopeid > UINT_MAX) |
| 56 » return 1; | 57 return EAI_NONAME; |
| 58 } |
| 59 buf[0].scopeid = scopeid; |
| 60 return 1; |
| 57 } | 61 } |
| OLD | NEW |