]> arthur.barton.de Git - netatalk.git/blob - etc/atalkd/route.c
Big configure.in cleanup
[netatalk.git] / etc / atalkd / route.c
1 /*
2  * $Id: route.c,v 1.8 2009-10-13 22:55:37 didg 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( int message, struct sockaddr *dst, struct sockaddr *gate, int flags)
28 {
29 #ifdef TRU64
30     struct ortentry     rtent;
31 #else /* TRU64 */
32     struct rtentry      rtent;
33 #endif /* TRU64 */
34
35     memset( &rtent, 0, sizeof( struct rtentry ));
36     rtent.rt_dst = *dst;
37     rtent.rt_gateway = *gate;
38     rtent.rt_flags = flags;
39     return( ioctl( rtfd, message, &rtent ));
40 }
41
42 #else /* BSD4_4 */
43
44 struct sockaddr_m {
45     u_char      sam_len;
46     u_char      sam_family;
47     u_short     sam_pad;
48     u_short     sam_mask;
49     u_short     sam_pad2;
50 } mask = { sizeof( struct sockaddr_m ), 0, 0, 0xffff, 0 };
51
52 struct rt_msg_at {
53     struct rt_msghdr    rtma_rtm;
54     struct sockaddr_at  rtma_dst;
55     struct sockaddr_at  rtma_gate;
56     struct sockaddr_m   rtma_mask;
57 } rtma;
58
59 route( int message, struct sockaddr_at  *dst, struct sockaddr_at *gate, int flags)
60 {
61     int                 rc;
62
63     memset( &rtma, 0, sizeof( struct rt_msg_at ));
64     rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
65     rtma.rtma_rtm.rtm_version = RTM_VERSION;
66     rtma.rtma_rtm.rtm_type = message;
67     rtma.rtma_rtm.rtm_pid = getpid();
68     rtma.rtma_rtm.rtm_addrs = RTA_DST|RTA_GATEWAY;
69     if ( flags & RTF_HOST ) {
70         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at ) -
71                 sizeof( struct sockaddr_m );
72     } else {
73         rtma.rtma_rtm.rtm_msglen = sizeof( struct rt_msg_at );
74         rtma.rtma_rtm.rtm_addrs |= RTA_NETMASK;
75         rtma.rtma_mask = mask;
76     }
77
78     rtma.rtma_rtm.rtm_flags = flags;
79     rtma.rtma_dst = *dst;
80     rtma.rtma_gate = *gate;
81     if (( rc = write( rtfd, &rtma, rtma.rtma_rtm.rtm_msglen )) !=
82             rtma.rtma_rtm.rtm_msglen ) {
83         return( -1 );
84     }
85     return( 0 );
86 }
87 #endif /* BSD4_4 */