updated get_ifcfg()

This commit is contained in:
hyung-hwan 2020-12-20 13:50:26 +00:00
parent e72e9f2c1d
commit 4cf6e17004

View File

@ -64,6 +64,9 @@
# if defined(HAVE_NET_IF_DL_H) # if defined(HAVE_NET_IF_DL_H)
# include <net/if_dl.h> # include <net/if_dl.h>
# endif # endif
# if defined(HAVE_NET_ROUTE_H)
# include <net/route.h>
# endif
# if defined(HAVE_SYS_SOCKIO_H) # if defined(HAVE_SYS_SOCKIO_H)
# include <sys/sockio.h> # include <sys/sockio.h>
# endif # endif
@ -591,21 +594,34 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i
mib[5] = cfg->index; mib[5] = cfg->index;
if (sysctl(mib, HAWK_COUNTOF(mib), HAWK_NULL, &len, HAWK_NULL, 0) >= 0) if (sysctl(mib, HAWK_COUNTOF(mib), HAWK_NULL, &len, HAWK_NULL, 0) >= 0)
{ {
hawk_mmgr_t* mmgr = HAWK_MMGR_GETDFL(); hawk_uint8_t* buf;
void* buf;
buf = hawk_gem_allocmem(gem, len); buf = hawk_gem_allocmem(gem, len);
if (buf) if (buf)
{ {
if (sysctl(mib, HAWK_COUNTOF(mib), buf, &len, HAWK_NULL, 0) >= 0) if (sysctl(mib, HAWK_COUNTOF(mib), buf, &len, HAWK_NULL, 0) >= 0)
{ {
hawk_uint8_t* ptr, * end;
struct if_msghdr* ifm;
struct sockaddr_dl* sadl; struct sockaddr_dl* sadl;
sadl = ((struct if_msghdr*)buf + 1);
ptr = buf;
end = buf + len;
while (ptr < end)
{
ifm = (struct if_msghdr*)ptr;
sadl = (struct sockaddr_dl*)(ifm + 1);
/* i don't really care if it's really ethernet /* i don't really care if it's really ethernet
* so long as the data is long enough */ * so long as the data is long enough */
if (sadl->sdl_alen >= HAWK_COUNTOF(cfg->ethw)) if (sadl->sdl_alen >= HAWK_COUNTOF(cfg->ethw))
{
HAWK_MEMCPY (cfg->ethw, LLADDR(sadl), HAWK_SIZEOF(cfg->ethw)); HAWK_MEMCPY (cfg->ethw, LLADDR(sadl), HAWK_SIZEOF(cfg->ethw));
break;
}
ptr += ifm->ifm_msglen;
}
} }
hawk_gem_freemem (gem, buf); hawk_gem_freemem (gem, buf);