From 4cf6e170043bc4784d7f5c887c91b4fe8169d7b3 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 20 Dec 2020 13:50:26 +0000 Subject: [PATCH] updated get_ifcfg() --- hawk/lib/gem-nwif2.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/hawk/lib/gem-nwif2.c b/hawk/lib/gem-nwif2.c index d207d62a..2b73d7b9 100644 --- a/hawk/lib/gem-nwif2.c +++ b/hawk/lib/gem-nwif2.c @@ -64,6 +64,9 @@ # if defined(HAVE_NET_IF_DL_H) # include # endif +# if defined(HAVE_NET_ROUTE_H) +# include +# endif # if defined(HAVE_SYS_SOCKIO_H) # include # 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; if (sysctl(mib, HAWK_COUNTOF(mib), HAWK_NULL, &len, HAWK_NULL, 0) >= 0) { - hawk_mmgr_t* mmgr = HAWK_MMGR_GETDFL(); - void* buf; + hawk_uint8_t* buf; buf = hawk_gem_allocmem(gem, len); if (buf) { 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; - sadl = ((struct if_msghdr*)buf + 1); - /* i don't really care if it's really ethernet - * so long as the data is long enough */ - if (sadl->sdl_alen >= HAWK_COUNTOF(cfg->ethw)) - HAWK_MEMCPY (cfg->ethw, LLADDR(sadl), HAWK_SIZEOF(cfg->ethw)); + 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 + * so long as the data is long enough */ + if (sadl->sdl_alen >= HAWK_COUNTOF(cfg->ethw)) + { + HAWK_MEMCPY (cfg->ethw, LLADDR(sadl), HAWK_SIZEOF(cfg->ethw)); + break; + } + + ptr += ifm->ifm_msglen; + } } hawk_gem_freemem (gem, buf);