tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / net / if.c
blob5727b8c0d1f1e46b235acec47ae9deb38ce07727
1 /*
2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
4 * All rights reserved.
5 * Copyright (C) 2005 - 2007 The AROS Dev Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
24 * Copyright (c) 1980, 1986 Regents of the University of California.
25 * All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
55 * @(#)if.c 7.14 (Berkeley) 4/20/91
58 #include "conf.h"
60 #include <dos/rdargs.h>
61 #include <net/route.h>
63 #include <sys/malloc.h>
64 #include <sys/mbuf.h>
65 #include <sys/systm.h>
66 #include <sys/socket.h>
67 #include <sys/socketvar.h>
68 #include <sys/protosw.h>
69 #include <sys/kernel.h>
70 #include <sys/sockio.h>
71 #include <sys/synch.h>
73 #include <net/if.h>
74 #include <net/if_dl.h>
75 #include <netinet/in.h> /* for findid */
77 void ifinit(void);
78 void if_attach(struct ifnet *);
79 struct ifaddr *ifa_ifwithaddr(register struct sockaddr *);
80 struct ifaddr *ifa_ifwithdstaddr(register struct sockaddr *);
81 struct ifaddr *ifa_ifwithnet(struct sockaddr *);
82 struct ifaddr *ifa_ifwithaf(register int );
83 struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, register struct ifnet *);
84 void link_rtrequest(int, struct rtentry *, struct sockaddr *);
85 void if_down(register struct ifnet *);
86 void if_qflush(register struct ifqueue *);
87 void if_slowtimo(void);
88 struct ifnet *ifunit(register char *);
89 int ifioctl(struct socket *, long, caddr_t);
90 int ifconf(int, caddr_t);
92 /* Compatibility with AmiTCP/IP 2 */
93 #include <sys/a_ioctl.h>
94 #include <net/a_if.h>
95 struct ifnet *aifunit(register char *name);
96 int aifconf(int cmd, caddr_t data);
98 #include <kern/uipc_domain_protos.h>
100 static char *sprint_d(u_int n, char *buf, int buflen);
101 int ifqmaxlen = IFQ_MAXLEN;
103 struct ifnet *ifnet = NULL;
106 * Network interface utility routines.
108 * Routines with ifa_ifwith* names take sockaddr *'s as
109 * parameters.
112 void ifinit(void)
114 register struct ifnet *ifp;
116 for (ifp = ifnet; ifp; ifp = ifp->if_next)
117 if (ifp->if_snd.ifq_maxlen == 0)
118 ifp->if_snd.ifq_maxlen = ifqmaxlen;
119 if_slowtimo();
122 #ifdef vax
124 * Call each interface on a Unibus reset.
126 ifubareset(uban)
127 int uban;
129 register struct ifnet *ifp;
131 for (ifp = ifnet; ifp; ifp = ifp->if_next)
132 if (ifp->if_reset)
133 (*ifp->if_reset)(ifp->if_unit, uban);
135 #endif
137 int if_index = 0;
138 struct ifaddr **ifnet_addrs;
141 * Attach an interface to the
142 * list of "active" interfaces.
144 void
145 if_attach(ifp)
146 struct ifnet *ifp;
148 unsigned socksize, ifasize;
149 int namelen, unitlen;
150 char workbuf[12], *unitname;
151 register struct sockaddr_dl *sdl;
152 register struct ifaddr *ifa;
153 static int if_indexlim = 8;
154 register struct ifnet **p = &ifnet;
156 while (*p)
157 p = &((*p)->if_next);
158 *p = ifp;
159 ifp->if_index = ++if_index;
160 if (ifnet_addrs == 0 || if_index >= if_indexlim) {
161 unsigned n = (if_indexlim <<= 1) * sizeof(ifa);
162 struct ifaddr **q = (struct ifaddr **)
163 bsd_malloc(n, M_IFADDR, M_WAITOK);
164 if (ifnet_addrs) {
165 aligned_bcopy((caddr_t)ifnet_addrs, (caddr_t)q, n/2);
166 bsd_free((caddr_t)ifnet_addrs, M_IFADDR);
168 ifnet_addrs = q;
171 * create a Link Level name for this device
173 unitname = sprint_d((u_int)ifp->if_unit, workbuf, sizeof(workbuf));
174 namelen = strlen(ifp->if_name);
175 unitlen = strlen(unitname);
176 #define _offsetof(t, m) ((IPTR)((caddr_t)&((t *)0)->m))
177 socksize = _offsetof(struct sockaddr_dl, sdl_data[0]) +
178 unitlen + namelen + ifp->if_addrlen;
179 #define ROUNDUP(a) (1 + (((a) - 1) | (sizeof(long) - 1)))
180 socksize = ROUNDUP(socksize);
181 if (socksize < sizeof(*sdl))
182 socksize = sizeof(*sdl);
183 ifasize = sizeof(*ifa) + 2 * socksize;
184 ifa = (struct ifaddr *)bsd_malloc(ifasize, M_IFADDR, M_WAITOK);
185 if (ifa == 0)
186 return;
187 ifnet_addrs[if_index - 1] = ifa;
188 aligned_bzero((caddr_t)ifa, ifasize);
189 sdl = (struct sockaddr_dl *)(ifa + 1);
190 ifa->ifa_addr = (struct sockaddr *)sdl;
191 ifa->ifa_ifp = ifp;
192 sdl->sdl_len = socksize;
193 sdl->sdl_family = AF_LINK;
194 bcopy(ifp->if_name, sdl->sdl_data, namelen);
195 bcopy(unitname, namelen + (caddr_t)sdl->sdl_data, unitlen);
196 sdl->sdl_nlen = (namelen += unitlen);
197 sdl->sdl_index = ifp->if_index;
198 /* Fill in the hardware address */
199 sdl->sdl_type = ifp->if_type;
200 sdl->sdl_alen = ifp->if_addrlen;
201 if ((ifp->if_output == sana_output) && (sdl->sdl_alen))
202 bcopy((caddr_t)((struct sana_softc *)ifp)->ss_hwaddr,LLADDR(sdl), sdl->sdl_alen);
203 sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl);
204 ifa->ifa_netmask = (struct sockaddr *)sdl;
205 sdl->sdl_len = socksize - ifp->if_addrlen;
206 while (namelen != 0)
207 sdl->sdl_data[--namelen] = (char)0xff;
208 ifa->ifa_next = ifp->if_addrlist;
209 ifa->ifa_rtrequest = link_rtrequest;
210 ifp->if_addrlist = ifa;
214 * Locate an interface based on a complete address.
218 * Find an interface address suitable for host id. If no suitable interface
219 * address is found, the *id is not touched.
221 * This routine stops after the first non-loopback AF_INET address is found.
223 * This routine is specially made for the gethostid() system call.
225 void
226 findid(unsigned long *id)
228 struct ifnet *ifp;
229 struct ifaddr *ifa;
231 spl_t s = splimp();
233 for (ifp = ifnet; ifp; ifp = ifp->if_next)
234 if (ifp->if_flags & IFF_UP)
235 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
236 if (ifa->ifa_addr->sa_family == AF_INET) {
237 *id = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
238 if (!(ifp->if_flags & IFF_LOOPBACK))
239 goto ret;
241 ret:
242 splx(s);
245 /*ARGSUSED*/
246 struct ifaddr *
247 ifa_ifwithaddr(addr)
248 register struct sockaddr *addr;
250 register struct ifnet *ifp;
251 register struct ifaddr *ifa;
253 #define equal(a1, a2) \
254 (bcmp((caddr_t)(a1), (caddr_t)(a2), ((struct sockaddr *)(a1))->sa_len) == 0)
255 for (ifp = ifnet; ifp; ifp = ifp->if_next)
256 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
257 if (ifa->ifa_addr->sa_family != addr->sa_family)
258 continue;
259 if (equal(addr, ifa->ifa_addr))
260 return (ifa);
261 if ((ifp->if_flags & IFF_BROADCAST) && ifa->ifa_broadaddr &&
262 equal(ifa->ifa_broadaddr, addr))
263 return (ifa);
265 return ((struct ifaddr *)0);
268 * Locate the point to point interface with a given destination address.
270 /*ARGSUSED*/
271 struct ifaddr *
272 ifa_ifwithdstaddr(addr)
273 register struct sockaddr *addr;
275 register struct ifnet *ifp;
276 register struct ifaddr *ifa;
278 for (ifp = ifnet; ifp; ifp = ifp->if_next)
279 if (ifp->if_flags & IFF_POINTOPOINT)
280 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
281 if (ifa->ifa_addr->sa_family != addr->sa_family)
282 continue;
283 if (equal(addr, ifa->ifa_dstaddr))
284 return (ifa);
286 return ((struct ifaddr *)0);
290 * Find an interface on a specific network. If many, choice
291 * is first found.
293 struct ifaddr *
294 ifa_ifwithnet(addr)
295 struct sockaddr *addr;
297 register struct ifnet *ifp;
298 register struct ifaddr *ifa;
299 u_int af = addr->sa_family;
301 if (af >= AF_MAX)
302 return (0);
303 if (af == AF_LINK) {
304 register struct sockaddr_dl *sdl = (struct sockaddr_dl *)addr;
305 if (sdl->sdl_index && sdl->sdl_index <= if_index)
306 return (ifnet_addrs[sdl->sdl_index - 1]);
308 for (ifp = ifnet; ifp; ifp = ifp->if_next)
309 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
310 register char *cp, *cp2, *cp3;
311 register char *cplim;
312 if (ifa->ifa_addr->sa_family != af || ifa->ifa_netmask == 0)
313 continue;
314 cp = addr->sa_data;
315 cp2 = ifa->ifa_addr->sa_data;
316 cp3 = ifa->ifa_netmask->sa_data;
317 cplim = ifa->ifa_netmask->sa_len + (char *)ifa->ifa_netmask;
318 for (; cp3 < cplim; cp3++)
319 if ((*cp++ ^ *cp2++) & *cp3)
320 break;
321 if (cp3 == cplim)
322 return (ifa);
324 return ((struct ifaddr *)0);
328 * Find an interface using a specific address family
330 struct ifaddr *
331 ifa_ifwithaf(af)
332 register int af;
334 register struct ifnet *ifp;
335 register struct ifaddr *ifa;
337 for (ifp = ifnet; ifp; ifp = ifp->if_next)
338 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
339 if (ifa->ifa_addr->sa_family == af)
340 return (ifa);
341 return ((struct ifaddr *)0);
345 * Find an interface address specific to an interface best matching
346 * a given address.
348 struct ifaddr *
349 ifaof_ifpforaddr(addr, ifp)
350 struct sockaddr *addr;
351 register struct ifnet *ifp;
353 register struct ifaddr *ifa;
354 register char *cp, *cp2, *cp3;
355 register char *cplim;
356 struct ifaddr *ifa_maybe = 0;
357 u_int af = addr->sa_family;
359 if (af >= AF_MAX)
360 return (0);
361 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
362 if (ifa->ifa_addr->sa_family != af)
363 continue;
364 ifa_maybe = ifa;
365 if (ifa->ifa_netmask == 0) {
366 if (equal(addr, ifa->ifa_addr) ||
367 (ifa->ifa_dstaddr && equal(addr, ifa->ifa_dstaddr)))
368 return (ifa);
369 continue;
371 cp = addr->sa_data;
372 cp2 = ifa->ifa_addr->sa_data;
373 cp3 = ifa->ifa_netmask->sa_data;
374 cplim = ifa->ifa_netmask->sa_len + (char *)ifa->ifa_netmask;
375 for (; cp3 < cplim; cp3++)
376 if ((*cp++ ^ *cp2++) & *cp3)
377 break;
378 if (cp3 == cplim)
379 return (ifa);
381 return (ifa_maybe);
384 #include <net/route.h>
387 * Default action when installing a route with a Link Level gateway.
388 * Lookup an appropriate real ifa to point to.
389 * This should be moved to /sys/net/link.c eventually.
391 void
392 link_rtrequest(int cmd, struct rtentry *rt, struct sockaddr *sa)
394 register struct ifaddr *ifa;
395 struct sockaddr *dst;
396 struct ifnet *ifp;
398 if (cmd != RTM_ADD || ((ifa = rt->rt_ifa) == 0) ||
399 ((ifp = ifa->ifa_ifp) == 0) || ((dst = rt_key(rt)) == 0))
400 return;
401 if (ifa = ifaof_ifpforaddr(dst, ifp)) {
402 rt->rt_ifa = ifa;
403 if (ifa->ifa_rtrequest &&
404 ifa->ifa_rtrequest != link_rtrequest)
405 ifa->ifa_rtrequest(cmd, rt, sa);
410 * Mark an interface down and notify protocols of
411 * the transition.
412 * NOTE: must be called at splnet or eqivalent.
414 void
415 if_down(ifp)
416 register struct ifnet *ifp;
418 register struct ifaddr *ifa;
420 ifp->if_flags &= ~IFF_UP;
421 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
422 pfctlinput(PRC_IFDOWN, ifa->ifa_addr);
423 if_qflush(&ifp->if_snd);
427 * Flush an interface queue.
429 void
430 if_qflush(ifq)
431 register struct ifqueue *ifq;
433 register struct mbuf *m, *n;
435 n = ifq->ifq_head;
436 while (m = n) {
437 n = m->m_act;
438 m_freem(m);
440 ifq->ifq_head = 0;
441 ifq->ifq_tail = 0;
442 ifq->ifq_len = 0;
446 * Handle interface watchdog timer routines. Called
447 * from softclock, we decrement timers (if set) and
448 * call the appropriate interface routine on expiration.
450 void
451 if_slowtimo()
454 * This routine is disabled since there are
455 * no timeouts in our network interfaces
457 #ifndef AMITCP
458 register struct ifnet *ifp;
459 spl_t s = splimp();
461 for (ifp = ifnet; ifp; ifp = ifp->if_next) {
462 if (ifp->if_timer == 0 || --ifp->if_timer)
463 continue;
464 if (ifp->if_watchdog)
465 (*ifp->if_watchdog)(ifp->if_unit);
467 splx(s);
468 #ifndef AMITCP
470 * Timeouts are scheduled from amiga_time.c in AmiTCP/IP.
472 timeout(if_slowtimo, (caddr_t)0, hz / IFNET_SLOWHZ);
473 #endif
474 #endif
478 * Map interface name to
479 * interface structure pointer.
481 struct ifnet *
482 ifunit(char *name)
484 register struct ifnet *ifp;
485 register char *cp;
486 int unit;
487 unsigned len;
488 char *ep, c;
490 for (cp = name; cp < name + IFNAMSIZ && *cp; cp++)
491 if (*cp >= '0' && *cp <= '9')
492 break;
493 if (*cp == '\0' || cp == name + IFNAMSIZ)
494 return ((struct ifnet *)0);
496 * Save first char of unit, and pointer to it,
497 * so we can put a null there to avoid matching
498 * initial substrings of interface names.
500 len = cp - name + 1;
501 c = *cp;
502 ep = cp;
503 for (unit = 0; *cp >= '0' && *cp <= '9'; )
504 unit = unit * 10 + *cp++ - '0';
505 *ep = 0;
507 for (ifp = ifnet; ifp; ifp = ifp->if_next) {
508 if (bcmp(ifp->if_name, name, len))
509 continue;
510 if (unit == ifp->if_unit)
511 break;
513 *ep = c;
514 return (ifp);
518 * Interface ioctls.
521 ifioctl(so, cmd, data)
522 struct socket *so;
523 long cmd;
524 caddr_t data;
526 register struct ifnet *ifp;
527 register struct ifreq *ifr;
528 #ifndef AMITCP
529 int error;
530 #endif
531 extern int arpioctl(int cmd, caddr_t data);
533 switch (cmd) {
535 case SIOCGIFCONF:
536 return (ifconf(cmd, data));
538 #ifdef COMPAT_AMITCP2
539 case ASIOCGIFCONF:
540 return (aifconf(cmd, data));
541 #endif
543 #if INET && NETHER > 0
544 case SIOCSARP:
545 case SIOCDARP:
546 #ifndef AMITCP /* no protection on AmigaOS */
547 if (error = suser(p->p_ucred, &p->p_acflag))
548 return (error);
549 /* FALL THROUGH */
550 #else
551 case SIOCGARPT:
552 #endif /* AMITCP */
553 case SIOCGARP:
554 return (arpioctl(cmd, data));
555 #endif
558 #ifndef COMPAT_AMITCP2
559 /* Do we have old ioctl? */
560 if (IOCGROUP(cmd) == 'I') {
561 struct aifreq *aifr;
562 aifr = (struct aifreq *)data;
563 /* Nobody needs interface name after we have got ifp */
564 ifp = aifunit(aifr->ifr_name);
565 ifr = (struct ifreq *)(data + AIFNAMSIZ - IFNAMSIZ);
566 cmd -= ASIOCSIFADDR - SIOCSIFADDR;
568 else
569 #endif
571 ifr = (struct ifreq *)data;
572 ifp = ifunit(ifr->ifr_name);
575 if (ifp == 0)
576 return (ENXIO);
577 switch (cmd) {
579 case SIOCGIFINDEX:
580 ifr->ifr_index = ifp->if_index;
581 break;
583 case SIOCGIFFLAGS:
584 ifr->ifr_flags = ifp->if_flags;
585 break;
587 case SIOCGIFMETRIC:
588 ifr->ifr_metric = ifp->if_metric;
589 break;
591 case SIOCGIFMTU:
592 ifr->ifr_mtu = ifp->if_mtu;
593 break;
595 case SIOCSIFFLAGS:
596 /* if_down() is kludged for Sana-II driver ioctl */
597 if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) {
598 spl_t s = splimp();
599 if_down(ifp);
600 splx(s);
603 if (ifp->if_ioctl)
604 (void) (*ifp->if_ioctl)(ifp, cmd, data);
606 ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) |
607 (ifr->ifr_flags &~ IFF_CANTCHANGE);
608 break;
610 case SIOCSIFMETRIC:
611 #ifndef AMITCP /* no protection on AmigaOS */
612 if (error = suser(p->p_ucred, &p->p_acflag))
613 return (error);
614 #endif /* AMITCP */
615 ifp->if_metric = ifr->ifr_metric;
616 break;
618 default:
619 if (so->so_proto == 0)
620 return (EOPNOTSUPP);
621 return ((*so->so_proto->pr_usrreq)(so,
622 PRU_CONTROL,
623 (struct mbuf *)cmd,
624 (struct mbuf *)ifr,
625 (struct mbuf *)ifp));
627 return (0);
631 * A helper routine for internal interface control
632 * Here we do the same as SIOCSIFFLAGS processing code from net/if.c
635 void ifupdown(struct ifnet *ifp, int up) {
636 struct ifreq ifr;
638 if (up) {
639 ifr.ifr_flags = ifp->if_flags & ~IFF_UP;
640 if (ifp->if_flags & IFF_UP) {
641 spl_t s = splimp();
642 if_down(ifp);
643 splx(s);
645 } else {
646 ifr.ifr_flags = ifp->if_flags | IFF_UP;
648 if (ifp->if_ioctl)
649 (void) (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr);
650 ifp->if_flags = ifr.ifr_flags;
654 * Return interface configuration
655 * of system. List may be used
656 * in later ioctl's (above) to get
657 * other information.
660 ifconf(cmd, data)
661 int cmd;
662 caddr_t data;
664 register struct ifconf *ifc = (struct ifconf *)data;
665 register struct ifnet *ifp = ifnet;
666 register struct ifaddr *ifa;
667 register char *cp, *ep;
668 struct ifreq ifr, *ifrp;
669 int space = ifc->ifc_len, error = 0;
671 ifrp = ifc->ifc_req;
672 #ifndef AMITCP
673 ep = ifr.ifr_name + sizeof (ifr.ifr_name) - 2;
674 #endif
675 for (; space > sizeof (ifr) && ifp; ifp = ifp->if_next) {
676 #ifdef AMITCP
677 ep = sprint_d(ifp->if_unit, ifr.ifr_name, sizeof(ifr.ifr_name));
678 /* Copy the interface name into ifr */
679 bcopy(ifp->if_name, ifr.ifr_name, ep - ifr.ifr_name);
680 /* Find the end of interface name */
681 for (cp = ifr.ifr_name; cp < ep && *cp; cp++)
683 /* Append unit number to it */
684 for (; *cp = *ep; cp++, ep++)
686 #else
687 bcopy(ifp->if_name, ifr.ifr_name, sizeof (ifr.ifr_name) - 2);
688 for (cp = ifr.ifr_name; cp < ep && *cp; cp++)
690 *cp++ = '0' + ifp->if_unit; *cp = '\0';
691 #endif
692 if ((ifa = ifp->if_addrlist) == 0) {
693 aligned_bzero_const((caddr_t)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
694 bcopy(&ifr, ifrp, sizeof(ifr));
695 space -= sizeof (ifr), ifrp++;
696 } else
697 for ( ; space > sizeof (ifr) && ifa; ifa = ifa->ifa_next) {
698 register struct sockaddr *sa = ifa->ifa_addr;
699 #ifdef COMPAT_43
700 if (cmd == OSIOCGIFCONF) {
701 struct osockaddr *osa =
702 (struct osockaddr *)&ifr.ifr_addr;
703 ifr.ifr_addr = *sa;
704 osa->sa_family = sa->sa_family;
705 error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
706 sizeof (ifr));
707 ifrp++;
708 } else
709 #endif
710 if (sa->sa_len <= sizeof(*sa)) {
711 ifr.ifr_addr = *sa;
712 bcopy(&ifr, ifrp, sizeof(ifr));
713 ifrp++;
714 } else {
715 space -= sa->sa_len - sizeof(*sa);
716 if (space < sizeof (ifr))
717 break;
718 #ifdef AMITCP
719 aligned_bcopy_const((caddr_t)&ifr,
720 (caddr_t)ifrp,
721 sizeof (ifr.ifr_name));
722 aligned_bcopy((caddr_t)sa,
723 (caddr_t)&ifrp->ifr_addr, sa->sa_len);
724 #else
725 error = copyout((caddr_t)&ifr, (caddr_t)ifrp,
726 sizeof (ifr.ifr_name));
727 if (error == 0)
728 error = copyout((caddr_t)sa,
729 (caddr_t)&ifrp->ifr_addr, sa->sa_len);
730 #endif
731 ifrp = (struct ifreq *)
732 (sa->sa_len + (caddr_t)&ifrp->ifr_addr);
734 #ifndef AMITCP
735 if (error)
736 break;
737 #endif
738 space -= sizeof (ifr);
741 ifc->ifc_len -= space;
742 return (error);
745 int aifconf(int cmd, caddr_t data)
747 return ENOSYS;
750 static char *
751 sprint_d(n, buf, buflen)
752 u_int n;
753 char *buf;
754 int buflen;
756 register char *cp = buf + buflen - 1;
758 *cp = 0;
759 do {
760 cp--;
761 *cp = "0123456789"[n % 10];
762 n /= 10;
763 } while (n != 0);
764 return (cp);