我在此示例代码块的最后一条指令中收到以下错误
sdl = (struct sockaddr_dl *)(sin + 1);
指向不完整类型的指针' struct sockaddr_inarp'
我删除了所有不必要的代码。
有人可以帮忙吗?
int test(void)
{
int mib[6];
size_t needed;
char *host, *lim, *buf, *next;
struct rt_msghdr *rtm;
struct sockaddr_inarp *sin;
struct sockaddr_dl *sdl;
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0;
mib[3] = AF_INET;
mib[4] = NET_RT_FLAGS;
mib[5] = RTF_LLINFO;
if ((buf = malloc(needed)) == NULL)
err(1, "malloc");
lim = buf + needed;
for (next = buf; next < lim; next += rtm->rtm_msglen)
{
rtm = (struct rt_msghdr *)next;
sin = (struct sockaddr_inarp *)(rtm + 1);
sdl = (struct sockaddr_dl *)(sin + 1);
}
}