summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2016-10-24 19:21:23 +0000
committerRoy Marples <roy@marples.name>2016-10-24 19:21:23 +0000
commit661e20a6900a458120378ded1ba77086849900ef (patch)
tree8bf2bbe840f1c113ceeeef4a4cfaae2cef2ba887
parent2c00914d355850fd6f650ed39974cb26d155f953 (diff)
downloaddhcpcd-661e20a6900a458120378ded1ba77086849900ef.tar.xz
hwaddr_ntoa now takes a void * as a source.
-rw-r--r--common.c20
-rw-r--r--common.h2
2 files changed, 12 insertions, 10 deletions
diff --git a/common.c b/common.c
index cbea738e..890851e9 100644
--- a/common.c
+++ b/common.c
@@ -282,26 +282,28 @@ addvard(struct dhcpcd_ctx *ctx,
return addvar(ctx, e, prefix, var, buffer);
}
-char *
-hwaddr_ntoa(const uint8_t *hwaddr, size_t hwlen, char *buf, size_t buflen)
+const char *
+hwaddr_ntoa(const void *hwaddr, size_t hwlen, char *buf, size_t buflen)
{
+ const unsigned char *hp, *ep;
char *p;
- size_t i;
- if (buf == NULL) {
+ if (buf == NULL)
return NULL;
- }
if (hwlen * 3 > buflen) {
errno = ENOBUFS;
- return 0;
+ return NULL;
}
+ hp = hwaddr;
+ ep = hp + hwlen;
p = buf;
- for (i = 0; i < hwlen; i++) {
- if (i > 0)
+
+ while (hp < ep) {
+ if (hp != hwaddr)
*p ++= ':';
- p += snprintf(p, 3, "%.2x", hwaddr[i]);
+ p += snprintf(p, 3, "%.2x", *hp++);
}
*p ++= '\0';
return buf;
diff --git a/common.h b/common.h
index c5941873..36048c8f 100644
--- a/common.h
+++ b/common.h
@@ -212,7 +212,7 @@ ssize_t addvar(struct dhcpcd_ctx *,
ssize_t addvard(struct dhcpcd_ctx *,
char ***, const char *, const char *, size_t);
-char *hwaddr_ntoa(const uint8_t *, size_t, char *, size_t);
+const char *hwaddr_ntoa(const void *, size_t, char *, size_t);
size_t hwaddr_aton(uint8_t *, const char *);
size_t read_hwaddr_aton(uint8_t **, const char *);