]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ether-addr-util: introduce ether_addr_to_string_alloc()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 29 Apr 2021 06:35:47 +0000 (15:35 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 29 Apr 2021 20:39:10 +0000 (05:39 +0900)
src/basic/ether-addr-util.c
src/basic/ether-addr-util.h

index c8094b6e45ecf6269dce7a290e3fc4ed8adf54c1..4bb655738454f7dcfd785529748dcf16ae09b5a1 100644 (file)
@@ -43,6 +43,22 @@ char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR
         return buffer;
 }
 
+int ether_addr_to_string_alloc(const struct ether_addr *addr, char **ret) {
+        char *buf;
+
+        assert(addr);
+        assert(ret);
+
+        buf = new(char, ETHER_ADDR_TO_STRING_MAX);
+        if (!buf)
+                return -ENOMEM;
+
+        ether_addr_to_string(addr, buf);
+
+        *ret = buf;
+        return 0;
+}
+
 int ether_addr_compare(const struct ether_addr *a, const struct ether_addr *b) {
         return memcmp(a, b, ETH_ALEN);
 }
index 942ce55621e16fe56140c42965c252e4051064bf..712c9277964829a05d22603a031c2b9e4e962a55 100644 (file)
@@ -35,6 +35,7 @@ char* hw_addr_to_string(const hw_addr_data *addr, char buffer[HW_ADDR_TO_STRING_
 
 #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);
 
 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) {