iphlpapi: Implement getNumArpEntries on FreeBSD.

This commit is contained in:
Eric Durbin 2008-06-24 22:49:15 -05:00 committed by Alexandre Julliard
parent beea4d3006
commit 6ea3796cdb
4 changed files with 52 additions and 0 deletions

2
configure vendored
View File

@ -7086,6 +7086,7 @@ done
for ac_header in \
@ -7136,6 +7137,7 @@ for ac_header in \
mntent.h \
ncurses.h \
netdb.h \
netinet/if_ether.h \
netinet/in.h \
netinet/in_systm.h \
netinet/ip_icmp.h \

View File

@ -273,6 +273,7 @@ AC_CHECK_HEADERS(\
mntent.h \
ncurses.h \
netdb.h \
netinet/if_ether.h \
netinet/in.h \
netinet/in_systm.h \
netinet/ip_icmp.h \

View File

@ -46,6 +46,9 @@
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
#ifdef HAVE_NET_IF_DL_H
#include <net/if_dl.h>
#endif
#ifdef HAVE_NET_IF_TYPES_H
#include <net/if_types.h>
#endif
@ -55,6 +58,9 @@
#ifdef HAVE_NET_IF_ARP_H
#include <net/if_arp.h>
#endif
#ifdef HAVE_NETINET_IF_ETHER_H
#include <netinet/if_ether.h>
#endif
#ifdef HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
#endif
@ -1234,6 +1240,46 @@ DWORD getRouteTable(PMIB_IPFORWARDTABLE *ppIpForwardTable, HANDLE heap,
DWORD getNumArpEntries(void)
{
#if defined(HAVE_SYS_SYSCTL_H) && defined(NET_RT_DUMP)
int mib[] = {CTL_NET, PF_ROUTE, 0, AF_INET, NET_RT_FLAGS, RTF_LLINFO};
#define MIB_LEN (sizeof(mib) / sizeof(mib[0]))
DWORD arpEntries = 0;
size_t needed;
char *buf, *lim, *next;
struct rt_msghdr *rtm;
struct sockaddr_inarp *sinarp;
struct sockaddr_dl *sdl;
if (sysctl (mib, MIB_LEN, NULL, &needed, NULL, 0) == -1)
{
ERR ("failed to get size of arp table\n");
return 0;
}
buf = HeapAlloc (GetProcessHeap (), 0, needed);
if (!buf) return 0;
if (sysctl (mib, MIB_LEN, buf, &needed, NULL, 0) == -1)
{
ERR ("failed to get arp table\n");
HeapFree (GetProcessHeap (), 0, buf);
return 0;
}
lim = buf + needed;
next = buf;
while(next < lim)
{
rtm = (struct rt_msghdr *)next;
sinarp=(struct sockaddr_inarp *)(rtm + 1);
sdl = (struct sockaddr_dl *)((char *)sinarp + ROUNDUP(sinarp->sin_len));
if(sdl->sdl_alen) /* arp entry */
arpEntries++;
next += rtm->rtm_msglen;
}
HeapFree (GetProcessHeap (), 0, buf);
return arpEntries;
#endif
return getNumWithOneHeader("/proc/net/arp");
}

View File

@ -441,6 +441,9 @@
/* Define to 1 if you have the <netinet/icmp_var.h> header file. */
#undef HAVE_NETINET_ICMP_VAR_H
/* Define to 1 if you have the <netinet/if_ether.h> header file. */
#undef HAVE_NETINET_IF_ETHER_H
/* Define to 1 if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H