]> arthur.barton.de Git - netatalk.git/blob - etc/atalkd/route.c
- merge branch-netatalk-afp-3x-dev, HEAD was tagged before
[netatalk.git] / etc / atalkd / route.c
1 /*
2  * $Id: route.c,v 1.7 2005-04-28 20:49:46 bfernhomberg 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 #ifdef HAVE_UNISTD_H
13 #include <unistd.h>
14 #endif
15 #include <string.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>
22
23 #include "rtmp.h"
24 #include "route.h"
25
26 #ifndef BSD4_4
27 int route( message, dst, gate, flags )
28     int                 message;
29     struct sockaddr     *dst, *gate;
30     int                 flags;
31 {
32 #ifdef TRU64
33     struct ortentry     rtent;
34 #else /* TRU64 */
35     struct rtentry      rtent;
36 #endif /* TRU64 */
37
38     memset( &rtent, 0, sizeof( struct rtentry ));
39     rtent.rt_dst = *dst;
40     rtent.rt_gateway = *gate;
41     rtent.rt_flags = flags;
42     return( ioctl( rtfd, message, &rtent ));
43 }
44
45 #else /* BSD4_4 */
46
47 struct sockaddr_m {
48     u_char      sam_len;
49     u_char      sam_family;
50     u_short     sam_pad;
51     u_short     sam_mask;
52     u_short     sam_pad2;
53 } mask = { sizeof( struct sockaddr_m ), 0, 0, 0xffff, 0 };
54
55 struct rt_msg_at {
56     struct rt_msghdr    rtma_rtm;
57     struct sockaddr_at  rtma_dst;
58     struct sockaddr_at  rtma_gate;
59     struct sockaddr_m   rtma_mask;
60 } rtma;
61
62 route( message, dst, gate, flags )
63     int                 message;
64     struct sockaddr_at  *dst, *gate;
65     int                 flags;
66 {
67     int                 rc;
68
69     memset( &rtma, 0, sizeof( struct rt_msg_at ));
70     rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
71     rtma.rtma_rtm.rtm_version = RTM_VERSION;
72     rtma.rtma_rtm.rtm_type = message;
73     rtma.rtma_rtm.rtm_pid = getpid();
74     rtma.rtma_rtm.rtm_addrs = RTA_DST|RTA_GATEWAY;
75     if ( flags & RTF_HOST ) {
76         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at ) -
77                 sizeof( struct sockaddr_m );
78     } else {
79         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
80         rtma.rtma_rtm.rtm_addrs |= RTA_NETMASK;
81         rtma.rtma_mask = mask;
82     }
83
84     rtma.rtma_rtm.rtm_flags = flags;
85     rtma.rtma_dst = *dst;
86     rtma.rtma_gate = *gate;
87     if (( rc = write( rtfd, &rtma, rtma.rtma_rtm.rtm_msglen )) !=
88             rtma.rtma_rtm.rtm_msglen ) {
89         return( -1 );
90     }
91     return( 0 );
92 }
93 #endif /* BSD4_4 */