diff options
author | rsc <devnull@localhost> | 2005-12-31 19:50:32 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-12-31 19:50:32 +0000 |
commit | 51b2002482faac9a8d4a8ebde27562ff64cd55fd (patch) | |
tree | c15cfbc1b4e694ab095477abd94c0893d5cf2c7b /src/libip | |
parent | 07683d0ef7798fdf4289ad1f9496a824f4178362 (diff) | |
download | plan9port-51b2002482faac9a8d4a8ebde27562ff64cd55fd.tar.gz plan9port-51b2002482faac9a8d4a8ebde27562ff64cd55fd.tar.bz2 plan9port-51b2002482faac9a8d4a8ebde27562ff64cd55fd.zip |
freebsd
Diffstat (limited to 'src/libip')
-rw-r--r-- | src/libip/FreeBSD.c | 36 | ||||
-rw-r--r-- | src/libip/mkfile | 5 | ||||
-rw-r--r-- | src/libip/testreadipifc.c | 1 |
3 files changed, 24 insertions, 18 deletions
diff --git a/src/libip/FreeBSD.c b/src/libip/FreeBSD.c index 71fb3ff3..2e35330d 100644 --- a/src/libip/FreeBSD.c +++ b/src/libip/FreeBSD.c @@ -32,8 +32,8 @@ sockaddr2ip(uchar *ip, struct sockaddr *sa) Ipifc* readipifc(char *net, Ipifc *ifc, int index) { - char *p, *ep, *q; - int i, mib[6], n, alloc; + char *p, *ep, *q, *bp; + int i, mib[6], n; Ipifc *list, **last; Iplifc *lifc, **lastlifc; struct if_msghdr *mh, *nmh; @@ -60,15 +60,18 @@ readipifc(char *net, Ipifc *ifc, int index) mib[4] = NET_RT_IFLIST; mib[5] = 0; + n = 0; if(sysctl(mib, 6, nil, &n, nil, 0) < 0) return nil; - p = mallocz(n, 1); - if(p == nil) + bp = mallocz(n, 1); + if(bp == nil) return nil; - if(sysctl(mib, 6, p, &n, nil, 0) < 0){ - free(p); + if(sysctl(mib, 6, bp, &n, nil, 0) < 0){ + free(bp); return nil; } + + p = bp; ep = p+n; while(p < ep){ mh = (struct if_msghdr*)p; @@ -89,30 +92,27 @@ readipifc(char *net, Ipifc *ifc, int index) ifc->rp.linkmtu = mh->ifm_data.ifi_mtu; lastlifc = &ifc->lifc; + if(sdl->sdl_type == IFT_ETHER && sdl->sdl_alen == 6) + memmove(ifc->ether, LLADDR(sdl), 6); + while(p < ep){ ah = (struct ifa_msghdr*)p; nmh = (struct if_msghdr*)p; if(nmh->ifm_type != RTM_NEWADDR) break; p += nmh->ifm_msglen; - alloc = 0; + lifc = nil; for(i=0, q=(char*)(ah+1); i<RTAX_MAX && q<p; i++){ if(!(ah->ifam_addrs & (1<<i))) continue; sa = (struct sockaddr*)q; q += (sa->sa_len+sizeof(long)-1) & ~(sizeof(long)-1); - - if(sa->sa_family == AF_LINK && i == RTAX_IFA){ - struct sockaddr_dl *e; - - if(e->sdl_type == IFT_ETHER && e->sdl_alen == 6) - memmove(ifc->ether, LLADDR(e), 6); - } if(sa->sa_family != AF_INET) continue; - if(alloc == 0){ - alloc = 1; + if(lifc == nil){ lifc = mallocz(sizeof *lifc, 1); + if(lifc == nil) + continue; *lastlifc = lifc; lastlifc = &lifc->next; } @@ -137,8 +137,10 @@ readipifc(char *net, Ipifc *ifc, int index) break; } } - maskip(lifc->ip, lifc->mask, lifc->net); + if(lifc) + maskip(lifc->ip, lifc->mask, lifc->net); } } + free(bp); return list; } diff --git a/src/libip/mkfile b/src/libip/mkfile index 35399d71..6f8ad2f8 100644 --- a/src/libip/mkfile +++ b/src/libip/mkfile @@ -18,3 +18,8 @@ HFILES=\ ip.h <$PLAN9/src/mksyslib + +testreadipifc: testreadipifc.o $LIBDIR/$LIB + $LD -o testreadipifc testreadipifc.o + + diff --git a/src/libip/testreadipifc.c b/src/libip/testreadipifc.c index 3515e7f2..1282f3b7 100644 --- a/src/libip/testreadipifc.c +++ b/src/libip/testreadipifc.c @@ -7,7 +7,6 @@ main(void) { Ipifc *ifc, *list; Iplifc *lifc; - int i; fmtinstall('I', eipfmt); fmtinstall('M', eipfmt); |