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

libnl 3.12.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 "nl-default.h"
7
8#include <netlink/cli/utils.h>
9
10int main(int argc, char *argv[])
11{
12 int err;
13 char host[256];
14 struct nl_addr *a;
15
16 if (argc < 2) {
17 fprintf(stderr, "Usage: nl-util-addr <address>\n");
18 return -1;
19 }
20
21 a = nl_cli_addr_parse(argv[1], AF_UNSPEC);
22 err = nl_addr_resolve(a, host, sizeof(host));
23 if (err != 0)
24 nl_cli_fatal(err, "Unable to resolve address \"%s\": %s",
25 argv[1], nl_geterror(err));
26
27 printf("%s\n", host);
28
29 return 0;
30}
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:850
nl_cli_fatal
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Definition utils.c:71