2 * $Id: route.c,v 1.8 2009-10-13 22:55:37 didg Exp $
4 * Copyright (c) 1990,1996 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
16 #include <sys/param.h>
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <net/route.h>
20 #include <sys/ioctl.h>
21 #include <netatalk/at.h>
27 int route( int message, struct sockaddr *dst, struct sockaddr *gate, int flags)
30 struct ortentry rtent;
35 memset( &rtent, 0, sizeof( struct rtentry ));
37 rtent.rt_gateway = *gate;
38 rtent.rt_flags = flags;
39 return( ioctl( rtfd, message, &rtent ));
50 } mask = { sizeof( struct sockaddr_m ), 0, 0, 0xffff, 0 };
53 struct rt_msghdr rtma_rtm;
54 struct sockaddr_at rtma_dst;
55 struct sockaddr_at rtma_gate;
56 struct sockaddr_m rtma_mask;
59 route( int message, struct sockaddr_at *dst, struct sockaddr_at *gate, int flags)
63 memset( &rtma, 0, sizeof( struct rt_msg_at ));
64 rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
65 rtma.rtma_rtm.rtm_version = RTM_VERSION;
66 rtma.rtma_rtm.rtm_type = message;
67 rtma.rtma_rtm.rtm_pid = getpid();
68 rtma.rtma_rtm.rtm_addrs = RTA_DST|RTA_GATEWAY;
69 if ( flags & RTF_HOST ) {
70 rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at ) -
71 sizeof( struct sockaddr_m );
73 rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
74 rtma.rtma_rtm.rtm_addrs |= RTA_NETMASK;
75 rtma.rtma_mask = mask;
78 rtma.rtma_rtm.rtm_flags = flags;
80 rtma.rtma_gate = *gate;
81 if (( rc = write( rtfd, &rtma, rtma.rtma_rtm.rtm_msglen )) !=
82 rtma.rtma_rtm.rtm_msglen ) {