--- libelwix/src/net.c 2014/11/17 23:00:36 1.10.10.3 +++ libelwix/src/net.c 2014/11/26 00:30:37 1.10.10.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: net.c,v 1.10.10.3 2014/11/17 23:00:36 misho Exp $ +* $Id: net.c,v 1.10.10.4 2014/11/26 00:30:37 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -95,6 +95,25 @@ e_link_ntoa(const struct sockaddr_dl *sdl) } /* + * e_link_addr() - String ethernet address to link address + * + * @mac = ethernet address + * @sdl = link address + * return: -1 error or 0 ok + */ +int +e_link_addr(const char *mac, struct sockaddr_dl * __restrict sdl) +{ + if (!mac || !sdl) + return -1; + if (!sdl->sdl_len) + sdl->sdl_len = sizeof(struct sockaddr_dl); + + link_addr(mac, sdl); + return 0; +} + +/* * e_ether_ntoa() - Convert ethernet address to string * * @n = ethernet address structure, like struct ether_addr @@ -518,6 +537,27 @@ e_getifacebyname(const char *psIface, sockaddr_t * __r break; } freeifaddrs(ifa); + + return addr; +} + +/* + * e_getlinkbyname() - Get host ethernet address and make network structure + * + * @psHost = Host ethernet address + * @addr = Network address structure + * return: NULL error or !=NULL network structure + */ +sockaddr_t * +e_getlinkbyname(const char *psHost, sockaddr_t * __restrict addr) +{ + if (!addr) + return NULL; + else + memset(addr, 0, sizeof(sockaddr_t)); + + addr->sdl.sdl_len = sizeof(struct sockaddr_dl); + e_link_addr(psHost, &addr->sdl); return addr; }