uroute
—
networking route objects
PDEL Library (libpdel, -lpdel)
#include
<sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include
<pdel/net/uroute.h>
struct uroute *
uroute_create
(const
struct sockaddr *dest,
const struct sockaddr
*gateway, const struct
sockaddr *netmask);
void
uroute_destroy
(struct
uroute **routep);
const struct sockaddr *
uroute_get_dest
(struct
uroute *route);
const struct sockaddr *
uroute_get_gateway
(struct
uroute *route);
const struct sockaddr *
uroute_get_netmask
(struct
uroute *route);
int
uroute_get_flags
(struct
uroute *route);
void
uroute_set_flags
(struct
uroute *route, int
flags);
int
uroute_add
(struct
uroute *route);
int
uroute_delete
(struct
uroute *route);
struct uroute *
uroute_get
(const
struct sockaddr *dest);
int
uroute_get_all
(struct
uroute ***listp, const
char *mtype);
void
uroute_print
(struct
uroute *route, FILE
*fp);
These functions support uroute
objects,
used for representing kernel routes in user code. Each
uroute
instance is represented by a
struct uroute
.
uroute_create
()
creates a new uroute
object using copies of the
supplied dest, gateway, and
netmask. The netmask should be
NULL
to specify a host route instead of a network
route.
uroute_destroy
()
destroys the object pointed to by *routep. Upon
return, *routep will be set to
NULL
. If *routep is already
NULL
when uroute_destroy
()
is invoked, nothing happens.
uroute_get_dest
(),
uroute_get_gateway
(),
and
uroute_get_netmask
()
return the addresses associated with the route. Note that
uroute_get_netmask
() returns
NULL
to indicate that route is
a host route.
uroute_get_flags
()
and
uroute_set_flags
()
are used to access or modify the flags associated with the route; these
flags are defined in the header file
<net/route.h>
. The only flag set for a newly
created route is RTF_STATIC
.
uroute_add
()
attempts to add the route to the kernel routing
table.
uroute_delete
()
attempts to remove the route from the kernel routing
table.
uroute_get
()
attempts to retrieve the route matching dest from the
kernel routing table.
uroute_get_all
()
retrieves the entire kernel routing table. Zero or more
uroute
objects are constructed and pointed to by the
elements of a newly allocated array of pointers. The length of the array is
returned by uroute_get_all
() and a pointer to the
array is stored in *listp. The array itself is
allocated with
typed_mem(3)
type mtype, and the caller is responsible for
eventually freeing it (as well as destroying the individudal
uroute
objects).
uroute_print
()
prints out uroute to the stream
fp for debugging purposes.
uroute_create
(),
uroute_add
(),
uroute_delete
(),
uroute_get
(), and
uroute_get_all
() return -1 or
NULL
to indicate an error, with
errno set appropriately.
The PDEL library was developed at Packet Design, LLC.
http://www.packetdesign.com/
Archie Cobbs
⟨archie@freebsd.org⟩