cfparse.y revision 1.2 1 1.1 mycroft %{
2 1.1 mycroft /*
3 1.1 mycroft * Configuration file parser for mrouted.
4 1.1 mycroft *
5 1.1 mycroft * Written by Bill Fenner, NRL, 1994
6 1.1 mycroft *
7 1.2 cgd * $Id: cfparse.y,v 1.2 1995/06/07 17:39:37 cgd Exp $
8 1.1 mycroft */
9 1.1 mycroft #include <stdio.h>
10 1.2 cgd #include <string.h>
11 1.1 mycroft #include <varargs.h>
12 1.1 mycroft #include "defs.h"
13 1.1 mycroft
14 1.1 mycroft static FILE *f;
15 1.1 mycroft
16 1.1 mycroft extern int udp_socket;
17 1.1 mycroft char *configfilename = _PATH_MROUTED_CONF;
18 1.1 mycroft
19 1.1 mycroft extern int cache_lifetime;
20 1.1 mycroft extern int max_prune_lifetime;
21 1.1 mycroft
22 1.1 mycroft static int lineno;
23 1.1 mycroft static struct ifreq ifbuf[32];
24 1.1 mycroft static struct ifconf ifc;
25 1.1 mycroft
26 1.1 mycroft static struct uvif *v;
27 1.1 mycroft
28 1.1 mycroft static int order;
29 1.1 mycroft
30 1.1 mycroft struct addrmask {
31 1.1 mycroft u_int32_t addr;
32 1.1 mycroft int mask;
33 1.1 mycroft };
34 1.1 mycroft
35 1.1 mycroft struct boundnam {
36 1.1 mycroft char *name;
37 1.1 mycroft struct addrmask bound;
38 1.1 mycroft };
39 1.1 mycroft
40 1.1 mycroft #define MAXBOUNDS 20
41 1.1 mycroft
42 1.1 mycroft struct boundnam boundlist[MAXBOUNDS]; /* Max. of 20 named boundaries */
43 1.1 mycroft int numbounds = 0; /* Number of named boundaries */
44 1.1 mycroft
45 1.1 mycroft %}
46 1.1 mycroft
47 1.1 mycroft %union
48 1.1 mycroft {
49 1.1 mycroft int num;
50 1.1 mycroft char *ptr;
51 1.1 mycroft struct addrmask addrmask;
52 1.1 mycroft u_int32_t addr;
53 1.1 mycroft };
54 1.1 mycroft
55 1.1 mycroft %token CACHE_LIFETIME PRUNING
56 1.1 mycroft %token PHYINT TUNNEL NAME
57 1.1 mycroft %token DISABLE METRIC THRESHOLD RATE_LIMIT SRCRT BOUNDARY NETMASK ALTNET
58 1.1 mycroft %token <num> BOOLEAN
59 1.1 mycroft %token <num> NUMBER
60 1.1 mycroft %token <ptr> STRING
61 1.1 mycroft %token <addrmask> ADDRMASK
62 1.1 mycroft %token <addr> ADDR
63 1.1 mycroft
64 1.1 mycroft %type <addr> interface
65 1.1 mycroft %type <addrmask> bound boundary addrmask
66 1.1 mycroft
67 1.1 mycroft %start conf
68 1.1 mycroft
69 1.1 mycroft %%
70 1.1 mycroft
71 1.1 mycroft conf : stmts
72 1.1 mycroft ;
73 1.1 mycroft
74 1.1 mycroft stmts : /* Empty */
75 1.1 mycroft | stmts stmt
76 1.1 mycroft ;
77 1.1 mycroft
78 1.1 mycroft stmt : error
79 1.1 mycroft | PHYINT interface {
80 1.1 mycroft
81 1.1 mycroft vifi_t vifi;
82 1.1 mycroft
83 1.1 mycroft if (order)
84 1.1 mycroft fatal("phyints must appear before tunnels");
85 1.1 mycroft
86 1.1 mycroft for (vifi = 0, v = uvifs;
87 1.1 mycroft vifi < numvifs;
88 1.1 mycroft ++vifi, ++v)
89 1.1 mycroft if (!(v->uv_flags & VIFF_TUNNEL) &&
90 1.1 mycroft $2 == v->uv_lcl_addr)
91 1.1 mycroft break;
92 1.1 mycroft
93 1.1 mycroft if (vifi == numvifs)
94 1.1 mycroft fatal("%s is not a configured interface",
95 1.1 mycroft inet_fmt($2,s1));
96 1.1 mycroft
97 1.1 mycroft /*log(LOG_INFO, 0, "phyint: %x\n", v);*/
98 1.1 mycroft }
99 1.1 mycroft ifmods
100 1.1 mycroft | TUNNEL interface ADDR {
101 1.1 mycroft
102 1.1 mycroft struct ifreq *ifr;
103 1.1 mycroft struct ifreq ffr;
104 1.1 mycroft vifi_t vifi;
105 1.1 mycroft
106 1.1 mycroft order++;
107 1.1 mycroft
108 1.1 mycroft ifr = ifconfaddr(&ifc, $2);
109 1.1 mycroft if (ifr == 0)
110 1.1 mycroft fatal("Tunnel local address %s is not mine",
111 1.1 mycroft inet_fmt($2, s1));
112 1.1 mycroft
113 1.1 mycroft strncpy(ffr.ifr_name, ifr->ifr_name, IFNAMSIZ);
114 1.1 mycroft if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ffr)<0)
115 1.1 mycroft fatal("ioctl SIOCGIFFLAGS on %s",ffr.ifr_name);
116 1.1 mycroft if (ffr.ifr_flags & IFF_LOOPBACK)
117 1.1 mycroft fatal("Tunnel local address %s is a loopback interface",
118 1.1 mycroft inet_fmt($2, s1));
119 1.1 mycroft
120 1.1 mycroft if (ifconfaddr(&ifc, $3) != 0)
121 1.1 mycroft fatal("Tunnel remote address %s is one of mine",
122 1.1 mycroft inet_fmt($3, s1));
123 1.1 mycroft
124 1.1 mycroft for (vifi = 0, v = uvifs;
125 1.1 mycroft vifi < numvifs;
126 1.1 mycroft ++vifi, ++v)
127 1.1 mycroft if (v->uv_flags & VIFF_TUNNEL) {
128 1.1 mycroft if ($3 == v->uv_rmt_addr)
129 1.1 mycroft fatal("Duplicate tunnel to %s",
130 1.1 mycroft inet_fmt($3, s1));
131 1.1 mycroft } else if (!(v->uv_flags & VIFF_DISABLED)) {
132 1.1 mycroft if (($3 & v->uv_subnetmask) == v->uv_subnet)
133 1.1 mycroft fatal("Unnecessary tunnel to %s",
134 1.1 mycroft inet_fmt($3,s1));
135 1.1 mycroft }
136 1.1 mycroft
137 1.1 mycroft if (numvifs == MAXVIFS)
138 1.1 mycroft fatal("too many vifs");
139 1.1 mycroft
140 1.1 mycroft v = &uvifs[numvifs];
141 1.1 mycroft v->uv_flags = VIFF_TUNNEL;
142 1.1 mycroft v->uv_metric = DEFAULT_METRIC;
143 1.1 mycroft v->uv_rate_limit= DEFAULT_TUN_RATE_LIMIT;
144 1.1 mycroft v->uv_threshold = DEFAULT_THRESHOLD;
145 1.1 mycroft v->uv_lcl_addr = $2;
146 1.1 mycroft v->uv_rmt_addr = $3;
147 1.1 mycroft v->uv_subnet = 0;
148 1.1 mycroft v->uv_subnetmask= 0;
149 1.1 mycroft v->uv_subnetbcast= 0;
150 1.1 mycroft strncpy(v->uv_name, ffr.ifr_name, IFNAMSIZ);
151 1.1 mycroft v->uv_groups = NULL;
152 1.1 mycroft v->uv_neighbors = NULL;
153 1.1 mycroft v->uv_acl = NULL;
154 1.1 mycroft v->uv_addrs = NULL;
155 1.1 mycroft
156 1.1 mycroft if (!(ffr.ifr_flags & IFF_UP)) {
157 1.1 mycroft v->uv_flags |= VIFF_DOWN;
158 1.1 mycroft vifs_down = TRUE;
159 1.1 mycroft }
160 1.1 mycroft /*log(LOG_INFO, 0, "tunnel: %x\n", v);*/
161 1.1 mycroft }
162 1.1 mycroft tunnelmods
163 1.1 mycroft {
164 1.1 mycroft log(LOG_INFO, 0,
165 1.1 mycroft "installing tunnel from %s to %s as vif #%u - rate=%d",
166 1.1 mycroft inet_fmt($2, s1), inet_fmt($3, s2),
167 1.1 mycroft numvifs, v->uv_rate_limit);
168 1.1 mycroft
169 1.1 mycroft ++numvifs;
170 1.1 mycroft }
171 1.1 mycroft | PRUNING BOOLEAN { pruning = $2; }
172 1.1 mycroft | CACHE_LIFETIME NUMBER { cache_lifetime = $2;
173 1.1 mycroft max_prune_lifetime = cache_lifetime * 2;
174 1.1 mycroft }
175 1.1 mycroft | NAME STRING boundary { if (numbounds >= MAXBOUNDS) {
176 1.1 mycroft fatal("Too many named boundaries (max %d)", MAXBOUNDS);
177 1.1 mycroft }
178 1.1 mycroft
179 1.1 mycroft boundlist[numbounds].name = malloc(strlen($2) + 1);
180 1.1 mycroft strcpy(boundlist[numbounds].name, $2);
181 1.1 mycroft boundlist[numbounds++].bound = $3;
182 1.1 mycroft }
183 1.1 mycroft ;
184 1.1 mycroft
185 1.1 mycroft tunnelmods : /* empty */
186 1.1 mycroft | tunnelmods /*{ log(LOG_INFO, 0, "tunnelmod: %x", v); }*/ tunnelmod
187 1.1 mycroft ;
188 1.1 mycroft
189 1.1 mycroft tunnelmod : mod
190 1.1 mycroft | SRCRT { fatal("Source-route tunnels not supported"); }
191 1.1 mycroft ;
192 1.1 mycroft
193 1.1 mycroft ifmods : /* empty */
194 1.1 mycroft | ifmods /*{ log(LOG_INFO, 0, "ifmod: %x", v); }*/ ifmod
195 1.1 mycroft ;
196 1.1 mycroft
197 1.1 mycroft ifmod : mod
198 1.1 mycroft | DISABLE { v->uv_flags |= VIFF_DISABLED; }
199 1.1 mycroft | NETMASK ADDR { v->uv_subnetmask = $2; }
200 1.1 mycroft | ALTNET addrmask {
201 1.1 mycroft
202 1.1 mycroft struct phaddr *ph;
203 1.1 mycroft
204 1.1 mycroft ph = (struct phaddr *)malloc(sizeof(struct phaddr));
205 1.1 mycroft if (ph == NULL)
206 1.1 mycroft fatal("out of memory");
207 1.1 mycroft if ($2.mask) {
208 1.1 mycroft VAL_TO_MASK(ph->pa_mask, $2.mask);
209 1.1 mycroft } else
210 1.1 mycroft ph->pa_mask = v->uv_subnetmask;
211 1.1 mycroft ph->pa_addr = $2.addr & ph->pa_mask;
212 1.1 mycroft if ($2.addr & ~ph->pa_mask)
213 1.1 mycroft warn("Extra addr %s/%d has host bits set",
214 1.1 mycroft inet_fmt($2.addr,s1), $2.mask);
215 1.1 mycroft ph->pa_next = v->uv_addrs;
216 1.1 mycroft v->uv_addrs = ph;
217 1.1 mycroft
218 1.1 mycroft }
219 1.1 mycroft ;
220 1.1 mycroft
221 1.1 mycroft mod : THRESHOLD NUMBER { if ($2 < 1 || $2 > 255)
222 1.1 mycroft fatal("Invalid threshold %d",$2);
223 1.1 mycroft v->uv_threshold = $2;
224 1.1 mycroft }
225 1.1 mycroft | THRESHOLD {
226 1.1 mycroft
227 1.1 mycroft warn("Expected number after threshold keyword");
228 1.1 mycroft
229 1.1 mycroft }
230 1.1 mycroft | METRIC NUMBER { if ($2 < 1 || $2 > UNREACHABLE)
231 1.1 mycroft fatal("Invalid metric %d",$2);
232 1.1 mycroft v->uv_metric = $2;
233 1.1 mycroft }
234 1.1 mycroft | METRIC {
235 1.1 mycroft
236 1.1 mycroft warn("Expected number after metric keyword");
237 1.1 mycroft
238 1.1 mycroft }
239 1.1 mycroft | RATE_LIMIT NUMBER { if ($2 > MAX_RATE_LIMIT)
240 1.1 mycroft fatal("Invalid rate_limit %d",$2);
241 1.1 mycroft v->uv_rate_limit = $2;
242 1.1 mycroft }
243 1.1 mycroft | RATE_LIMIT {
244 1.1 mycroft
245 1.1 mycroft warn("Expected number after rate_limit keyword");
246 1.1 mycroft
247 1.1 mycroft }
248 1.1 mycroft | BOUNDARY bound {
249 1.1 mycroft
250 1.1 mycroft struct vif_acl *v_acl;
251 1.1 mycroft
252 1.1 mycroft v_acl = (struct vif_acl *)malloc(sizeof(struct vif_acl));
253 1.1 mycroft if (v_acl == NULL)
254 1.1 mycroft fatal("out of memory");
255 1.1 mycroft VAL_TO_MASK(v_acl->acl_mask, $2.mask);
256 1.1 mycroft v_acl->acl_addr = $2.addr & v_acl->acl_mask;
257 1.1 mycroft if ($2.addr & ~v_acl->acl_mask)
258 1.1 mycroft warn("Boundary spec %s/%d has host bits set",
259 1.1 mycroft inet_fmt($2.addr,s1),$2.mask);
260 1.1 mycroft v_acl->acl_next = v->uv_acl;
261 1.1 mycroft v->uv_acl = v_acl;
262 1.1 mycroft
263 1.1 mycroft }
264 1.1 mycroft | BOUNDARY {
265 1.1 mycroft
266 1.1 mycroft warn("Expected boundary spec after boundary keyword");
267 1.1 mycroft
268 1.1 mycroft }
269 1.1 mycroft ;
270 1.1 mycroft
271 1.1 mycroft interface : ADDR { $$ = $1; }
272 1.1 mycroft | STRING {
273 1.1 mycroft $$ = valid_if($1);
274 1.1 mycroft if ($$ == 0)
275 1.1 mycroft fatal("Invalid interface name %s",$1);
276 1.1 mycroft }
277 1.1 mycroft ;
278 1.1 mycroft
279 1.1 mycroft bound : boundary { $$ = $1; }
280 1.1 mycroft | STRING { int i;
281 1.1 mycroft
282 1.1 mycroft for (i=0; i < numbounds; i++) {
283 1.1 mycroft if (!strcmp(boundlist[i].name, $1)) {
284 1.1 mycroft $$ = boundlist[i].bound;
285 1.1 mycroft break;
286 1.1 mycroft }
287 1.1 mycroft }
288 1.1 mycroft if (i == numbounds) {
289 1.1 mycroft fatal("Invalid boundary name %s",$1);
290 1.1 mycroft }
291 1.1 mycroft }
292 1.1 mycroft ;
293 1.1 mycroft
294 1.1 mycroft boundary : ADDRMASK {
295 1.1 mycroft
296 1.1 mycroft if ((ntohl($1.addr) & 0xff000000) != 0xef000000) {
297 1.1 mycroft fatal("Boundaries must be 239.x.x.x, not %s/%d",
298 1.1 mycroft inet_fmt($1.addr, s1), $1.mask);
299 1.1 mycroft }
300 1.1 mycroft $$ = $1;
301 1.1 mycroft
302 1.1 mycroft }
303 1.1 mycroft ;
304 1.1 mycroft
305 1.1 mycroft addrmask : ADDRMASK { $$ = $1; }
306 1.1 mycroft | ADDR { $$.addr = $1; $$.mask = 0; }
307 1.1 mycroft ;
308 1.1 mycroft %%
309 1.1 mycroft /*VARARGS1*/
310 1.1 mycroft static void fatal(fmt, va_alist)
311 1.1 mycroft char *fmt;
312 1.1 mycroft va_dcl
313 1.1 mycroft {
314 1.1 mycroft va_list ap;
315 1.1 mycroft char buf[200];
316 1.1 mycroft
317 1.1 mycroft va_start(ap);
318 1.1 mycroft vsprintf(buf, fmt, ap);
319 1.1 mycroft va_end(ap);
320 1.1 mycroft
321 1.1 mycroft log(LOG_ERR,0,"%s: %s near line %d", configfilename, buf, lineno);
322 1.1 mycroft }
323 1.1 mycroft
324 1.1 mycroft /*VARARGS1*/
325 1.1 mycroft static void warn(fmt, va_alist)
326 1.1 mycroft char *fmt;
327 1.1 mycroft va_dcl
328 1.1 mycroft {
329 1.1 mycroft va_list ap;
330 1.1 mycroft char buf[200];
331 1.1 mycroft
332 1.1 mycroft va_start(ap);
333 1.1 mycroft vsprintf(buf, fmt, ap);
334 1.1 mycroft va_end(ap);
335 1.1 mycroft
336 1.1 mycroft log(LOG_WARNING,0,"%s: %s near line %d", configfilename, buf, lineno);
337 1.1 mycroft }
338 1.1 mycroft
339 1.1 mycroft void yyerror(s)
340 1.1 mycroft char *s;
341 1.1 mycroft {
342 1.1 mycroft log(LOG_ERR, 0, "%s: %s near line %d", configfilename, s, lineno);
343 1.1 mycroft }
344 1.1 mycroft
345 1.1 mycroft char *next_word()
346 1.1 mycroft {
347 1.1 mycroft static char buf[1024];
348 1.1 mycroft static char *p=NULL;
349 1.1 mycroft extern FILE *f;
350 1.1 mycroft char *q;
351 1.1 mycroft
352 1.1 mycroft while (1) {
353 1.1 mycroft if (!p || !*p) {
354 1.1 mycroft lineno++;
355 1.1 mycroft if (fgets(buf, sizeof(buf), f) == NULL)
356 1.1 mycroft return NULL;
357 1.1 mycroft p = buf;
358 1.1 mycroft }
359 1.1 mycroft while (*p && (*p == ' ' || *p == '\t')) /* skip whitespace */
360 1.1 mycroft p++;
361 1.1 mycroft if (*p == '#') {
362 1.1 mycroft p = NULL; /* skip comments */
363 1.1 mycroft continue;
364 1.1 mycroft }
365 1.1 mycroft q = p;
366 1.1 mycroft while (*p && *p != ' ' && *p != '\t' && *p != '\n')
367 1.1 mycroft p++; /* find next whitespace */
368 1.1 mycroft *p++ = '\0'; /* null-terminate string */
369 1.1 mycroft
370 1.1 mycroft if (!*q) {
371 1.1 mycroft p = NULL;
372 1.1 mycroft continue; /* if 0-length string, read another line */
373 1.1 mycroft }
374 1.1 mycroft
375 1.1 mycroft return q;
376 1.1 mycroft }
377 1.1 mycroft }
378 1.1 mycroft
379 1.1 mycroft int yylex()
380 1.1 mycroft {
381 1.1 mycroft int n;
382 1.1 mycroft u_int32_t addr;
383 1.1 mycroft char *q;
384 1.1 mycroft
385 1.1 mycroft if ((q = next_word()) == NULL) {
386 1.1 mycroft return 0;
387 1.1 mycroft }
388 1.1 mycroft
389 1.1 mycroft if (!strcmp(q,"cache_lifetime"))
390 1.1 mycroft return CACHE_LIFETIME;
391 1.1 mycroft if (!strcmp(q,"pruning"))
392 1.1 mycroft return PRUNING;
393 1.1 mycroft if (!strcmp(q,"phyint"))
394 1.1 mycroft return PHYINT;
395 1.1 mycroft if (!strcmp(q,"tunnel"))
396 1.1 mycroft return TUNNEL;
397 1.1 mycroft if (!strcmp(q,"disable"))
398 1.1 mycroft return DISABLE;
399 1.1 mycroft if (!strcmp(q,"metric"))
400 1.1 mycroft return METRIC;
401 1.1 mycroft if (!strcmp(q,"threshold"))
402 1.1 mycroft return THRESHOLD;
403 1.1 mycroft if (!strcmp(q,"rate_limit"))
404 1.1 mycroft return RATE_LIMIT;
405 1.1 mycroft if (!strcmp(q,"srcrt") || !strcmp(q,"sourceroute"))
406 1.1 mycroft return SRCRT;
407 1.1 mycroft if (!strcmp(q,"boundary"))
408 1.1 mycroft return BOUNDARY;
409 1.1 mycroft if (!strcmp(q,"netmask"))
410 1.1 mycroft return NETMASK;
411 1.1 mycroft if (!strcmp(q,"name"))
412 1.1 mycroft return NAME;
413 1.1 mycroft if (!strcmp(q,"altnet"))
414 1.1 mycroft return ALTNET;
415 1.1 mycroft if (!strcmp(q,"on") || !strcmp(q,"yes")) {
416 1.1 mycroft yylval.num = 1;
417 1.1 mycroft return BOOLEAN;
418 1.1 mycroft }
419 1.1 mycroft if (!strcmp(q,"off") || !strcmp(q,"no")) {
420 1.1 mycroft yylval.num = 0;
421 1.1 mycroft return BOOLEAN;
422 1.1 mycroft }
423 1.1 mycroft if (sscanf(q,"%[.0-9]/%d%c",s1,&n,s2) == 2) {
424 1.1 mycroft if ((addr = inet_parse(s1)) != 0xffffffff) {
425 1.1 mycroft yylval.addrmask.mask = n;
426 1.1 mycroft yylval.addrmask.addr = addr;
427 1.1 mycroft return ADDRMASK;
428 1.1 mycroft }
429 1.1 mycroft /* fall through to returning STRING */
430 1.1 mycroft }
431 1.1 mycroft if (sscanf(q,"%[.0-9]%c",s1,s2) == 1) {
432 1.1 mycroft if ((addr = inet_parse(s1)) != 0xffffffff &&
433 1.1 mycroft inet_valid_host(addr)) {
434 1.1 mycroft yylval.addr = addr;
435 1.1 mycroft return ADDR;
436 1.1 mycroft }
437 1.1 mycroft }
438 1.1 mycroft if (sscanf(q,"0x%8x%c",&n,s1) == 1) {
439 1.1 mycroft yylval.addr = n;
440 1.1 mycroft return ADDR;
441 1.1 mycroft }
442 1.1 mycroft if (sscanf(q,"%d%c",&n,s1) == 1) {
443 1.1 mycroft yylval.num = n;
444 1.1 mycroft return NUMBER;
445 1.1 mycroft }
446 1.1 mycroft yylval.ptr = q;
447 1.1 mycroft return STRING;
448 1.1 mycroft }
449 1.1 mycroft
450 1.1 mycroft void config_vifs_from_file()
451 1.1 mycroft {
452 1.1 mycroft extern FILE *f;
453 1.1 mycroft
454 1.1 mycroft order = 0;
455 1.1 mycroft numbounds = 0;
456 1.1 mycroft lineno = 0;
457 1.1 mycroft
458 1.1 mycroft if ((f = fopen(configfilename, "r")) == NULL) {
459 1.1 mycroft if (errno != ENOENT)
460 1.1 mycroft log(LOG_ERR, errno, "can't open %s", configfilename);
461 1.1 mycroft return;
462 1.1 mycroft }
463 1.1 mycroft
464 1.1 mycroft ifc.ifc_buf = (char *)ifbuf;
465 1.1 mycroft ifc.ifc_len = sizeof(ifbuf);
466 1.1 mycroft if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0)
467 1.1 mycroft log(LOG_ERR, errno, "ioctl SIOCGIFCONF");
468 1.1 mycroft
469 1.1 mycroft yyparse();
470 1.1 mycroft
471 1.1 mycroft close(f);
472 1.1 mycroft }
473 1.1 mycroft
474 1.1 mycroft static u_int32_t
475 1.1 mycroft valid_if(s)
476 1.1 mycroft char *s;
477 1.1 mycroft {
478 1.1 mycroft register vifi_t vifi;
479 1.1 mycroft register struct uvif *v;
480 1.1 mycroft
481 1.1 mycroft for (vifi=0, v=uvifs; vifi<numvifs; vifi++, v++)
482 1.1 mycroft if (!strcmp(v->uv_name, s))
483 1.1 mycroft return v->uv_lcl_addr;
484 1.1 mycroft
485 1.1 mycroft return 0;
486 1.1 mycroft }
487 1.1 mycroft
488 1.1 mycroft static struct ifreq *
489 1.1 mycroft ifconfaddr(ifcp, a)
490 1.1 mycroft struct ifconf *ifcp;
491 1.1 mycroft u_int32_t a;
492 1.1 mycroft {
493 1.1 mycroft int n;
494 1.1 mycroft struct ifreq *ifrp = (struct ifreq *)ifcp->ifc_buf;
495 1.1 mycroft struct ifreq *ifend = (struct ifreq *)((char *)ifrp + ifcp->ifc_len);
496 1.1 mycroft
497 1.1 mycroft while (ifrp < ifend) {
498 1.1 mycroft if (ifrp->ifr_addr.sa_family == AF_INET &&
499 1.1 mycroft ((struct sockaddr_in *)&ifrp->ifr_addr)->sin_addr.s_addr == a)
500 1.1 mycroft return (ifrp);
501 1.1 mycroft #if (defined(BSD) && (BSD >= 199006))
502 1.1 mycroft n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
503 1.1 mycroft if (n < sizeof(*ifrp))
504 1.1 mycroft ++ifrp;
505 1.1 mycroft else
506 1.1 mycroft ifrp = (struct ifreq *)((char *)ifrp + n);
507 1.1 mycroft #else
508 1.1 mycroft ++ifrp;
509 1.1 mycroft #endif
510 1.1 mycroft }
511 1.1 mycroft return (0);
512 1.1 mycroft }
513