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