]> arthur.barton.de Git - netatalk.git/blob - etc/atalkd/route.c
This patch adds function prototypes, fixes a few argument count bugs for
[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 <string.h>
11 #include <sys/param.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <net/route.h>
15 #include <sys/ioctl.h>
16
17 #include <netatalk/at.h>
18
19 #include "rtmp.h"
20 #include "route.h"
21
22 #ifndef BSD4_4
23 int route( message, dst, gate, flags )
24     int                 message;
25     struct sockaddr     *dst, *gate;
26     int                 flags;
27 {
28 #ifdef TRU64
29     struct ortentry     rtent;
30 #else
31     struct rtentry      rtent;
32 #endif
33
34     memset( &rtent, 0, sizeof( struct rtentry ));
35     rtent.rt_dst = *dst;
36     rtent.rt_gateway = *gate;
37     rtent.rt_flags = flags;
38     return( ioctl( rtfd, message, &rtent ));
39 }
40
41 #else BSD4_4
42
43 struct sockaddr_m {
44     u_char      sam_len;
45     u_char      sam_family;
46     u_short     sam_pad;
47     u_short     sam_mask;
48 } mask = { sizeof( struct sockaddr_m ), 0, 0, 0xffff };
49
50 struct rt_msg_at {
51     struct rt_msghdr    rtma_rtm;
52     struct sockaddr_at  rtma_dst;
53     struct sockaddr_at  rtma_gate;
54     struct sockaddr_m   rtma_mask;
55 } rtma;
56
57 route( message, dst, gate, flags )
58     int                 message;
59     struct sockaddr_at  *dst, *gate;
60     int                 flags;
61 {
62     int                 rc;
63
64     memset( &rtma, 0, sizeof( struct rt_msg_at ));
65     rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
66     rtma.rtma_rtm.rtm_version = RTM_VERSION;
67     rtma.rtma_rtm.rtm_type = message;
68     rtma.rtma_rtm.rtm_pid = getpid();
69     rtma.rtma_rtm.rtm_addrs = RTA_DST|RTA_GATEWAY;
70     if ( flags & RTF_HOST ) {
71         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at ) -
72                 sizeof( struct sockaddr_m );
73     } else {
74         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
75         rtma.rtma_rtm.rtm_addrs |= RTA_NETMASK;
76         rtma.rtma_mask = mask;
77     }
78
79     rtma.rtma_rtm.rtm_flags = flags;
80     rtma.rtma_dst = *dst;
81     rtma.rtma_gate = *gate;
82     if (( rc = write( rtfd, &rtma, rtma.rtma_rtm.rtm_msglen )) !=
83             rtma.rtma_rtm.rtm_msglen ) {
84         return( -1 );
85     }
86     return( 0 );
87 }
88 #endif BSD4_4