mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
util-lib: add function to resolve "alternative" names
Calls to if_nametoindex() are expected to use resolve_ifname() instead.
This commit is contained in:
@@ -10,11 +10,26 @@
|
||||
#include "extract-word.h"
|
||||
#include "log.h"
|
||||
#include "memory-util.h"
|
||||
#include "netlink-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "socket-netlink.h"
|
||||
#include "socket-util.h"
|
||||
#include "string-util.h"
|
||||
|
||||
int resolve_ifname(sd_netlink **rtnl, const char *name) {
|
||||
int r;
|
||||
|
||||
/* Like if_nametoindex, but resolves "alternative names" too. */
|
||||
|
||||
assert(name);
|
||||
|
||||
r = if_nametoindex(name);
|
||||
if (r > 0)
|
||||
return r;
|
||||
|
||||
return rtnl_resolve_link_alternative_name(rtnl, name);
|
||||
}
|
||||
|
||||
int socket_address_parse(SocketAddress *a, const char *s) {
|
||||
_cleanup_free_ char *n = NULL;
|
||||
char *e;
|
||||
@@ -140,15 +155,12 @@ int socket_address_parse(SocketAddress *a, const char *s) {
|
||||
a->sockaddr.in.sin_port = htobe16(port);
|
||||
a->size = sizeof(struct sockaddr_in);
|
||||
} else {
|
||||
unsigned idx;
|
||||
|
||||
if (strlen(n) > IF_NAMESIZE-1)
|
||||
return -EINVAL;
|
||||
int idx;
|
||||
|
||||
/* Uh, our last resort, an interface name */
|
||||
idx = if_nametoindex(n);
|
||||
if (idx == 0)
|
||||
return -EINVAL;
|
||||
idx = resolve_ifname(NULL, n);
|
||||
if (idx < 0)
|
||||
return idx;
|
||||
|
||||
a->sockaddr.in6.sin6_family = AF_INET6;
|
||||
a->sockaddr.in6.sin6_port = htobe16(port);
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include "sd-netlink.h"
|
||||
|
||||
#include "in-addr-util.h"
|
||||
#include "macro.h"
|
||||
#include "socket-util.h"
|
||||
|
||||
int resolve_ifname(sd_netlink **rtnl, const char *name);
|
||||
|
||||
int make_socket_fd(int log_level, const char* address, int type, int flags);
|
||||
|
||||
int socket_address_parse(SocketAddress *a, const char *s);
|
||||
|
||||
Reference in New Issue
Block a user