--- libelwix/src/net.c 2013/06/10 14:49:48 1.4.2.1 +++ libelwix/src/net.c 2013/06/20 14:55:23 1.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: net.c,v 1.4.2.1 2013/06/10 14:49:48 misho Exp $ +* $Id: net.c,v 1.6 2013/06/20 14:55:23 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -46,7 +46,52 @@ SUCH DAMAGE. #include "global.h" +static char hexlist[] = "0123456789abcdef"; + /* + * e_link_ntoa() - String ethernet address from link address + * + * @sdl = link address + * return: =NULL error or !=NULL ethernet address, should be e_free() + */ +char * +e_link_ntoa(const struct sockaddr_dl *sdl) +{ + static char obuf[64]; + char *out = obuf; + int i; + u_char *in = (u_char*) LLADDR(sdl); + u_char *inlim = in + sdl->sdl_alen; + int firsttime = 1; + + if (sdl->sdl_nlen) { + memcpy(obuf, sdl->sdl_data, sdl->sdl_nlen); + out += sdl->sdl_nlen; + if (sdl->sdl_alen) + *out++ = '!'; + } + + while (in < inlim) { + if (firsttime) + firsttime ^= firsttime; + else + *out++ = ':'; + i = *in++; + if (i > 0xf) { + out[1] = hexlist[i & 0xf]; + i >>= 4; + } else + out[1] = hexlist[0]; + + out[0] = hexlist[i]; + out += 2; + } + + *out = 0; + return obuf; +} + +/* * e_ether_ntoa() - Convert ethernet address to string * * @n = ethernet address structure, like struct ether_addr @@ -162,7 +207,7 @@ e_n2addr(sockaddr_t * __restrict addr, ait_val_t * __r ret = addr->sun.sun_path; break; case AF_LINK: - if (!(s = link_ntoa(&addr->sdl))) { + if (!(s = e_link_ntoa(&addr->sdl))) { LOGERR; return ret; } else