summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-12-04 12:41:39 +0100
committerxengineering <me@xengineering.eu>2022-12-04 12:41:39 +0100
commit0de21ec65f3c28f2acc947c00c3cb26dc9ea4ecd (patch)
tree1d8490f38520908f55f38edbc050920f9eebb15e
parentd3a952c04f16723a5dc86fccc5919082dcd1c90e (diff)
downloadlimox-0de21ec65f3c28f2acc947c00c3cb26dc9ea4ecd.tar
limox-0de21ec65f3c28f2acc947c00c3cb26dc9ea4ecd.tar.zst
limox-0de21ec65f3c28f2acc947c00c3cb26dc9ea4ecd.zip
Implement DNS with a temporary solution
The DNS resolution implemented with this commit uses getaddrinfo() from the standard library to get an IPv4 address for the domainpart of the user-given Jabber ID (JID). This is by far not the process described in [RFC 6120][1]. This XMPP core standard prefers SRV entry lookups. Taking A records like in this implementation is referenced as "fallback process". Furthermore this implementation just takes the first A record it finds which could also be improved. It could for example be that IPv4 is blocked in the referenced network and a AAAA IPv6 record is given and functional. In this case this implementation would needlessly fail to connect. [1]: https://www.rfc-editor.org/rfc/rfc6120
-rw-r--r--xmpp.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/xmpp.c b/xmpp.c
index dda49dd..9db1574 100644
--- a/xmpp.c
+++ b/xmpp.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <arpa/inet.h>
#include <netdb.h>
@@ -62,11 +63,17 @@ char *get_domainpart(char *jid)
* This handles DNS resolution. It returns the first valid addrinfo which is
* returned by getaddrinfo. Mind that the addrinfo could use IPv6 instead of
* IPv4.
+ *
+ * FIXME this just takes the first received IPv4 address (by far not compliant
+ * to RFC 6120!)
+ * FIXME This function contains a memory leak! Free the linked list servinfo!
*/
struct addrinfo *get_addrinfo(char *domain)
{
struct addrinfo hints;
struct addrinfo *servinfo;
+ void *addr;
+ char ipstr[INET6_ADDRSTRLEN];
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
@@ -77,14 +84,18 @@ struct addrinfo *get_addrinfo(char *domain)
struct addrinfo *p;
for(p=servinfo; p!=NULL; p=p->ai_next) {
if (p->ai_family == AF_INET) {
- printf("an IPv4!\n"); // TODO
-
+ struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
+ addr = &(ipv4->sin_addr);
+ inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
+ printf("Got compatible IPv4 address %s from DNS.\n", ipstr);
+ return p;
} else if (p->ai_family == AF_INET6) {
- printf("an IPv6!\n"); // TODO
+ printf("Ignored IPv6 DNS entry which is not supported.\n");
} else {
- printf("Unknown addrinfo address type.\n");
+ printf("Ignored unknown addrinfo address type.\n");
}
}
+ printf("No suitable IP address found via DNS!\n");
return NULL;
}