| 1 |
/* |
| 2 |
* Template MIB group implementation - at.c |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* Portions of this file are subject to the following copyright(s). See |
| 7 |
* the Net-SNMP's COPYING file for more details and other copyrights |
| 8 |
* that may apply: |
| 9 |
*/ |
| 10 |
/* |
| 11 |
* Portions of this file are copyrighted by: |
| 12 |
* Copyright © 2003 Sun Microsystems, Inc. All rights reserved. |
| 13 |
* Use is subject to license terms specified in the COPYING file |
| 14 |
* distributed with the Net-SNMP package. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <netinet/if_ether.h> |
| 18 |
#include <net-snmp/net-snmp-config.h> |
| 19 |
#include <net-snmp/net-snmp-includes.h> |
| 20 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 21 |
#include <net-snmp/agent/auto_nlist.h> |
| 22 |
#include <net-snmp/data_access/interface.h> |
| 23 |
#include "../at.h" |
| 24 |
|
| 25 |
#if defined(_AIX) |
| 26 |
#define ARPTAB_SIZE_SYMBOL "arptabsize" |
| 27 |
#define ARPTAB_SYMBOL "arptabnb" |
| 28 |
#endif |
| 29 |
#if defined(hpux) && !defined(hpux11) |
| 30 |
#define ARPTAB_SYMBOL "arphd" |
| 31 |
#define ARPTAB_SIZE_SYMBOL "arptab_nb" |
| 32 |
#endif |
| 33 |
#if defined(solaris) |
| 34 |
#define ARPTAB_SYMBOL "arptab_nb" |
| 35 |
#define ARPTAB_SIZE_SYMBOL "arphd" |
| 36 |
#endif |
| 37 |
|
| 38 |
static int arptab_size, arptab_current; |
| 39 |
|
| 40 |
#ifdef HAVE_STRUCT_ARPHD_AT_NEXT |
| 41 |
static struct arphd *at; |
| 42 |
#else |
| 43 |
static struct arptab *at; |
| 44 |
#endif |
| 45 |
|
| 46 |
void |
| 47 |
ARP_Scan_Init(void) |
| 48 |
{ |
| 49 |
if (!at) { |
| 50 |
#ifdef ARPTAB_SIZE_SYMBOL |
| 51 |
auto_nlist(ARPTAB_SIZE_SYMBOL, (char *) &arptab_size, |
| 52 |
sizeof arptab_size); |
| 53 |
at = malloc(arptab_size * sizeof(*at)); |
| 54 |
#else |
| 55 |
return; |
| 56 |
#endif |
| 57 |
} |
| 58 |
#ifdef HAVE_STRUCT_ARPHD_AT_NEXT |
| 59 |
auto_nlist(ARPTAB_SYMBOL, (char *) at, |
| 60 |
arptab_size * sizeof(struct arphd)); |
| 61 |
at_ptr = at[0].at_next; |
| 62 |
#else |
| 63 |
auto_nlist(ARPTAB_SYMBOL, (char *) at, |
| 64 |
arptab_size * sizeof(struct arptab)); |
| 65 |
#endif |
| 66 |
arptab_current = 0; |
| 67 |
} |
| 68 |
|
| 69 |
int |
| 70 |
ARP_Scan_Next(in_addr_t * IPAddr, char *PhysAddr, int *PhysAddrLen, |
| 71 |
u_long * ifType, u_short * ifIndex) |
| 72 |
{ |
| 73 |
register struct arptab *atab; |
| 74 |
|
| 75 |
*ifIndex = 0; |
| 76 |
|
| 77 |
while (arptab_current < arptab_size) { |
| 78 |
#ifdef HAVE_STRUCT_ARPHD_AT_NEXT |
| 79 |
/* |
| 80 |
* The arp table is an array of linked lists of arptab entries. |
| 81 |
* Unused slots have pointers back to the array entry itself |
| 82 |
*/ |
| 83 |
|
| 84 |
if (at_ptr == (auto_nlist_value(ARPTAB_SYMBOL) + |
| 85 |
arptab_current * sizeof(struct arphd))) { |
| 86 |
/* |
| 87 |
* Usused |
| 88 |
*/ |
| 89 |
arptab_current++; |
| 90 |
at_ptr = at[arptab_current].at_next; |
| 91 |
continue; |
| 92 |
} |
| 93 |
|
| 94 |
if (!NETSNMP_KLOOKUP(at_ptr, (char *) &at_entry, sizeof(struct arptab))) { |
| 95 |
DEBUGMSGTL(("mibII/at:ARP_Scan_Next", "klookup failed\n")); |
| 96 |
break; |
| 97 |
} |
| 98 |
|
| 99 |
if (!NETSNMP_KLOOKUP(at_entry.at_ac, (char *) &at_com, sizeof(struct arpcom))) { |
| 100 |
DEBUGMSGTL(("mibII/at:ARP_Scan_Next", "klookup failed\n")); |
| 101 |
break; |
| 102 |
} |
| 103 |
|
| 104 |
at_ptr = at_entry.at_next; |
| 105 |
atab = &at_entry; |
| 106 |
*ifIndex = at_com.ac_if.if_index; /* not strictly ARPHD */ |
| 107 |
#else /* HAVE_STRUCT_ARPHD_AT_NEXT */ |
| 108 |
atab = &at[arptab_current++]; |
| 109 |
#endif /* HAVE_STRUCT_ARPHD_AT_NEXT */ |
| 110 |
if (!(atab->at_flags & ATF_COM)) |
| 111 |
continue; |
| 112 |
*ifType = (atab->at_flags & ATF_PERM) ? 4 : 3; |
| 113 |
*IPAddr = atab->at_iaddr.s_addr; |
| 114 |
#if defined (sunV3) || defined(sparc) || defined(hpux) |
| 115 |
memcpy(PhysAddr, (char *) &atab->at_enaddr, |
| 116 |
sizeof(atab->at_enaddr)); |
| 117 |
*PhysAddrLen = sizeof(atab->at_enaddr); |
| 118 |
#endif |
| 119 |
#if defined(mips) || defined(ibm032) |
| 120 |
memcpy(PhysAddr, (char *) atab->at_enaddr, |
| 121 |
sizeof(atab->at_enaddr)); |
| 122 |
*PhysAddrLen = sizeof(atab->at_enaddr); |
| 123 |
#endif |
| 124 |
return (1); |
| 125 |
} |
| 126 |
|
| 127 |
return 0; |
| 128 |
} |