顯示arp快取的程式

2021-05-24 06:06:10 字數 1403 閱讀 4754

從freebsd4.5的arp命令的源**中獲得,可以在macos10.6上編譯,執行。

gcc -o arp -wall arp.c

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define roundup(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))

void

ether_print(u_char * cp)

void

print_entry(struct sockaddr_dl * sdl, struct sockaddr_inarp * sin, struct rt_msghdr * rtm)

else

if (if_indextoname(sdl->sdl_index, ifname) != null)

if (rtm->rtm_rmx.rmx_expire == 0)

if (sin->sin_other & sin_proxy)

if (rtm->rtm_addrs & rta_netmask)

if (sin->sin_len != 8)

}switch (sdl->sdl_type)

printf("/n");

}void

search(u_long addr, void (*action) (struct sockaddr_dl * sdl, struct sockaddr_inarp * sin, struct rt_msghdr * rtm))

if ((buf = malloc(needed)) == null)

if (sysctl(mib, 6, buf, &needed, null, 0) < 0)

lim = buf + needed;

for (next = buf; next < lim; next += rtm->rtm_msglen)

}(*action) (sdl, sin, rtm);

}free(buf);

}int

main()

監控ARP快取

我對c不是太懂,為了完成上級的任務,組合了幾個函式,目的是監控arp快取,對arp條目的刪除時出現了問題,刪除不了想要刪除的ip位址,麻煩各位幫指導一下 int main 獲取ip位址表,以便根據它將arp表項中的介面索引轉化為ip位址 pmib ipaddrtable pipaddrtable m...

10 5 arp 管理系統的arp快取

用於操作本機的arp快取區,它可以顯示arp快取區中的所有條目 刪除指定的條目或者新增靜態的ip位址與mac位址的對應關係。什麼是arp?即位址解析協議 arp,address resolution protocol 其主要功能是根據ip位址獲取實體地址 mac位址 n 顯示數字ip位址 s 主機 ...

arp快取重新整理問題

修改單個引數 直接 sysctl w 修改即可 永久生效 root ufo130 eth0 sysctl w net.ipv4.neigh.eth0.base reachable time 5 net.ipv4.neigh.eth0.base reachable time 5 root ufo130...