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

Mike D. Schiffman

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

Route Table Functions

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


route_t *route_open(void);

route_open() opens and initializes a route table handle for use in subsequent route functions. Upon success, the function returns a valid route_t descriptor; upon failure, the function returns NULL.


int route_add(route_t *r, const struct route_entry *entry);

route_add() adds a route via r for the route table entry in entry. Upon success, the function returns 0; upon failure, the function returns −1 and sets errno.


int route_delete(route_t *r, const struct route_entry *entry);

route_delete() deletes the route via r for the destination address specified inside entry. Upon success, the function returns 0; upon failure, the function returns −1 and sets errno.


int route_get(route_t *r, const struct route_entry *entry);

route_get() retrieves via r the gateway address corresponding to the destination address inside entry. Upon success, the function returns 0; upon failure, the function returns −1 and sets errno.


int route_loop(route_t *r, route_handler callback, void *arg);
int callback(const struct route_entry *entry, void *arg);

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


route_t *route_close(route_t *r);

route_close() closes the underlying route table interface and frees any memory associated with r. The function returns NULL.