diff options
Diffstat (limited to 'xmpp.c')
-rw-r--r-- | xmpp.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -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; } |