summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Agner <stefan@agner.ch>2015-04-24 21:27:53 +0200
committerKrzysztof Opasiak <k.opasiak@samsung.com>2015-04-27 12:41:03 +0200
commit93631e618436989ebd7e9df2c997c175feb14bda (patch)
tree7aaa1ee3c9e586a491d5b44fba085a7d3003c124
parentdf46a742c954ace89d6b0c8bf3ec584157ce8d02 (diff)
downloadlibusbg-93631e618436989ebd7e9df2c997c175feb14bda.tar.gz
libusbg-93631e618436989ebd7e9df2c997c175feb14bda.tar.bz2
libusbg-93631e618436989ebd7e9df2c997c175feb14bda.zip
libusbg: print leading zero for MAC address bytes
The ethernet gadget driver requires the hex formatted MAC address bytes with leading zero, in other words each byte needs to be two characters in length (see get_ether_addr in u_ether.c). The libc implementation ether_ntoa does not print leading zeros. Hence use our own implementation which provides the format expected by the kernel. Signed-off-by: Stefan Agner <stefan@agner.ch> Rebased onto current master. Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r--include/usbg/usbg_internal.h2
-rw-r--r--src/usbg.c17
-rw-r--r--src/usbg_schemes_libconfig.c4
3 files changed, 17 insertions, 6 deletions
diff --git a/include/usbg/usbg_internal.h b/include/usbg/usbg_internal.h
index 30098c9..30d3fcf 100644
--- a/include/usbg/usbg_internal.h
+++ b/include/usbg/usbg_internal.h
@@ -168,5 +168,7 @@ static inline int file_select(const struct dirent *dent)
int usbg_translate_error(int error);
+char *usbg_ether_ntoa_r(const struct ether_addr *addr, char *buf);
+
#endif /* USBG_INTERNAL_H */
diff --git a/src/usbg.c b/src/usbg.c
index d8b00c9..6239c60 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -852,6 +852,15 @@ static int usbg_rm_all_dirs(const char *path)
return ret;
}
+char *usbg_ether_ntoa_r(const struct ether_addr *addr, char *buf)
+{
+ sprintf(buf, "%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 buf;
+}
+
static int usbg_parse_function_net_attrs(usbg_function *f,
usbg_f_net_attrs *f_net_attrs)
{
@@ -2928,12 +2937,12 @@ int usbg_set_function_net_attrs(usbg_function *f, const usbg_f_net_attrs *attrs)
goto out;
}
- addr = ether_ntoa_r(&attrs->dev_addr, addr_buf);
+ addr = usbg_ether_ntoa_r(&attrs->dev_addr, addr_buf);
ret = usbg_write_string(f->path, f->name, "dev_addr", addr);
if (ret != USBG_SUCCESS)
goto out;
- addr = ether_ntoa_r(&attrs->host_addr, addr_buf);
+ addr = usbg_ether_ntoa_r(&attrs->host_addr, addr_buf);
ret = usbg_write_string(f->path, f->name, "host_addr", addr);
if (ret != USBG_SUCCESS)
goto out;
@@ -3171,7 +3180,7 @@ int usbg_set_net_dev_addr(usbg_function *f, struct ether_addr *dev_addr)
if (f && dev_addr) {
char str_buf[USBG_MAX_STR_LENGTH];
- char *str_addr = ether_ntoa_r(dev_addr, str_buf);
+ char *str_addr = usbg_ether_ntoa_r(dev_addr, str_buf);
ret = usbg_write_string(f->path, f->name, "dev_addr", str_addr);
} else {
ret = USBG_ERROR_INVALID_PARAM;
@@ -3186,7 +3195,7 @@ int usbg_set_net_host_addr(usbg_function *f, struct ether_addr *host_addr)
if (f && host_addr) {
char str_buf[USBG_MAX_STR_LENGTH];
- char *str_addr = ether_ntoa_r(host_addr, str_buf);
+ char *str_addr = usbg_ether_ntoa_r(host_addr, str_buf);
ret = usbg_write_string(f->path, f->name, "host_addr", str_addr);
} else {
ret = USBG_ERROR_INVALID_PARAM;
diff --git a/src/usbg_schemes_libconfig.c b/src/usbg_schemes_libconfig.c
index 212fc2d..1cbf3c4 100644
--- a/src/usbg_schemes_libconfig.c
+++ b/src/usbg_schemes_libconfig.c
@@ -326,7 +326,7 @@ static int usbg_export_f_net_attrs(usbg_f_net_attrs *attrs,
if (!node)
goto out;
- addr = ether_ntoa_r(&attrs->dev_addr, addr_buf);
+ addr = usbg_ether_ntoa_r(&attrs->dev_addr, addr_buf);
cfg_ret = config_setting_set_string(node, addr);
if (cfg_ret != CONFIG_TRUE) {
ret = USBG_ERROR_OTHER_ERROR;
@@ -337,7 +337,7 @@ static int usbg_export_f_net_attrs(usbg_f_net_attrs *attrs,
if (!node)
goto out;
- addr = ether_ntoa_r(&attrs->host_addr, addr_buf);
+ addr = usbg_ether_ntoa_r(&attrs->host_addr, addr_buf);
cfg_ret = config_setting_set_string(node, addr);
if (cfg_ret != CONFIG_TRUE) {
ret = USBG_ERROR_OTHER_ERROR;