From 89ea3fd62d0c8b924198d991c8ee2dcb39f16035 Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson Date: Sat, 27 Nov 2010 01:04:07 +0100 Subject: [PATCH 2/3] inetd: Adapt service nodes to IPv6. --- ChangeLog | 7 +++++++ src/inetd.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletions(-) diff --git a/ChangeLog b/ChangeLog index 232c611..358fece 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-11-27 Mats Erik Andersson + + * src/inetd.c (inetd_getaddrinfo): If IPV6, then add a flag + AI_NUMERICHOST if the node is a numeric address string. + New variable NUMERIC_ADDRESS. Debug symbolic addresses. + (getconfigent): Replace `strchr' with `strrchr'. + 2010-11-26 Mats Erik Andersson * src/inetd.c (print_service): If `ISMUX(SEP)' then present the diff --git a/src/inetd.c b/src/inetd.c index 7f7adbb..3d87867 100644 --- a/src/inetd.c +++ b/src/inetd.c @@ -737,10 +737,33 @@ enter (struct servtab *cp) return sep; } +#define IPV4_NUMCHARS ".0123456789" +#define IPV6_NUMCHARS ".:0123456789abcdefABCDEF" + int inetd_getaddrinfo (struct servtab *sep, int proto, struct addrinfo **result) { struct addrinfo hints; +#ifdef IPV6 + bool numeric_address = false; + + /* In case a numerical address is supplied, which does not + apply to the indicated domain, a non-local resolver + will wait in vain until time out occurs, thus blocking. + Avoid this by falling back to numerical host resolving + when address string seems to be numerical. */ + + /* Purely numeric address? Separate criteria for IPv4 and IPv6, + since IPv6 allows hexadecimal coding and IPv4 mapping! */ + if (sep->se_node + && (strspn (sep->se_node, IPV4_NUMCHARS) == strlen (sep->se_node) + || (strchr (sep->se_node, ':') + && strspn (sep->se_node, IPV6_NUMCHARS)) ) ) + numeric_address = true; + else + if (debug && sep->se_node) + fprintf (stderr, "Resolving address: %s\n", sep->se_node); +#endif /* IPV6 */ memset (&hints, 0, sizeof (hints)); @@ -749,6 +772,10 @@ inetd_getaddrinfo (struct servtab *sep, int proto, struct addrinfo **result) if (sep->se_v4mapped && (sep->se_family != AF_INET)) hints.ai_flags |= AI_V4MAPPED; #endif +#ifdef IPV6 + if (numeric_address) + hints.ai_flags |= AI_NUMERICHOST; +#endif hints.ai_family = sep->se_family; hints.ai_socktype = sep->se_socktype; hints.ai_protocol = proto; @@ -944,7 +971,7 @@ getconfigent (FILE *fconfig, const char *file, size_t *line) sep->se_line = *line; node = argv[INETD_SERVICE]; - service = strchr (node, ':'); + service = strrchr (node, ':'); if (!service) { if (global_serv_node) -- 1.7.2.3