libnl 3.5.0

nl-util-addr.c
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * src/nl-util-addr.c Address Helper
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation version 2.1
8 * of the License.
9 *
10 * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
11 */
12
13 #include <netlink/cli/utils.h>
14
15 int main(int argc, char *argv[])
16 {
17 int err;
18 char host[256];
19 struct nl_addr *a;
20
21 if (argc < 2) {
22 fprintf(stderr, "Usage: nl-util-addr <address>\n");
23 return -1;
24 }
25
26 a = nl_cli_addr_parse(argv[1], AF_UNSPEC);
27 err = nl_addr_resolve(a, host, sizeof(host));
28 if (err != 0)
29 nl_cli_fatal(err, "Unable to resolve address \"%s\": %s",
30 argv[1], nl_geterror(err));
31
32 printf("%s\n", host);
33
34 return 0;
35 }
nl_addr_resolve
int nl_addr_resolve(const struct nl_addr *addr, char *host, size_t hostlen)
Resolve abstract address object to a name using getnameinfo().
Definition: addr.c:849
nl_cli_fatal
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Definition: utils.c:78