diff options
Diffstat (limited to 'xmpp.c')
-rw-r--r-- | xmpp.c | 48 |
1 files changed, 41 insertions, 7 deletions
@@ -30,14 +30,51 @@ char *domainpart(char *jid) } } - char* retval = (char *)malloc((stop-start+1) * sizeof(char)); - memcpy(retval, jid+start, (stop-start)*sizeof(char)); + char *retval = (char *)malloc((stop-start+1) * sizeof(char)); + memcpy(retval, jid+start, (stop-start) * sizeof(char)); retval[stop] = '\0'; return retval; } -void net_init(void) +/* + * Return the preferred struct addrinfo * or NULL + * + * 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. + */ +struct addrinfo *get_addrinfo(char *domain) +{ + struct addrinfo hints; + struct addrinfo *servinfo; + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + if (getaddrinfo(domain, "xmpp-client", &hints, &servinfo) != 0) { + printf("Failed to resolve hostname '%s'.\n", domain); + return NULL; + } + struct addrinfo *p; + for(p=servinfo; p!=NULL; p=p->ai_next) { + if (p->ai_family == AF_INET) { + printf("an IPv4!\n"); // TODO + + } else if (p->ai_family == AF_INET6) { + printf("an IPv6!\n"); // TODO + } else { + printf("Unknown addrinfo address type.\n"); + } + } + return NULL; +} + +/* + * Initialize the network connection to the XMPP server + * + * TODO: Error handling is missing. + */ +void xmpp_connect(void) { printf("net_init()\n"); @@ -46,9 +83,6 @@ void net_init(void) char *domain = domainpart(user_str); printf("Trying to connect as '%s' with '%s'.\n", user_str, pwd_str); printf("Domainpart is '%s'.\n", domain); -} -void net_quit(void) -{ - printf("net_quit()\n"); + get_addrinfo(domain); } |