summaryrefslogtreecommitdiff
path: root/src/network/lookup.h
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-05-31 20:57:54 -0400
committerRich Felker <dalias@aerifal.cx>2014-05-31 20:57:54 -0400
commit6f409bff008a83fa6bc640c10366765874de35e2 (patch)
tree4c192acbf8bdd019719dd9536cc3eaae0de3696c /src/network/lookup.h
parent5f4c4966934b913e9f8a54d60312f874a9d14088 (diff)
downloadmusl-6f409bff008a83fa6bc640c10366765874de35e2.tar.gz
refactor getaddrinfo and add support for most remaining features
this is the first phase of the "resolver overhaul" project. conceptually, the results of getaddrinfo are a direct product of a list of address results and a list of service results. the new code makes this explicit by computing these lists separately and combining the results. this adds support for services that have both tcp and udp versions, where the caller has not specified which it wants, and eliminates a number of duplicate code paths which were all producing the final output addrinfo structures, but in subtly different ways, making it difficult to implement any of the features which were missing. in addition to the above benefits, the refactoring allows for legacy functions like gethostbyname to be implemented without using the getaddrinfo function itself. such changes to the legacy functions have not yet been made, however. further improvements include matching of service alias names from /etc/services (previously only the primary name was supported), returning multiple results from /etc/hosts (previously only the first matching line was honored), and support for the AI_V4MAPPED and AI_ALL flags. features which remain unimplemented are IDN translations (encoding non-ASCII hostnames for DNS lookup) and the AI_ADDRCONFIG flag. at this point, the DNS-based name resolving code is still based on the old interfaces in __dns.c, albeit somewhat simpler in its use of them. there may be some dead code which could already be removed, but changes to this layer will be a later phase of the resolver overhaul.
Diffstat (limited to 'src/network/lookup.h')
-rw-r--r--src/network/lookup.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/network/lookup.h b/src/network/lookup.h
new file mode 100644
index 00000000..82c969ec
--- /dev/null
+++ b/src/network/lookup.h
@@ -0,0 +1,26 @@
+#ifndef LOOKUP_H
+#define LOOKUP_H
+
+#include <stdint.h>
+
+struct address {
+ int family;
+ unsigned scopeid;
+ uint8_t addr[16];
+};
+
+struct service {
+ uint16_t port;
+ char proto;
+};
+
+/* The limit of 48 results is a non-sharp bound on the number of addresses
+ * that can fit in one 512-byte DNS packet full of v4 results and a second
+ * packet full of v6 results. Due to headers, the actual limit is lower. */
+#define MAXADDRS 48
+#define MAXSERVS 2
+
+int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int flags);
+int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags);
+
+#endif