test-resolve.c revision 279d3c9cead3a7ffb657fedbab0e2bc90db45667
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2005-2008 Lennart Poettering
Copyright 2014 Daniel Buch
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <string.h>
#include <stdio.h>
#include <resolv.h>
#include <assert.h>
#include <signal.h>
#include <errno.h>
#include "socket-util.h"
#include "sd-resolve.h"
#include "resolve-util.h"
#include "macro.h"
static int getaddrinfo_handler(sd_resolve_query *q, int ret, const struct addrinfo *ai, void *userdata) {
const struct addrinfo *i;
assert(q);
if (ret != 0) {
return 0;
}
}
return 0;
}
static int getnameinfo_handler(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata) {
assert(q);
if (ret != 0) {
return 0;
}
return 0;
}
char name[256];
assert(q);
if (ret < 0) {
return 0;
}
if (ret == 0) {
log_error("No reply for SRV lookup");
return 0;
}
/* Ignore the questions */
}
/* Parse the answers */
/* Ignore the initial string */
/* Ignore type, ttl, class and dlen */
pos += 10;
printf("\tpreference: %2d weight: %2d port: %d host: %s\n",
}
return 0;
}
int r = 0;
};
struct sockaddr_in sa = {
.sin_family = AF_INET,
};
/* Test a floating resolver query */
/* Make a name -> address query */
r = sd_resolve_getaddrinfo(resolve, &q1, argc >= 2 ? argv[1] : "www.heise.de", NULL, &hints, getaddrinfo_handler, NULL);
if (r < 0)
log_error_errno(r, "sd_resolve_getaddrinfo(): %m");
/* Make an address -> name query */
r = sd_resolve_getnameinfo(resolve, &q2, (struct sockaddr*) &sa, sizeof(sa), 0, SD_RESOLVE_GET_BOTH, getnameinfo_handler, NULL);
if (r < 0)
log_error_errno(r, "sd_resolve_getnameinfo(): %m");
/* Make a res_query() call */
r = sd_resolve_res_query(resolve, &q3, "_xmpp-client._tcp.gmail.com", C_IN, T_SRV, res_handler, NULL);
if (r < 0)
log_error_errno(r, "sd_resolve_res_query(): %m");
/* Wait until the three queries are completed */
while (sd_resolve_query_is_done(q1) == 0 ||
sd_resolve_query_is_done(q2) == 0 ||
sd_resolve_query_is_done(q3) == 0) {
if (r < 0) {
log_error_errno(r, "sd_resolve_wait(): %m");
assert_not_reached("sd_resolve_wait() failed");
}
}
return 0;
}