Commit | Line | Data |
---|---|---|
ad9d7253 WJ |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | #ifndef lint | |
35 | char copyright[] = | |
36 | "@(#) Copyright (c) 1983 Regents of the University of California.\n\ | |
37 | All rights reserved.\n"; | |
38 | #endif /* not lint */ | |
39 | ||
40 | #ifndef lint | |
41 | static char sccsid[] = "@(#)ifconfig.c 5.1 (Berkeley) 2/28/91"; | |
42 | #endif /* not lint */ | |
43 | ||
44 | #include <sys/param.h> | |
45 | #include <sys/socket.h> | |
46 | #include <sys/ioctl.h> | |
47 | ||
48 | #include <net/if.h> | |
49 | #include <netinet/in.h> | |
50 | #include <arpa/inet.h> | |
51 | ||
52 | #ifdef notdef | |
53 | #define NSIP | |
54 | #include <netns/ns.h> | |
55 | #include <netns/ns_if.h> | |
56 | ||
57 | #define EON | |
58 | #include <netiso/iso.h> | |
59 | #include <netiso/iso_var.h> | |
60 | #endif | |
61 | #include <netdb.h> | |
62 | #include <sys/protosw.h> | |
63 | ||
64 | #include <unistd.h> | |
65 | #include <stdio.h> | |
66 | #include <errno.h> | |
67 | #include <ctype.h> | |
68 | #include <stdlib.h> | |
69 | #include <string.h> | |
70 | ||
71 | struct ifreq ifr, ridreq; | |
72 | struct ifaliasreq addreq; | |
73 | #ifdef EON | |
74 | struct iso_ifreq iso_ridreq; | |
75 | struct iso_aliasreq iso_addreq; | |
76 | #endif | |
77 | struct sockaddr_in netmask; | |
78 | ||
79 | char name[30]; | |
80 | int flags; | |
81 | int metric; | |
82 | int nsellength = 1; | |
83 | int setaddr; | |
84 | int setipdst; | |
85 | int doalias; | |
86 | int clearaddr; | |
87 | int newaddr = 1; | |
88 | int s; | |
89 | extern int errno; | |
90 | ||
91 | int setifflags(), setifaddr(), setifdstaddr(), setifnetmask(); | |
92 | int setifmetric(), setifbroadaddr(), setifipdst(); | |
93 | int notealias(), setsnpaoffset(), setnsellength(); | |
94 | ||
95 | #define NEXTARG 0xffffff | |
96 | ||
97 | struct cmd { | |
98 | char *c_name; | |
99 | int c_parameter; /* NEXTARG means next argv */ | |
100 | int (*c_func)(); | |
101 | } cmds[] = { | |
102 | { "up", IFF_UP, setifflags } , | |
103 | { "down", -IFF_UP, setifflags }, | |
104 | { "trailers", -IFF_NOTRAILERS,setifflags }, | |
105 | { "-trailers", IFF_NOTRAILERS, setifflags }, | |
106 | { "arp", -IFF_NOARP, setifflags }, | |
107 | { "-arp", IFF_NOARP, setifflags }, | |
108 | { "debug", IFF_DEBUG, setifflags }, | |
109 | { "-debug", -IFF_DEBUG, setifflags }, | |
110 | { "alias", IFF_UP, notealias }, | |
111 | { "-alias", -IFF_UP, notealias }, | |
112 | { "delete", -IFF_UP, notealias }, | |
113 | #ifdef notdef | |
114 | #define EN_SWABIPS 0x1000 | |
115 | { "swabips", EN_SWABIPS, setifflags }, | |
116 | { "-swabips", -EN_SWABIPS, setifflags }, | |
117 | #endif | |
118 | { "netmask", NEXTARG, setifnetmask }, | |
119 | { "metric", NEXTARG, setifmetric }, | |
120 | { "broadcast", NEXTARG, setifbroadaddr }, | |
121 | { "ipdst", NEXTARG, setifipdst }, | |
122 | { "snpaoffset", NEXTARG, setsnpaoffset }, | |
123 | { "nsellength", NEXTARG, setnsellength }, | |
124 | { 0, 0, setifaddr }, | |
125 | { 0, 0, setifdstaddr }, | |
126 | }; | |
127 | ||
128 | /* | |
129 | * XNS support liberally adapted from | |
130 | * code written at the University of Maryland | |
131 | * principally by James O'Toole and Chris Torek. | |
132 | */ | |
133 | int in_status(), in_getaddr(); | |
134 | #ifdef NSIP | |
135 | int xns_status(), xns_getaddr(); | |
136 | #endif | |
137 | #ifdef EON | |
138 | int iso_status(), iso_getaddr(); | |
139 | #endif | |
140 | ||
141 | /* Known address families */ | |
142 | struct afswtch { | |
143 | char *af_name; | |
144 | short af_af; | |
145 | int (*af_status)(); | |
146 | int (*af_getaddr)(); | |
147 | int af_difaddr; | |
148 | int af_aifaddr; | |
149 | caddr_t af_ridreq; | |
150 | caddr_t af_addreq; | |
151 | } afs[] = { | |
152 | #define C(x) ((caddr_t) &x) | |
153 | { "inet", AF_INET, in_status, in_getaddr, | |
154 | SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) }, | |
155 | #ifdef NSIP | |
156 | { "ns", AF_NS, xns_status, xns_getaddr, | |
157 | SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) }, | |
158 | #endif | |
159 | #ifdef EON | |
160 | { "iso", AF_ISO, iso_status, iso_getaddr, | |
161 | SIOCDIFADDR_ISO, SIOCAIFADDR_ISO, C(iso_ridreq), C(iso_addreq) }, | |
162 | #endif | |
163 | { 0, 0, 0, 0 } | |
164 | }; | |
165 | ||
166 | struct afswtch *afp; /*the address family being set or asked about*/ | |
167 | ||
168 | main(argc, argv) | |
169 | int argc; | |
170 | char *argv[]; | |
171 | { | |
172 | int af = AF_INET; | |
173 | register struct afswtch *rafp; | |
174 | ||
175 | if (argc < 2) { | |
176 | fprintf(stderr, "usage: ifconfig interface\n%s%s%s%s%s", | |
177 | "\t[ af [ address [ dest_addr ] ] [ up ] [ down ]", | |
178 | "[ netmask mask ] ]\n", | |
179 | "\t[ metric n ]\n", | |
180 | "\t[ trailers | -trailers ]\n", | |
181 | "\t[ arp | -arp ]\n"); | |
182 | exit(1); | |
183 | } | |
184 | argc--, argv++; | |
185 | strncpy(name, *argv, sizeof(name)); | |
186 | strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); | |
187 | argc--, argv++; | |
188 | if (argc > 0) { | |
189 | for (afp = rafp = afs; rafp->af_name; rafp++) | |
190 | if (strcmp(rafp->af_name, *argv) == 0) { | |
191 | afp = rafp; argc--; argv++; | |
192 | break; | |
193 | } | |
194 | rafp = afp; | |
195 | af = ifr.ifr_addr.sa_family = rafp->af_af; | |
196 | } | |
197 | s = socket(af, SOCK_DGRAM, 0); | |
198 | if (s < 0) { | |
199 | perror("ifconfig: socket"); | |
200 | exit(1); | |
201 | } | |
202 | if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) { | |
203 | Perror("ioctl (SIOCGIFFLAGS)"); | |
204 | exit(1); | |
205 | } | |
206 | strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); | |
207 | flags = ifr.ifr_flags; | |
208 | if (ioctl(s, SIOCGIFMETRIC, (caddr_t)&ifr) < 0) | |
209 | perror("ioctl (SIOCGIFMETRIC)"); | |
210 | else | |
211 | metric = ifr.ifr_metric; | |
212 | if (argc == 0) { | |
213 | status(); | |
214 | exit(0); | |
215 | } | |
216 | while (argc > 0) { | |
217 | register struct cmd *p; | |
218 | ||
219 | for (p = cmds; p->c_name; p++) | |
220 | if (strcmp(*argv, p->c_name) == 0) | |
221 | break; | |
222 | if (p->c_name == 0 && setaddr) | |
223 | p++; /* got src, do dst */ | |
224 | if (p->c_func) { | |
225 | if (p->c_parameter == NEXTARG) { | |
226 | (*p->c_func)(argv[1]); | |
227 | argc--, argv++; | |
228 | } else | |
229 | (*p->c_func)(*argv, p->c_parameter); | |
230 | } | |
231 | argc--, argv++; | |
232 | } | |
233 | if (af == AF_ISO) | |
234 | adjust_nsellength(); | |
235 | #ifdef NSIP | |
236 | if (setipdst && af==AF_NS) { | |
237 | struct nsip_req rq; | |
238 | int size = sizeof(rq); | |
239 | ||
240 | rq.rq_ns = addreq.ifra_addr; | |
241 | rq.rq_ip = addreq.ifra_dstaddr; | |
242 | ||
243 | if (setsockopt(s, 0, SO_NSIP_ROUTE, &rq, size) < 0) | |
244 | Perror("Encapsulation Routing"); | |
245 | } | |
246 | #endif | |
247 | if (clearaddr) { | |
248 | int ret; | |
249 | strncpy(rafp->af_ridreq, name, sizeof ifr.ifr_name); | |
250 | if ((ret = ioctl(s, rafp->af_difaddr, rafp->af_ridreq)) < 0) { | |
251 | if (errno == EADDRNOTAVAIL && (doalias >= 0)) { | |
252 | /* means no previous address for interface */ | |
253 | } else | |
254 | Perror("ioctl (SIOCDIFADDR)"); | |
255 | } | |
256 | } | |
257 | if (newaddr) { | |
258 | strncpy(rafp->af_addreq, name, sizeof ifr.ifr_name); | |
259 | if (ioctl(s, rafp->af_aifaddr, rafp->af_addreq) < 0) | |
260 | Perror("ioctl (SIOCAIFADDR)"); | |
261 | } | |
262 | exit(0); | |
263 | } | |
264 | #define RIDADDR 0 | |
265 | #define ADDR 1 | |
266 | #define MASK 2 | |
267 | #define DSTADDR 3 | |
268 | ||
269 | /*ARGSUSED*/ | |
270 | setifaddr(addr, param) | |
271 | char *addr; | |
272 | short param; | |
273 | { | |
274 | /* | |
275 | * Delay the ioctl to set the interface addr until flags are all set. | |
276 | * The address interpretation may depend on the flags, | |
277 | * and the flags may change when the address is set. | |
278 | */ | |
279 | setaddr++; | |
280 | if (doalias == 0) | |
281 | clearaddr = 1; | |
282 | (*afp->af_getaddr)(addr, (doalias >= 0 ? ADDR : RIDADDR)); | |
283 | } | |
284 | ||
285 | setifnetmask(addr) | |
286 | char *addr; | |
287 | { | |
288 | (*afp->af_getaddr)(addr, MASK); | |
289 | } | |
290 | ||
291 | setifbroadaddr(addr) | |
292 | char *addr; | |
293 | { | |
294 | (*afp->af_getaddr)(addr, DSTADDR); | |
295 | } | |
296 | ||
297 | setifipdst(addr) | |
298 | char *addr; | |
299 | { | |
300 | in_getaddr(addr, DSTADDR); | |
301 | setipdst++; | |
302 | clearaddr = 0; | |
303 | newaddr = 0; | |
304 | } | |
305 | #define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr)) | |
306 | /*ARGSUSED*/ | |
307 | notealias(addr, param) | |
308 | char *addr; | |
309 | { | |
310 | if (setaddr && doalias == 0 && param < 0) | |
311 | bcopy((caddr_t)rqtosa(af_addreq), | |
312 | (caddr_t)rqtosa(af_ridreq), | |
313 | rqtosa(af_addreq)->sa_len); | |
314 | doalias = param; | |
315 | if (param < 0) { | |
316 | clearaddr = 1; | |
317 | newaddr = 0; | |
318 | } else | |
319 | clearaddr = 0; | |
320 | } | |
321 | ||
322 | /*ARGSUSED*/ | |
323 | setifdstaddr(addr, param) | |
324 | char *addr; | |
325 | int param; | |
326 | { | |
327 | (*afp->af_getaddr)(addr, DSTADDR); | |
328 | } | |
329 | ||
330 | setifflags(vname, value) | |
331 | char *vname; | |
332 | short value; | |
333 | { | |
334 | if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) { | |
335 | Perror("ioctl (SIOCGIFFLAGS)"); | |
336 | exit(1); | |
337 | } | |
338 | strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); | |
339 | flags = ifr.ifr_flags; | |
340 | ||
341 | if (value < 0) { | |
342 | value = -value; | |
343 | flags &= ~value; | |
344 | } else | |
345 | flags |= value; | |
346 | ifr.ifr_flags = flags; | |
347 | if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) | |
348 | Perror(vname); | |
349 | } | |
350 | ||
351 | setifmetric(val) | |
352 | char *val; | |
353 | { | |
354 | strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); | |
355 | ifr.ifr_metric = atoi(val); | |
356 | if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0) | |
357 | perror("ioctl (set metric)"); | |
358 | } | |
359 | ||
360 | setsnpaoffset(val) | |
361 | char *val; | |
362 | { | |
363 | #ifdef EON | |
364 | iso_addreq.ifra_snpaoffset = atoi(val); | |
365 | #endif | |
366 | } | |
367 | ||
368 | #define IFFBITS \ | |
369 | "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\ | |
370 | " | |
371 | ||
372 | /* | |
373 | * Print the status of the interface. If an address family was | |
374 | * specified, show it and it only; otherwise, show them all. | |
375 | */ | |
376 | status() | |
377 | { | |
378 | register struct afswtch *p = afp; | |
379 | short af = ifr.ifr_addr.sa_family; | |
380 | ||
381 | printf("%s: ", name); | |
382 | printb("flags", flags, IFFBITS); | |
383 | if (metric) | |
384 | printf(" metric %d", metric); | |
385 | putchar('\n'); | |
386 | if ((p = afp) != NULL) { | |
387 | (*p->af_status)(1); | |
388 | } else for (p = afs; p->af_name; p++) { | |
389 | ifr.ifr_addr.sa_family = p->af_af; | |
390 | (*p->af_status)(0); | |
391 | } | |
392 | } | |
393 | ||
394 | in_status(force) | |
395 | int force; | |
396 | { | |
397 | struct sockaddr_in *sin; | |
398 | char *inet_ntoa(); | |
399 | ||
400 | strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); | |
401 | if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) { | |
402 | if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) { | |
403 | if (!force) | |
404 | return; | |
405 | bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr)); | |
406 | } else | |
407 | perror("ioctl (SIOCGIFADDR)"); | |
408 | } | |
409 | sin = (struct sockaddr_in *)&ifr.ifr_addr; | |
410 | printf("\tinet %s ", inet_ntoa(sin->sin_addr)); | |
411 | strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); | |
412 | if (ioctl(s, SIOCGIFNETMASK, (caddr_t)&ifr) < 0) { | |
413 | if (errno != EADDRNOTAVAIL) | |
414 | perror("ioctl (SIOCGIFNETMASK)"); | |
415 | bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr)); | |
416 | } else | |
417 | netmask.sin_addr = | |
418 | ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr; | |
419 | if (flags & IFF_POINTOPOINT) { | |
420 | if (ioctl(s, SIOCGIFDSTADDR, (caddr_t)&ifr) < 0) { | |
421 | if (errno == EADDRNOTAVAIL) | |
422 | bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr)); | |
423 | else | |
424 | perror("ioctl (SIOCGIFDSTADDR)"); | |
425 | } | |
426 | strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); | |
427 | sin = (struct sockaddr_in *)&ifr.ifr_dstaddr; | |
428 | printf("--> %s ", inet_ntoa(sin->sin_addr)); | |
429 | } | |
430 | printf("netmask %x ", ntohl(netmask.sin_addr.s_addr)); | |
431 | if (flags & IFF_BROADCAST) { | |
432 | if (ioctl(s, SIOCGIFBRDADDR, (caddr_t)&ifr) < 0) { | |
433 | if (errno == EADDRNOTAVAIL) | |
434 | bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr)); | |
435 | else | |
436 | perror("ioctl (SIOCGIFADDR)"); | |
437 | } | |
438 | strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); | |
439 | sin = (struct sockaddr_in *)&ifr.ifr_addr; | |
440 | if (sin->sin_addr.s_addr != 0) | |
441 | printf("broadcast %s", inet_ntoa(sin->sin_addr)); | |
442 | } | |
443 | putchar('\n'); | |
444 | } | |
445 | ||
446 | #ifdef NSIP | |
447 | ||
448 | xns_status(force) | |
449 | int force; | |
450 | { | |
451 | struct sockaddr_ns *sns; | |
452 | ||
453 | close(s); | |
454 | s = socket(AF_NS, SOCK_DGRAM, 0); | |
455 | if (s < 0) { | |
456 | if (errno == EPROTONOSUPPORT) | |
457 | return; | |
458 | perror("ifconfig: socket"); | |
459 | exit(1); | |
460 | } | |
461 | if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) { | |
462 | if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) { | |
463 | if (!force) | |
464 | return; | |
465 | bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr)); | |
466 | } else | |
467 | perror("ioctl (SIOCGIFADDR)"); | |
468 | } | |
469 | strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); | |
470 | sns = (struct sockaddr_ns *)&ifr.ifr_addr; | |
471 | printf("\tns %s ", ns_ntoa(sns->sns_addr)); | |
472 | if (flags & IFF_POINTOPOINT) { /* by W. Nesheim@Cornell */ | |
473 | if (ioctl(s, SIOCGIFDSTADDR, (caddr_t)&ifr) < 0) { | |
474 | if (errno == EADDRNOTAVAIL) | |
475 | bzero((char *)&ifr.ifr_addr, sizeof(ifr.ifr_addr)); | |
476 | else | |
477 | Perror("ioctl (SIOCGIFDSTADDR)"); | |
478 | } | |
479 | strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); | |
480 | sns = (struct sockaddr_ns *)&ifr.ifr_dstaddr; | |
481 | printf("--> %s ", ns_ntoa(sns->sns_addr)); | |
482 | } | |
483 | putchar('\n'); | |
484 | } | |
485 | ||
486 | #endif | |
487 | #ifdef EON | |
488 | iso_status(force) | |
489 | int force; | |
490 | { | |
491 | struct sockaddr_iso *siso; | |
492 | struct iso_ifreq ifr; | |
493 | ||
494 | close(s); | |
495 | s = socket(AF_ISO, SOCK_DGRAM, 0); | |
496 | if (s < 0) { | |
497 | if (errno == EPROTONOSUPPORT) | |
498 | return; | |
499 | perror("ifconfig: socket"); | |
500 | exit(1); | |
501 | } | |
502 | bzero((caddr_t)&ifr, sizeof(ifr)); | |
503 | strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); | |
504 | if (ioctl(s, SIOCGIFADDR_ISO, (caddr_t)&ifr) < 0) { | |
505 | if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) { | |
506 | if (!force) | |
507 | return; | |
508 | bzero((char *)&ifr.ifr_Addr, sizeof(ifr.ifr_Addr)); | |
509 | } else { | |
510 | perror("ioctl (SIOCGIFADDR_ISO)"); | |
511 | exit(1); | |
512 | } | |
513 | } | |
514 | strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); | |
515 | siso = &ifr.ifr_Addr; | |
516 | printf("\tiso %s ", iso_ntoa(&siso->siso_addr)); | |
517 | if (ioctl(s, SIOCGIFNETMASK_ISO, (caddr_t)&ifr) < 0) { | |
518 | if (errno != EADDRNOTAVAIL) | |
519 | perror("ioctl (SIOCGIFNETMASK_ISO)"); | |
520 | } else { | |
521 | printf(" netmask %s ", iso_ntoa(&siso->siso_addr)); | |
522 | } | |
523 | if (flags & IFF_POINTOPOINT) { | |
524 | if (ioctl(s, SIOCGIFDSTADDR_ISO, (caddr_t)&ifr) < 0) { | |
525 | if (errno == EADDRNOTAVAIL) | |
526 | bzero((char *)&ifr.ifr_Addr, sizeof(ifr.ifr_Addr)); | |
527 | else | |
528 | Perror("ioctl (SIOCGIFDSTADDR_ISO)"); | |
529 | } | |
530 | strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); | |
531 | siso = &ifr.ifr_Addr; | |
532 | printf("--> %s ", iso_ntoa(&siso->siso_addr)); | |
533 | } | |
534 | putchar('\n'); | |
535 | } | |
536 | #endif | |
537 | ||
538 | Perror(cmd) | |
539 | char *cmd; | |
540 | { | |
541 | extern int errno; | |
542 | ||
543 | fprintf(stderr, "ifconfig: "); | |
544 | switch (errno) { | |
545 | ||
546 | case ENXIO: | |
547 | fprintf(stderr, "%s: no such interface\n", cmd); | |
548 | break; | |
549 | ||
550 | case EPERM: | |
551 | fprintf(stderr, "%s: permission denied\n", cmd); | |
552 | break; | |
553 | ||
554 | default: | |
555 | perror(cmd); | |
556 | } | |
557 | exit(1); | |
558 | } | |
559 | ||
560 | struct in_addr inet_makeaddr(); | |
561 | ||
562 | #define SIN(x) ((struct sockaddr_in *) &(x)) | |
563 | struct sockaddr_in *sintab[] = { | |
564 | SIN(ridreq.ifr_addr), SIN(addreq.ifra_addr), | |
565 | SIN(addreq.ifra_mask), SIN(addreq.ifra_broadaddr)}; | |
566 | ||
567 | in_getaddr(s, which) | |
568 | char *s; | |
569 | { | |
570 | register struct sockaddr_in *sin = sintab[which]; | |
571 | struct hostent *hp; | |
572 | struct netent *np; | |
573 | int val; | |
574 | ||
575 | sin->sin_len = sizeof(*sin); | |
576 | if (which != MASK) | |
577 | sin->sin_family = AF_INET; | |
578 | ||
579 | if ((val = inet_addr(s)) != -1) | |
580 | sin->sin_addr.s_addr = val; | |
581 | else if (hp = gethostbyname(s)) | |
582 | bcopy(hp->h_addr, (char *)&sin->sin_addr, hp->h_length); | |
583 | else if (np = getnetbyname(s)) | |
584 | sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY); | |
585 | else { | |
586 | fprintf(stderr, "%s: bad value\n", s); | |
587 | exit(1); | |
588 | } | |
589 | } | |
590 | ||
591 | /* | |
592 | * Print a value a la the %b format of the kernel's printf | |
593 | */ | |
594 | printb(s, v, bits) | |
595 | char *s; | |
596 | register char *bits; | |
597 | register unsigned short v; | |
598 | { | |
599 | register int i, any = 0; | |
600 | register char c; | |
601 | ||
602 | if (bits && *bits == 8) | |
603 | printf("%s=%o", s, v); | |
604 | else | |
605 | printf("%s=%x", s, v); | |
606 | bits++; | |
607 | if (bits) { | |
608 | putchar('<'); | |
609 | while (i = *bits++) { | |
610 | if (v & (1 << (i-1))) { | |
611 | if (any) | |
612 | putchar(','); | |
613 | any = 1; | |
614 | for (; (c = *bits) > 32; bits++) | |
615 | putchar(c); | |
616 | } else | |
617 | for (; *bits > 32; bits++) | |
618 | ; | |
619 | } | |
620 | putchar('>'); | |
621 | } | |
622 | } | |
623 | #ifdef NSIP | |
624 | ||
625 | #define SNS(x) ((struct sockaddr_ns *) &(x)) | |
626 | struct sockaddr_ns *snstab[] = { | |
627 | SNS(ridreq.ifr_addr), SNS(addreq.ifra_addr), | |
628 | SNS(addreq.ifra_mask), SNS(addreq.ifra_broadaddr)}; | |
629 | ||
630 | xns_getaddr(addr, which) | |
631 | char *addr; | |
632 | { | |
633 | struct sockaddr_ns *sns = snstab[which]; | |
634 | struct ns_addr ns_addr(); | |
635 | ||
636 | sns->sns_family = AF_NS; | |
637 | sns->sns_len = sizeof(*sns); | |
638 | sns->sns_addr = ns_addr(addr); | |
639 | if (which == MASK) | |
640 | printf("Attempt to set XNS netmask will be ineffectual\n"); | |
641 | } | |
642 | ||
643 | #endif | |
644 | #ifdef EON | |
645 | #define SISO(x) ((struct sockaddr_iso *) &(x)) | |
646 | struct sockaddr_iso *sisotab[] = { | |
647 | SISO(iso_ridreq.ifr_Addr), SISO(iso_addreq.ifra_addr), | |
648 | SISO(iso_addreq.ifra_mask), SISO(iso_addreq.ifra_dstaddr)}; | |
649 | ||
650 | iso_getaddr(addr, which) | |
651 | char *addr; | |
652 | { | |
653 | register struct sockaddr_iso *siso = sisotab[which]; | |
654 | struct iso_addr *iso_addr(); | |
655 | siso->siso_addr = *iso_addr(addr); | |
656 | ||
657 | if (which == MASK) { | |
658 | siso->siso_len = TSEL(siso) - (caddr_t)(siso); | |
659 | siso->siso_nlen = 0; | |
660 | } else { | |
661 | siso->siso_len = sizeof(*siso); | |
662 | siso->siso_family = AF_ISO; | |
663 | } | |
664 | } | |
665 | #endif | |
666 | ||
667 | setnsellength(val) | |
668 | char *val; | |
669 | { | |
670 | nsellength = atoi(val); | |
671 | if (nsellength < 0) { | |
672 | fprintf(stderr, "Negative NSEL length is absurd\n"); | |
673 | exit (1); | |
674 | } | |
675 | if (afp == 0 || afp->af_af != AF_ISO) { | |
676 | fprintf(stderr, "Setting NSEL length valid only for iso\n"); | |
677 | exit (1); | |
678 | } | |
679 | } | |
680 | ||
681 | #ifdef notdef | |
682 | fixnsel(s) | |
683 | register struct sockaddr_iso *s; | |
684 | { | |
685 | if (s->siso_family == 0) | |
686 | return; | |
687 | s->siso_tlen = nsellength; | |
688 | } | |
689 | #endif | |
690 | ||
691 | adjust_nsellength() | |
692 | { | |
693 | #ifdef notdef | |
694 | fixnsel(sisotab[RIDADDR]); | |
695 | fixnsel(sisotab[ADDR]); | |
696 | fixnsel(sisotab[DSTADDR]); | |
697 | #endif | |
698 | } |