From af722a297833f70923be52c038285a4866d12783 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 8 Mar 2015 13:33:55 +0100 Subject: [PATCH] PPP, IPv6, reduce size of llv6_ntoa() function Reduced static buffer to the strict necessary (26 bytes), removed call to eui64_ntoa(), merged eui64_ntoa() into llv6_ntoa(). 272 bytes (code + static buffers) to 140 bytes on x86_64. Improved eui64_ntoa() as well, we don't need it anymore but I'd like to keep all eui64_* helpers functions. --- src/netif/ppp/eui64.c | 4 ++-- src/netif/ppp/ipv6cp.c | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/netif/ppp/eui64.c b/src/netif/ppp/eui64.c index e23a34e8..e042eb4c 100644 --- a/src/netif/ppp/eui64.c +++ b/src/netif/ppp/eui64.c @@ -45,9 +45,9 @@ * eui64_ntoa - Make an ascii representation of an interface identifier */ char *eui64_ntoa(eui64_t e) { - static char buf[32]; + static char buf[20]; - snprintf(buf, 32, "%02x%02x:%02x%02x:%02x%02x:%02x%02x", + sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x", e.e8[0], e.e8[1], e.e8[2], e.e8[3], e.e8[4], e.e8[5], e.e8[6], e.e8[7]); return buf; diff --git a/src/netif/ppp/ipv6cp.c b/src/netif/ppp/ipv6cp.c index 74b0cc6a..eba006fe 100644 --- a/src/netif/ppp/ipv6cp.c +++ b/src/netif/ppp/ipv6cp.c @@ -412,9 +412,12 @@ printifaceid(opt, printer, arg) static char * llv6_ntoa(eui64_t ifaceid) { - static char b[64]; + static char b[26]; + + sprintf(b, "fe80::%02x%02x:%02x%02x:%02x%02x:%02x%02x", + ifaceid.e8[0], ifaceid.e8[1], ifaceid.e8[2], ifaceid.e8[3], + ifaceid.e8[4], ifaceid.e8[5], ifaceid.e8[6], ifaceid.e8[7]); - sprintf(b, "fe80::%s", eui64_ntoa(ifaceid)); return b; }