libnl: /data/src/libnl3/src/nl-util-addr.c Source File

libnl 3.7.0

nl-util-addr.c
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
4 */
5
6 #include <netlink/cli/utils.h>
7
8 int main(int argc, char *argv[])
9 {
10 int err;
11 char host[256];
12 struct nl_addr *a;
13
14 if (argc < 2) {
15 fprintf(stderr, "Usage: nl-util-addr <address>\n");
16 return -1;
17 }
18
19 a = nl_cli_addr_parse(argv[1], AF_UNSPEC);
20 err = nl_addr_resolve(a, host, sizeof(host));
21 if (err != 0)
22 nl_cli_fatal(err, "Unable to resolve address \"%s\": %s",
23 argv[1], nl_geterror(err));
24
25 printf("%s\n", host);
26
27 return 0;
28 }
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:842
nl_cli_fatal
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Definition: utils.c:71