resolve-host.c revision bdef7319e4145fec3160468a1ef9775d682f2fa4
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 Zbigniew Jędrzejewski-Szmek
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 <getopt.h>
#include "sd-bus.h"
#include "bus-util.h"
#include "bus-error.h"
#include "bus-errors.h"
#include "in-addr-util.h"
#include "af-list.h"
#include "build.h"
static int arg_family = AF_UNSPEC;
static int arg_ifindex = 0;
unsigned c = 0;
int r;
log_debug("Resolving %s (family %s)",
bus,
&req,
"org.freedesktop.resolve1",
"/org/freedesktop/resolve1",
"org.freedesktop.resolve1.Manager",
"ResolveHostname");
if (r < 0) {
return r;
}
r = sd_bus_message_set_auto_start(req, false);
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
if (r < 0) {
return r;
}
const void *a;
if (r < 0) {
log_error("Cannot parse message, aborting.");
return -EBADMSG;
}
if (r < 0) {
log_error("Cannot parse message, aborting.");
return -EBADMSG;
}
if (r < 0) {
log_error("Cannot parse message, aborting.");
return -EBADMSG;
}
if (r < 0) {
log_error("Cannot parse message, aborting.");
return -EBADMSG;
}
log_debug("%s: skipping entry with family %hu (%s)",
continue;
}
log_error("%s: systemd-resolved returned address of invalid size %zu for family %s",
continue;
}
if (ifindex < 0) {
log_error("%s: systemd-resolved returned invalid interface index %i",
continue;
}
if (ifindex > 0) {
char *t;
if (!t) {
continue;
}
}
log_debug("%s: skipping entry with ifindex %i (%s)",
continue;
}
if (r < 0) {
continue;
}
log_info("%*s%s %s%s%.*s",
c++;
}
if (c == 0) {
return -ENONET;
}
return sd_bus_message_exit_container(reply);
}
static void help(void) {
printf("%s [OPTIONS...]\n\n"
"Resolve IPv4 or IPv6 addresses.\n\n"
"Options:\n"
" -4 Resolve IPv4 addresses\n"
" -6 Resolve IPv6 addresses\n"
" -i INTERFACE Filter by interface\n"
" -h --help Show this help and exit\n"
" --version Print version string and exit\n"
);
}
enum {
ARG_VERSION = 0x100,
};
{}
};
int c;
switch(c) {
case 'h':
help();
return 0; /* done */;
case ARG_VERSION:
return 0 /* done */;
case '4':
break;
case '6':
break;
case 'i':
if (arg_ifindex <= 0) {
return -EINVAL;
}
break;
case '?':
return -EINVAL;
default:
assert_not_reached("Unhandled option");
}
return 1 /* work to do */;
}
int r;
log_open();
if (r <= 0)
goto end;
r = sd_bus_open_system(&bus);
if (r < 0) {
goto end;
}
int k;
if (r == 0)
r = k;
}
end:
return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}