mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-24 21:34:08 +03:00
ether-addr-util, network: introduce ETHER_ADDR_TO_STR() macro and use it
This commit is contained in:
parent
f929f18c59
commit
4b574fd813
@ -42,6 +42,8 @@ static inline bool hw_addr_is_null(const struct hw_addr_data *addr) {
|
||||
#define ETHER_ADDR_TO_STRING_MAX (3*6)
|
||||
char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]);
|
||||
int ether_addr_to_string_alloc(const struct ether_addr *addr, char **ret);
|
||||
/* Use only as function argument, never stand-alone! */
|
||||
#define ETHER_ADDR_TO_STR(addr) ether_addr_to_string((addr), (char[ETHER_ADDR_TO_STRING_MAX]){})
|
||||
|
||||
int ether_addr_compare(const struct ether_addr *a, const struct ether_addr *b);
|
||||
static inline bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b) {
|
||||
|
@ -1040,7 +1040,6 @@ static int route_dump(Route *route, FILE *f) {
|
||||
}
|
||||
|
||||
void network_dump(Network *network, FILE *f) {
|
||||
char mac[ETHER_ADDR_TO_STRING_MAX];
|
||||
Address *address;
|
||||
Route *route;
|
||||
const char *dhcp;
|
||||
@ -1057,7 +1056,7 @@ void network_dump(Network *network, FILE *f) {
|
||||
fputs("\n[Link]\n", f);
|
||||
|
||||
if (!ether_addr_is_null(&network->mac))
|
||||
fprintf(f, "MACAddress=%s\n", ether_addr_to_string(&network->mac, mac));
|
||||
fprintf(f, "MACAddress=%s\n", ETHER_ADDR_TO_STR(&network->mac));
|
||||
if (network->mtu > 0)
|
||||
fprintf(f, "MTUBytes=%" PRIu32 "\n", network->mtu);
|
||||
|
||||
@ -1111,15 +1110,13 @@ void netdev_dump(NetDev *netdev, FILE *f) {
|
||||
}
|
||||
|
||||
void link_dump(Link *link, FILE *f) {
|
||||
char mac[ETHER_ADDR_TO_STRING_MAX];
|
||||
|
||||
assert(link);
|
||||
assert(f);
|
||||
|
||||
fputs("[Match]\n", f);
|
||||
|
||||
if (!ether_addr_is_null(&link->mac))
|
||||
fprintf(f, "MACAddress=%s\n", ether_addr_to_string(&link->mac, mac));
|
||||
fprintf(f, "MACAddress=%s\n", ETHER_ADDR_TO_STR(&link->mac));
|
||||
|
||||
fprintf(f,
|
||||
"\n[Link]\n"
|
||||
|
@ -1702,7 +1702,6 @@ static int link_status_one(
|
||||
|
||||
if (info->has_permanent_mac_address) {
|
||||
_cleanup_free_ char *description = NULL;
|
||||
char ea[ETHER_ADDR_TO_STRING_MAX];
|
||||
|
||||
(void) ieee_oui(hwdb, &info->permanent_mac_address, &description);
|
||||
|
||||
@ -1712,7 +1711,7 @@ static int link_status_one(
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
r = table_add_cell_stringf(table, NULL, "%s%s%s%s",
|
||||
ether_addr_to_string(&info->permanent_mac_address, ea),
|
||||
ETHER_ADDR_TO_STR(&info->permanent_mac_address),
|
||||
description ? " (" : "",
|
||||
strempty(description),
|
||||
description ? ")" : "");
|
||||
@ -2107,7 +2106,6 @@ static int link_status_one(
|
||||
|
||||
if (info->has_wlan_link_info) {
|
||||
_cleanup_free_ char *esc = NULL;
|
||||
char buf[ETHER_ADDR_TO_STRING_MAX];
|
||||
|
||||
r = table_add_many(table,
|
||||
TABLE_EMPTY,
|
||||
@ -2120,7 +2118,7 @@ static int link_status_one(
|
||||
|
||||
r = table_add_cell_stringf(table, NULL, "%s (%s)",
|
||||
strnull(esc),
|
||||
ether_addr_to_string(&info->bssid, buf));
|
||||
ETHER_ADDR_TO_STR(&info->bssid));
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ static int property_get_ether_addrs(
|
||||
void *userdata,
|
||||
sd_bus_error *error) {
|
||||
|
||||
char buf[ETHER_ADDR_TO_STRING_MAX];
|
||||
const struct ether_addr *p;
|
||||
Set *s;
|
||||
int r;
|
||||
@ -32,7 +31,7 @@ static int property_get_ether_addrs(
|
||||
return r;
|
||||
|
||||
SET_FOREACH(p, s) {
|
||||
r = sd_bus_message_append(reply, "s", ether_addr_to_string(p, buf));
|
||||
r = sd_bus_message_append(reply, "s", ETHER_ADDR_TO_STR(p));
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
@ -55,11 +55,9 @@ int wifi_get_info(Link *link) {
|
||||
}
|
||||
|
||||
if (r > 0 || s > 0) {
|
||||
char buf[ETHER_ADDR_TO_STRING_MAX];
|
||||
|
||||
if (link->wlan_iftype == NL80211_IFTYPE_STATION && link->ssid)
|
||||
log_link_info(link, "Connected WiFi access point: %s (%s)",
|
||||
link->ssid, ether_addr_to_string(&link->bssid, buf));
|
||||
link->ssid, ETHER_ADDR_TO_STR(&link->bssid));
|
||||
|
||||
return 1; /* Some information is updated. */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user