]> arthur.barton.de Git - netatalk.git/blob - etc/atalkd/route.c
Trunk-BP: struct padding.
[netatalk.git] / etc / atalkd / route.c
1 /*
2  * $Id: route.c,v 1.5.2.1 2002-02-07 23:59:11 srittau 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     u_short     sam_pad2;
51 } mask = { sizeof( struct sockaddr_m ), 0, 0, 0xffff, 0 };
52
53 struct rt_msg_at {
54     struct rt_msghdr    rtma_rtm;
55     struct sockaddr_at  rtma_dst;
56     struct sockaddr_at  rtma_gate;
57     struct sockaddr_m   rtma_mask;
58 } rtma;
59
60 route( message, dst, gate, flags )
61     int                 message;
62     struct sockaddr_at  *dst, *gate;
63     int                 flags;
64 {
65     int                 rc;
66
67     memset( &rtma, 0, sizeof( struct rt_msg_at ));
68     rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
69     rtma.rtma_rtm.rtm_version = RTM_VERSION;
70     rtma.rtma_rtm.rtm_type = message;
71     rtma.rtma_rtm.rtm_pid = getpid();
72     rtma.rtma_rtm.rtm_addrs = RTA_DST|RTA_GATEWAY;
73     if ( flags & RTF_HOST ) {
74         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at ) -
75                 sizeof( struct sockaddr_m );
76     } else {
77         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
78         rtma.rtma_rtm.rtm_addrs |= RTA_NETMASK;
79         rtma.rtma_mask = mask;
80     }
81
82     rtma.rtma_rtm.rtm_flags = flags;
83     rtma.rtma_dst = *dst;
84     rtma.rtma_gate = *gate;
85     if (( rc = write( rtfd, &rtma, rtma.rtma_rtm.rtm_msglen )) !=
86             rtma.rtma_rtm.rtm_msglen ) {
87         return( -1 );
88     }
89     return( 0 );
90 }
91 #endif /* BSD4_4 */