diff options
author | Felix Fietkau <nbd@openwrt.org> | 2012-01-19 17:38:01 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2012-01-20 00:01:40 +0100 |
commit | b8f0ce8319a43d629c8de86df6951892b7e8d813 (patch) | |
tree | f2871b340805cdac49c6835a421173a7ef357015 /system-linux.c | |
parent | fcbec58e1494281dfeb2f19576c52667a512fad2 (diff) |
add mac address to device info
Diffstat (limited to 'system-linux.c')
-rw-r--r-- | system-linux.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/system-linux.c b/system-linux.c index f2ee10a..1fcf22f 100644 --- a/system-linux.c +++ b/system-linux.c @@ -640,24 +640,28 @@ system_if_get_parent(struct device *dev) } static bool -read_int_file(int dir_fd, const char *file, int *val) +read_string_file(int dir_fd, const char *file, char *buf, int len) { - char buf[64]; - int len, fd; bool ret = false; + char *c; + int fd; fd = openat(dir_fd, file, O_RDONLY); if (fd < 0) return false; retry: - len = read(fd, buf, sizeof(buf)); + len = read(fd, buf, len - 1); if (len < 0) { if (errno == EINTR) goto retry; } else if (len > 0) { buf[len] = 0; - *val = strtoul(buf, NULL, 0); + + c = strchr(buf, '\n'); + if (c) + *c = 0; + ret = true; } @@ -666,6 +670,19 @@ retry: return ret; } +static bool +read_int_file(int dir_fd, const char *file, int *val) +{ + char buf[64]; + bool ret = false; + + ret = read_string_file(dir_fd, file, buf, sizeof(buf)); + if (ret) + *val = strtoul(buf, NULL, 0); + + return ret; +} + int system_if_dump_info(struct device *dev, struct blob_buf *b) { @@ -677,6 +694,8 @@ system_if_dump_info(struct device *dev, struct blob_buf *b) if (read_int_file(dir_fd, "carrier", &val)) blobmsg_add_u8(b, "link", !!val); + if (read_string_file(dir_fd, "address", buf, sizeof(buf))) + blobmsg_add_string(b, "macaddr", buf); close(dir_fd); return 0; |