diff options
-rw-r--r-- | src/libsystemd-network/sd-dhcp-client.c | 3 | ||||
-rw-r--r-- | src/libsystemd/sd-rtnl/test-rtnl.c | 3 | ||||
-rw-r--r-- | src/network/networkctl.c | 7 | ||||
-rw-r--r-- | src/shared/socket-util.c | 19 | ||||
-rw-r--r-- | src/shared/socket-util.h | 5 |
5 files changed, 33 insertions, 4 deletions
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index f5910d9e0b..8a9887d19f 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -1420,6 +1420,7 @@ static int client_receive_message_raw(sd_event_source *s, int fd, } int sd_dhcp_client_start(sd_dhcp_client *client) { + char buffer[ETHER_ADDR_TO_STRING_MAX]; int r; assert_return(client, -EINVAL); @@ -1435,7 +1436,7 @@ int sd_dhcp_client_start(sd_dhcp_client *client) { if (r >= 0) log_dhcp_client(client, "STARTED on ifindex %u with address %s", client->index, - ether_ntoa(&client->client_id.mac_addr)); + ether_addr_to_string(&client->client_id.mac_addr, buffer)); return r; } diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c index 4b6e5339d9..46b5bb20c3 100644 --- a/src/libsystemd/sd-rtnl/test-rtnl.c +++ b/src/libsystemd/sd-rtnl/test-rtnl.c @@ -34,6 +34,7 @@ static void test_link_configure(sd_rtnl *rtnl, int ifindex) { _cleanup_rtnl_message_unref_ sd_rtnl_message *message; const char *mac = "98:fe:94:3f:c6:18", *name = "test"; + char buffer[ETHER_ADDR_TO_STRING_MAX]; unsigned int mtu = 1450, mtu_out; const char *name_out; struct ether_addr mac_out; @@ -51,7 +52,7 @@ static void test_link_configure(sd_rtnl *rtnl, int ifindex) { assert_se(streq(name, name_out)); assert_se(sd_rtnl_message_read_ether_addr(message, IFLA_ADDRESS, &mac_out) >= 0); - assert_se(streq(mac, ether_ntoa(&mac_out))); + assert_se(streq(mac, ether_addr_to_string(&mac_out, buffer))); assert_se(sd_rtnl_message_read_u32(message, IFLA_MTU, &mtu_out) >= 0); assert_se(mtu == mtu_out); diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 620bc46b8f..33fe8bfc61 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -33,6 +33,7 @@ #include "udev-util.h" #include "arphrd-list.h" #include "local-addresses.h" +#include "socket-util.h" static bool arg_no_pager = false; static bool arg_legend = true; @@ -402,8 +403,10 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) { if (model) printf(" Model: %s\n", model); - if (have_mac) - printf(" HW Address: %s\n", ether_ntoa(&e)); + if (have_mac) { + char ea[ETHER_ADDR_TO_STRING_MAX]; + printf(" HW Address: %s\n", ether_addr_to_string(&e, ea)); + } if (mtu > 0) printf(" MTU: %u\n", mtu); diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c index 38729a25b8..e3e54e8e08 100644 --- a/src/shared/socket-util.c +++ b/src/shared/socket-util.c @@ -727,3 +727,22 @@ bool sockaddr_equal(const union sockaddr_union *a, const union sockaddr_union *b return false; } + +char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]) { + assert(addr); + assert(buffer); + + /* Like ether_ntoa() but uses %02x instead of %x to print + * ethernet addresses, which makes them look less funny. Also, + * doesn't use a static buffer. */ + + sprintf(buffer, "%02x:%02x:%02x:%02x:%02x:%02x", + addr->ether_addr_octet[0], + addr->ether_addr_octet[1], + addr->ether_addr_octet[2], + addr->ether_addr_octet[3], + addr->ether_addr_octet[4], + addr->ether_addr_octet[5]); + + return buffer; +} diff --git a/src/shared/socket-util.h b/src/shared/socket-util.h index 0b4998d044..07d0aff72b 100644 --- a/src/shared/socket-util.h +++ b/src/shared/socket-util.h @@ -23,6 +23,7 @@ #include <sys/socket.h> #include <netinet/in.h> +#include <netinet/ether.h> #include <sys/un.h> #include <asm/types.h> #include <linux/netlink.h> @@ -111,3 +112,7 @@ int netlink_family_to_string_alloc(int b, char **s); int netlink_family_from_string(const char *s) _pure_; bool sockaddr_equal(const union sockaddr_union *a, const union sockaddr_union *b); + +#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]); |