#include <sys/types.h>
#include <stdio.h>
#include <pdel/net/route_msg.h>
struct route_msg *
route_msg_create
(void);
void
route_msg_destroy
(struct
route_msg **msgp);
int
route_msg_get_type
(struct
route_msg *msg);
void
route_msg_set_type
(struct
route_msg *msg, int
type);
int
route_msg_get_index
(struct
route_msg *msg);
void
route_msg_set_index
(struct
route_msg *msg, int
index);
int
route_msg_get_flags
(struct
route_msg *msg);
void
route_msg_set_flags
(struct
route_msg *msg, int
flags);
int
route_msg_get_error
(struct
route_msg *msg);
pid_t
route_msg_get_pid
(struct
route_msg *msg);
int
route_msg_get_seq
(struct
route_msg *msg);
const struct sockaddr *
route_msg_get_dest
(struct
route_msg *msg);
int
route_msg_set_dest
(struct
route_msg *msg, const
struct sockaddr *dest);
const struct sockaddr *
route_msg_get_gateway
(struct
route_msg *msg);
int
route_msg_set_gateway
(struct
route_msg *msg, const
struct sockaddr *gateway);
const struct sockaddr *
route_msg_get_netmask
(struct
route_msg *msg);
int
route_msg_set_netmask
(struct
route_msg *msg, const
struct sockaddr *netmask);
const struct sockaddr *
route_msg_get_genmask
(struct
route_msg *msg);
int
route_msg_set_genmask
(struct
route_msg *msg, const
struct sockaddr *genmask);
const struct sockaddr *
route_msg_get_ifp
(struct
route_msg *msg);
int
route_msg_set_ifp
(struct
route_msg *msg, const
struct sockaddr *ifp);
const struct sockaddr *
route_msg_get_ifa
(struct
route_msg *msg);
int
route_msg_set_ifa
(struct
route_msg *msg, const
struct sockaddr *ifa);
const struct sockaddr *
route_msg_get_author
(struct
route_msg *msg);
int
route_msg_set_author
(struct
route_msg *msg, const
struct sockaddr *author);
const struct sockaddr *
route_msg_get_brd
(struct
route_msg *msg);
int
route_msg_set_brd
(struct
route_msg *msg, const
struct sockaddr *brd);
int
route_msg_decode
(const
u_char *data, size_t
dlen, struct route_msg
***listp, const char
*mtype);
int
route_msg_encode
(const
struct route_msg *msg,
u_char *data,
size_t dlen);
void
route_msg_print
(struct
route_msg *msg, FILE
*fp);
int
route_msg_send
(struct
route_msg *msg, int
sock);
int
route_msg_recv
(struct
route_msg ***listp, int
sock, const char
*mtype);
These functions support route_msg
objects, used for
communication over kernel routing sockets. The routing socket messages are
defined in the header file <net/route.h>
. Each
route_msg
instance is represented by a
struct route_msg
.
route_msg_create
() creates a new, empty
route_msg
object.
route_msg_destroy
() destroys the object
pointed to by *msgp. Upon return,
*msgp will be set to NULL
. If
*msgp is already NULL
when
route_msg_destroy
() is invoked, nothing happens.
The route_msg_get_XXX
() and
route_msg_set_XXX
() routines allow reading and
changing the attributes associated with a route_msg
object.
route_msg_decode
() decodes routing
messages from data encoded in the format used when communicating over kernel
routing sockets. The encoded data is pointed to by
data and has length dlen. Zero
or more route_msg
objects are constructed and
pointed to by the elements of a newly allocated array of pointers. The
length of the array is returned by
route_msg_decode
() 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
route_msg
objects). If the encoded data is invalid,
-1 is returned with errno set to
EINVAL
.
route_msg_encode
() encodes a
route_msg
object into the format used when
communicating over kernel routing sockets. The resulting data is stored in
the buffer pointed to by data, which must have length
at least dlen. If the encoding does not fit in
dlen bytes, -1 is returned with
errno set to EMSGSIZE
.
Otherwise, the number of bytes actually written into
data is returned.
route_msg_print
() prints out a
route_msg
object to the stream
fp for debugging purposes.
route_msg_send
() encodes and writes the
route_msg
object to the routing socket descriptor
sock.
route_msg_recv
reads the next packet from
the routing socket descriptor sock and decodes
route_msg
objects from the data read. The
listp and mtype parameters are
the same as with route_msg_decode
().