--- libelwix/src/net.c 2014/02/10 22:50:44 1.10 +++ libelwix/src/net.c 2014/11/17 22:38:09 1.10.10.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: net.c,v 1.10 2014/02/10 22:50:44 misho Exp $ +* $Id: net.c,v 1.10.10.2 2014/11/17 22:38:09 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -442,7 +442,7 @@ e_getnet(const char *net) * * @ifname = interface name * @addr = if addr is !=NULL then set this for new address - * return: NULL error or !=NULL get ethernet address + * return: NULL error or !=NULL get ethernet address should be e_free() */ ether_addr_t * e_ether_addr(const char *ifname, ether_addr_t * __restrict addr) @@ -469,4 +469,25 @@ e_ether_addr(const char *ifname, ether_addr_t * __rest freeifaddrs(ifa); return a; +} + +/* + * e_get1stiface() - Get first interface of host + * + * @szIface = interface string buffer + * @iflen = size of interface buffer + * return: -1 error or 0 ok + */ +int +e_get1stiface(char *szIface, int iflen) +{ + struct ifaddrs *ifa; + + if (!szIface || !iflen) + return -1; + + getifaddrs(&ifa); + strlcpy(szIface, ifa->ifa_name, iflen); + freeifaddrs(ifa); + return 0; }