]> arthur.barton.de Git - netatalk.git/blob - etc/atalkd/route.c
83c4d250fc1ee0f226de1750e4ba4721516d082e
[netatalk.git] / etc / atalkd / route.c
1 /*
2  * $Id: route.c,v 1.5 2001-06-25 20:13:45 rufustfirefly Exp $
3  *
4  * Copyright (c) 1990,1996 Regents of The University of Michigan.
5  * All Rights Reserved. See COPYRIGHT.
6  */
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif /* HAVE_CONFIG_H */
11
12 #include <string.h>
13 #include <sys/param.h>
14 #include <sys/types.h>
15 #include <sys/socket.h>
16 #include <net/route.h>
17 #include <sys/ioctl.h>
18
19 #include <netatalk/at.h>
20
21 #include "rtmp.h"
22 #include "route.h"
23
24 #ifndef BSD4_4
25 int route( message, dst, gate, flags )
26     int                 message;
27     struct sockaddr     *dst, *gate;
28     int                 flags;
29 {
30 #ifdef TRU64
31     struct ortentry     rtent;
32 #else /* TRU64 */
33     struct rtentry      rtent;
34 #endif /* TRU64 */
35
36     memset( &rtent, 0, sizeof( struct rtentry ));
37     rtent.rt_dst = *dst;
38     rtent.rt_gateway = *gate;
39     rtent.rt_flags = flags;
40     return( ioctl( rtfd, message, &rtent ));
41 }
42
43 #else /* BSD4_4 */
44
45 struct sockaddr_m {
46     u_char      sam_len;
47     u_char      sam_family;
48     u_short     sam_pad;
49     u_short     sam_mask;
50 } mask = { sizeof( struct sockaddr_m ), 0, 0, 0xffff };
51
52 struct rt_msg_at {
53     struct rt_msghdr    rtma_rtm;
54     struct sockaddr_at  rtma_dst;
55     struct sockaddr_at  rtma_gate;
56     struct sockaddr_m   rtma_mask;
57 } rtma;
58
59 route( message, dst, gate, flags )
60     int                 message;
61     struct sockaddr_at  *dst, *gate;
62     int                 flags;
63 {
64     int                 rc;
65
66     memset( &rtma, 0, sizeof( struct rt_msg_at ));
67     rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
68     rtma.rtma_rtm.rtm_version = RTM_VERSION;
69     rtma.rtma_rtm.rtm_type = message;
70     rtma.rtma_rtm.rtm_pid = getpid();
71     rtma.rtma_rtm.rtm_addrs = RTA_DST|RTA_GATEWAY;
72     if ( flags & RTF_HOST ) {
73         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at ) -
74                 sizeof( struct sockaddr_m );
75     } else {
76         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
77         rtma.rtma_rtm.rtm_addrs |= RTA_NETMASK;
78         rtma.rtma_mask = mask;
79     }
80
81     rtma.rtma_rtm.rtm_flags = flags;
82     rtma.rtma_dst = *dst;
83     rtma.rtma_gate = *gate;
84     if (( rc = write( rtfd, &rtma, rtma.rtma_rtm.rtm_msglen )) !=
85             rtma.rtma_rtm.rtm_msglen ) {
86         return( -1 );
87     }
88     return( 0 );
89 }
90 #endif /* BSD4_4 */