]> git.proxmox.com Git - systemd.git/blob - src/libsystemd-network/network-common.c
New upstream version 249~rc1
[systemd.git] / src / libsystemd-network / network-common.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "format-util.h"
4 #include "network-common.h"
5 #include "string-util.h"
6
7 const char *get_ifname(int ifindex, char **ifname) {
8 char buf[IF_NAMESIZE + 1];
9
10 assert(ifname);
11
12 /* This sets ifname only when it is not set yet. */
13
14 if (*ifname)
15 return *ifname;
16
17 if (ifindex <= 0)
18 return NULL;
19
20 if (!format_ifname(ifindex, buf))
21 return NULL;
22
23 return *ifname = strdup(buf);
24 }