--- libelwix/src/net.c 2013/07/09 00:18:19 1.7 +++ libelwix/src/net.c 2013/08/12 02:10:44 1.8 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: net.c,v 1.7 2013/07/09 00:18:19 misho Exp $ +* $Id: net.c,v 1.8 2013/08/12 02:10:44 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -76,12 +76,15 @@ e_link_ntoa(const struct sockaddr_dl *sdl) firsttime ^= firsttime; else *out++ = ':'; + i = *in++; if (i > 0xf) { out[1] = hexlist[i & 0xf]; i >>= 4; - } else - out[1] = hexlist[0]; + } else { + out[1] = hexlist[i]; + i = 0; + } out[0] = hexlist[i]; out += 2; @@ -106,7 +109,7 @@ e_ether_ntoa(const ether_addr_t * __restrict n, char * return NULL; memset(a, 0, len); - if (snprintf(a, len, "%02x:%02x:%02x:%02x:%02x:%02x", + if (snprintf(a, len, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", n->ether_addr_octet[0], n->ether_addr_octet[1], n->ether_addr_octet[2], n->ether_addr_octet[3], n->ether_addr_octet[4], n->ether_addr_octet[5]) < 17) @@ -126,21 +129,19 @@ ether_addr_t * e_ether_aton(const char *a, ether_addr_t * __restrict e) { int i; - u_int o0, o1, o2, o3, o4, o5; if (!a || !e) return NULL; - i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o0, &o1, &o2, &o3, &o4, &o5); + i = sscanf(a, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", + &e->ether_addr_octet[0], + &e->ether_addr_octet[1], + &e->ether_addr_octet[2], + &e->ether_addr_octet[3], + &e->ether_addr_octet[4], + &e->ether_addr_octet[5]); if (i != 6) return NULL; - - e->ether_addr_octet[0] = o0; - e->ether_addr_octet[1] = o1; - e->ether_addr_octet[2] = o2; - e->ether_addr_octet[3] = o3; - e->ether_addr_octet[4] = o4; - e->ether_addr_octet[5] = o5; return e; }