]> arthur.barton.de Git - netatalk.git/blob - etc/atalkd/multicast.c
Remove bdb env on exit
[netatalk.git] / etc / atalkd / multicast.c
1 /*
2  * $Id: multicast.c,v 1.13 2009-10-14 01:38:28 didg Exp $
3  *
4  * Copyright (c) 1990,1993 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 <stdlib.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <sys/param.h>
16 #include <sys/types.h>
17 #include <sys/ioctl.h>
18 #include <sys/socket.h>
19 #ifdef TRU64
20 #include <sys/mbuf.h>
21 #include <net/route.h>
22 #endif /* TRU64 */
23 #include <net/if.h>
24 #include <atalk/logger.h>
25
26 /* work around for FreeBSD */
27 #if defined(__FreeBSD__) && (__FreeBSD__ >= 2)
28 #include <osreldate.h>
29 #if __FreeBSD_version >= 300000
30 #include <net/if_dl.h>
31 #define NO_DATA_LINK_PASSTHROUGH
32 #endif /* __FreeBSD_version >= 300000 */
33 #endif /* __FreeBSD__ */
34
35 #ifdef __svr4__
36 #include <sys/sockio.h>
37 #endif /* __svr4__ */
38
39 #include <atalk/util.h>
40 #include <netatalk/endian.h>
41 #include "rtmp.h"
42 #include "zip.h"
43 #include "main.h"
44 #include "multicast.h"
45
46
47 static const unsigned char      ethermulti[ 6 ] = {
48     0x09, 0x00, 0x07, 0xff, 0xff, 0xff,
49 };
50
51 static const unsigned char      ethermultitab[ 253 ][ 6 ] = {
52     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x00, },
53     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x01, },
54     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x02, },
55     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x03, },
56     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x04, },
57     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x05, },
58     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x06, },
59     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x07, },
60     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x08, },
61     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x09, },
62     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0a, },
63     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0b, },
64     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0c, },
65     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0d, },
66     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0e, },
67     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x0f, },
68     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x10, },
69     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x11, },
70     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x12, },
71     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x13, },
72     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x14, },
73     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x15, },
74     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x16, },
75     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x17, },
76     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x18, },
77     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x19, },
78     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1a, },
79     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1b, },
80     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1c, },
81     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1d, },
82     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1e, },
83     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x1f, },
84     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x20, },
85     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x21, },
86     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x22, },
87     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x23, },
88     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x24, },
89     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x25, },
90     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x26, },
91     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x27, },
92     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x28, },
93     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x29, },
94     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2a, },
95     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2b, },
96     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2c, },
97     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2d, },
98     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2e, },
99     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x2f, },
100     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x30, },
101     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x31, },
102     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x32, },
103     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x33, },
104     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x34, },
105     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x35, },
106     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x36, },
107     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x37, },
108     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x38, },
109     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x39, },
110     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3a, },
111     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3b, },
112     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3c, },
113     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3d, },
114     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3e, },
115     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x3f, },
116     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x40, },
117     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x41, },
118     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x42, },
119     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x43, },
120     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x44, },
121     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x45, },
122     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x46, },
123     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x47, },
124     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x48, },
125     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x49, },
126     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4a, },
127     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4b, },
128     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4c, },
129     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4d, },
130     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4e, },
131     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x4f, },
132     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x50, },
133     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x51, },
134     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x52, },
135     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x53, },
136     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x54, },
137     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x55, },
138     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x56, },
139     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x57, },
140     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x58, },
141     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x59, },
142     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5a, },
143     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5b, },
144     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5c, },
145     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5d, },
146     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5e, },
147     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x5f, },
148     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x60, },
149     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x61, },
150     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x62, },
151     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x63, },
152     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x64, },
153     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x65, },
154     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x66, },
155     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x67, },
156     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x68, },
157     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x69, },
158     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6a, },
159     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6b, },
160     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6c, },
161     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6d, },
162     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6e, },
163     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x6f, },
164     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x70, },
165     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x71, },
166     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x72, },
167     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x73, },
168     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x74, },
169     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x75, },
170     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x76, },
171     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x77, },
172     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x78, },
173     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x79, },
174     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7a, },
175     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7b, },
176     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7c, },
177     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7d, },
178     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7e, },
179     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x7f, },
180     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x80, },
181     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x81, },
182     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x82, },
183     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x83, },
184     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x84, },
185     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x85, },
186     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x86, },
187     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x87, },
188     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x88, },
189     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x89, },
190     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8a, },
191     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8b, },
192     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8c, },
193     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8d, },
194     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8e, },
195     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x8f, },
196     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x90, },
197     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x91, },
198     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x92, },
199     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x93, },
200     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x94, },
201     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x95, },
202     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x96, },
203     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x97, },
204     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x98, },
205     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x99, },
206     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9a, },
207     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9b, },
208     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9c, },
209     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9d, },
210     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9e, },
211     { 0x09, 0x00, 0x07, 0x00, 0x00, 0x9f, },
212     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa0, },
213     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa1, },
214     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa2, },
215     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa3, },
216     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa4, },
217     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa5, },
218     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa6, },
219     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa7, },
220     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa8, },
221     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xa9, },
222     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xaa, },
223     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xab, },
224     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xac, },
225     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xad, },
226     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xae, },
227     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xaf, },
228     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb0, },
229     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb1, },
230     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb2, },
231     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb3, },
232     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb4, },
233     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb5, },
234     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb6, },
235     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb7, },
236     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb8, },
237     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xb9, },
238     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xba, },
239     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xbb, },
240     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xbc, },
241     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xbd, },
242     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xbe, },
243     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xbf, },
244     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc0, },
245     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc1, },
246     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc2, },
247     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc3, },
248     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc4, },
249     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc5, },
250     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc6, },
251     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc7, },
252     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc8, },
253     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xc9, },
254     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xca, },
255     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xcb, },
256     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xcc, },
257     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xcd, },
258     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xce, },
259     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xcf, },
260     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd0, },
261     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd1, },
262     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd2, },
263     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd3, },
264     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd4, },
265     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd5, },
266     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd6, },
267     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd7, },
268     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd8, },
269     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xd9, },
270     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xda, },
271     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xdb, },
272     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xdc, },
273     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xdd, },
274     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xde, },
275     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xdf, },
276     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe0, },
277     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe1, },
278     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe2, },
279     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe3, },
280     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe4, },
281     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe5, },
282     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe6, },
283     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe7, },
284     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe8, },
285     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xe9, },
286     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xea, },
287     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xeb, },
288     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xec, },
289     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xed, },
290     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xee, },
291     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xef, },
292     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf0, },
293     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf1, },
294     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf2, },
295     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf3, },
296     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf4, },
297     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf5, },
298     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf6, },
299     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf7, },
300     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf8, },
301     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xf9, },
302     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xfa, },
303     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xfb, },
304     { 0x09, 0x00, 0x07, 0x00, 0x00, 0xfc, },
305 };
306
307
308
309 /* configure multicast for a given named interface */
310 int addmulti(const char *name, const unsigned char *data)
311 {
312 #ifdef NO_DATA_LINK_PASSTHROUGH
313     struct sockaddr_dl sa;
314 #else /* NO_DATA_LINK_PASSTHROUGH */
315     struct sockaddr sa;
316 #endif /* NO_DATA_LINK_PASSTHROUGH */
317
318     memset(&sa, 0, sizeof(sa));
319 #ifdef NO_DATA_LINK_PASSTHROUGH
320     sa.sdl_family = AF_LINK;
321     memcpy(LLADDR(&sa), data ? data : ethermulti, sizeof(ethermulti));
322     sa.sdl_alen = sizeof(ethermulti);
323     sa.sdl_len = sizeof(sa);
324 #else /* NO_DATA_LINK_PASSTHROUGH */
325     memcpy(sa.sa_data, data ? data : ethermulti, sizeof(ethermulti));
326 #endif /* NO_DATA_LINK_PASSTHROUGH */
327     if (ifconfig(name, SIOCADDMULTI, (struct sockaddr_at *)&sa))
328       return -1;
329
330     return 0;
331 }
332
333 static u_int16_t
334 atalk_cksum( u_char *data, int len)
335 {
336     u_char      *end;
337     u_int32_t   cksum = 0;
338
339     for ( end = data + len; data < end; data++ ) {
340         cksum = ( cksum + *data ) << 1;
341         if ( cksum & 0x00010000 ) {
342             cksum++;
343         }
344         cksum &= 0x0000ffff;
345     }
346
347     if ( cksum == 0 ) {
348         cksum = 0x0000ffff;
349     }
350
351     return( (u_int16_t) cksum );
352 }
353
354 /*
355  * Fill in multicast for zone.  There is a general issue here:  how can
356  * we tell the type of interface we're configuring for?  E.g.  Is it
357  * ethernet, tokenring, or FDDI?  (Of course, FDDI and Ethernet look just
358  * alike.)
359  */
360 int
361 zone_bcast( struct ziptab *zt)
362 {
363     u_char              uname[ 32 ];
364     u_int16_t           cksum;
365     int                 i;
366
367     if (!zt->zt_bcast &&
368         (zt->zt_bcast = (u_char *) malloc(sizeof( ethermulti ))) == NULL) {
369        LOG(log_error, logtype_atalkd, "zone_bcast malloc: %s", strerror(errno) );
370        return -1;
371      }
372
373     for ( i = 0; i < zt->zt_len; i++ ) {
374         uname[ i ] = diatoupper((int) zt->zt_name[ i ]);
375     }
376     cksum = atalk_cksum( uname, zt->zt_len );
377 #define elements(a)   (sizeof(a)/sizeof((a)[0]))
378     memcpy(zt->zt_bcast, ethermultitab[ cksum % elements( ethermultitab ) ],
379            sizeof( ethermulti ));
380     return 0;
381 }