HP-UX Reference (11i v3 07/02) - 7 Device (Special) Files, 9 General Information, Index (vol 10)
r
route(7P) route(7P)
Structure Fields Not Used
rt_msghdr
rtm_use, rtm_inits, rtm_rmx, except for rtm_rmx.rmx_mtu and rtm_rmx.rmx_rtt
if_msghdr ifm_data, except for ifm_data.ifi_mtu, ifm_data.ifi_metric, ifm_data.ifi_ipackets, and
ifm_data.ifi_opackets
ifa_msghdr ifam_metric
ERRORS
If the kernel rejects a routing message, the
rtm_errno field in the rt_msghdr structure may be set to
one of the following values:
[EEXIST] The specified entry already exist. Requested to duplicate an existing entry.
[ENETUNREACH] Network is unreachable.
[ENOENT] The specified entry does not exist. Requested to delete non-existent entry.
[ENOBUFS] No buffer space is available. Insufficient resources were available to install a
new route.
[EOPNOTSUPP] Operation not supported. Message types RTM_CHANGE and RTM_LOCK are
not supported on HP-UX.
[EPERM] Permission to issue a command is denied. The user needs appropriate privileges
to make changes to the routing table.
EXAMPLES
The following sample program illustrates how a user process can add a route to the kernel’s routing table.
#include <sys/types.h>
#include <sys/socket.h>
#include <net/route.h>
#include <net/if.h>
#include <netinet/in.h>
int main(int argc, char **argv)
{
int s;
char buf[1024];
struct rt_msghdr *rtm;
struct sockaddr_in *sin1, *sin2;
if (argc != 3) {
printf("usage: %s <destinationIP> <gatewayIP>\n",
argv[0]);
return -1;
}
if ((s = socket(AF_ROUTE, SOCK_RAW, AF_UNSPEC)) < 0) {
perror("failed to create socket");
return -1;
}
rtm = (struct rt_msghdr *)buf;
rtm->rtm_msglen = sizeof(struct rt_msghdr) +
(2 * sizeof(struct sockaddr_in));
rtm->rtm_version = RTM_VERSION;
rtm->rtm_type = RTM_ADD;
rtm->rtm_addrs = (RTA_DST | RTA_GATEWAY);
rtm->rtm_rmx.rmx_hopcount = 1;
rtm->rtm_pid = getpid();
rtm->rtm_errno = 0;
rtm->rtm_seq = 0001;
138 Hewlett-Packard Company − 4 − HP-UX 11i Version 3: February 2007