]> arthur.barton.de Git - netatalk.git/blob - etc/atalkd/route.c
Removed duplicate -I tags from CFLAGS
[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     struct rtentry      rtent;
26
27     bzero( &rtent, sizeof( struct rtentry ));
28     rtent.rt_dst = *dst;
29     rtent.rt_gateway = *gate;
30     rtent.rt_flags = flags;
31     return( ioctl( rtfd, message, &rtent ));
32 }
33
34 #else BSD4_4
35
36 struct sockaddr_m {
37     u_char      sam_len;
38     u_char      sam_family;
39     u_short     sam_pad;
40     u_short     sam_mask;
41 } mask = { sizeof( struct sockaddr_m ), 0, 0, 0xffff };
42
43 struct rt_msg_at {
44     struct rt_msghdr    rtma_rtm;
45     struct sockaddr_at  rtma_dst;
46     struct sockaddr_at  rtma_gate;
47     struct sockaddr_m   rtma_mask;
48 } rtma;
49
50 route( message, dst, gate, flags )
51     int                 message;
52     struct sockaddr_at  *dst, *gate;
53     int                 flags;
54 {
55     int                 rc;
56
57     bzero( &rtma, sizeof( struct rt_msg_at ));
58     rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
59     rtma.rtma_rtm.rtm_version = RTM_VERSION;
60     rtma.rtma_rtm.rtm_type = message;
61     rtma.rtma_rtm.rtm_pid = getpid();
62     rtma.rtma_rtm.rtm_addrs = RTA_DST|RTA_GATEWAY;
63     if ( flags & RTF_HOST ) {
64         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at ) -
65                 sizeof( struct sockaddr_m );
66     } else {
67         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
68         rtma.rtma_rtm.rtm_addrs |= RTA_NETMASK;
69         rtma.rtma_mask = mask;
70     }
71
72     rtma.rtma_rtm.rtm_flags = flags;
73     rtma.rtma_dst = *dst;
74     rtma.rtma_gate = *gate;
75     if (( rc = write( rtfd, &rtma, rtma.rtma_rtm.rtm_msglen )) !=
76             rtma.rtma_rtm.rtm_msglen ) {
77         return( -1 );
78     }
79     return( 0 );
80 }
81 #endif BSD4_4