Building.Open.Source.Network.Security.Tools.Components.And.Techniques [Electronic resources]

Mike D. Schiffman

نسخه متنی -صفحه : 135/ 61
نمايش فراداده

ARP Cache Functions

The ARP cache functionality of libdnet gives the application programmer a simple interface to read from and write to the kernel's ARP cache.


arp_t *arp_open(void);

arp_open() opens and initializes an ARP cache handle for use in subsequent ARP functions. Upon success, the function returns a valid arp_t descriptor; upon failure, the function returns NULL.


int arp_add(arp_t *a, const struct arp_entry *entry);

arp_add() adds a new MAC address to protocol address (ha to pa) mapping to the ARP cache via a. entry should contain the desired address mapping. Upon success, the function returns 0; upon failure, the function returns −1 and sets errno.


int arp_delete(arp_t *a, const struct arp_entry *entry);

arp_delete() deletes the ARP mapping entry for the specified protocol address in entry via a. Upon success, the function returns 0; upon failure, the function returns −1 and sets errno.


int arp_get (arp_t *a, const struct arp_entry *entry);

arp_get() retrieves the hardware address mapping arp_ha for the protocol address arp_pa inside entry via a. Upon success, the function returns 0; upon failure, the function returns −1 and sets errno.


int arp_loop(arp_t *a, arp_handler callback, void *arg);
int callback(const struct arp_entry *entry, void *arg);

arp_loop() iterates over the kernel's ARP cache that a references, invoking the specified callback function callback with the optional additional argument arg. Upon success, the function returns 0; upon failure, the function returns −1 and sets errno. The arp_loop() callback function format expects two arguments: a pointer to the ARP entry structure entry and the optionally filled-in argument arg.


arp_t *arp_close(arp_t *a);

arp_close() closes the underlying ARP interface and frees any memory associated with a. The function returns NULL.