use getifaddrs from libc instead of private code

Reviewed by:	bms
MFC after:	1 month
This commit is contained in:
Sam Leffler 2007-02-24 23:55:46 +00:00
parent 16d84e0140
commit cb8c905ae9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=166956
7 changed files with 116 additions and 195 deletions

View File

@ -36,7 +36,6 @@ static const char rcsid[] =
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <net/if.h> #include <net/if.h>
#include <net/route.h> /* for RTX_IFA */
#include <netatalk/at.h> #include <netatalk/at.h>
@ -45,6 +44,7 @@ static const char rcsid[] =
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <ifaddrs.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -81,32 +81,30 @@ setatphase(const char *phase, int dummy __unused, int s,
} }
static void static void
at_status(int s __unused, const struct rt_addrinfo * info) at_status(int s __unused, const struct ifaddrs *ifa)
{ {
struct sockaddr_at *sat, null_sat; struct sockaddr_at *sat, null_sat;
struct netrange *nr; struct netrange *nr;
memset(&null_sat, 0, sizeof(null_sat)); memset(&null_sat, 0, sizeof(null_sat));
sat = (struct sockaddr_at *)info->rti_info[RTAX_IFA]; sat = (struct sockaddr_at *)ifa->ifa_addr;
if (sat == NULL) if (sat == NULL)
return; return;
nr = &sat->sat_range.r_netrange; nr = &sat->sat_range.r_netrange;
printf("\tatalk %d.%d range %d-%d phase %d", printf("\tatalk %d.%d range %d-%d phase %d",
ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node, ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node,
ntohs(nr->nr_firstnet), ntohs(nr->nr_lastnet), nr->nr_phase); ntohs(nr->nr_firstnet), ntohs(nr->nr_lastnet), nr->nr_phase);
if (flags & IFF_POINTOPOINT) { if (ifa->ifa_flags & IFF_POINTOPOINT) {
/* note RTAX_BRD overlap with IFF_BROADCAST */ sat = (struct sockaddr_at *)ifa->ifa_dstaddr;
sat = (struct sockaddr_at *)info->rti_info[RTAX_BRD]; if (sat == NULL)
if (!sat)
sat = &null_sat; sat = &null_sat;
printf("--> %d.%d", printf("--> %d.%d",
ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node); ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node);
} }
if (flags & IFF_BROADCAST) { if (ifa->ifa_flags & IFF_BROADCAST) {
/* note RTAX_BRD overlap with IFF_POINTOPOINT */ sat = (struct sockaddr_at *)ifa->ifa_broadaddr;
sat = (struct sockaddr_at *)info->rti_info[RTAX_BRD]; if (sat != NULL)
if (sat)
printf(" broadcast %d.%d", printf(" broadcast %d.%d",
ntohs(sat->sat_addr.s_net), ntohs(sat->sat_addr.s_net),
sat->sat_addr.s_node); sat->sat_addr.s_node);

View File

@ -36,13 +36,13 @@ static const char rcsid[] =
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <net/if.h> #include <net/if.h>
#include <net/route.h> /* for RTX_IFA */
#include <err.h> #include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <ifaddrs.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/if_var.h> /* for struct ifaddr */ #include <net/if_var.h> /* for struct ifaddr */
@ -56,35 +56,33 @@ static struct ifaliasreq in_addreq;
static struct ifreq in_ridreq; static struct ifreq in_ridreq;
static void static void
in_status(int s __unused, const struct rt_addrinfo * info) in_status(int s __unused, const struct ifaddrs *ifa)
{ {
struct sockaddr_in *sin, null_sin; struct sockaddr_in *sin, null_sin;
memset(&null_sin, 0, sizeof(null_sin)); memset(&null_sin, 0, sizeof(null_sin));
sin = (struct sockaddr_in *)info->rti_info[RTAX_IFA]; sin = (struct sockaddr_in *)ifa->ifa_addr;
if (sin == NULL) if (sin == NULL)
return; return;
printf("\tinet %s ", inet_ntoa(sin->sin_addr)); printf("\tinet %s ", inet_ntoa(sin->sin_addr));
if (flags & IFF_POINTOPOINT) { if (ifa->ifa_flags & IFF_POINTOPOINT) {
/* note RTAX_BRD overlap with IFF_BROADCAST */ sin = (struct sockaddr_in *)ifa->ifa_dstaddr;
sin = (struct sockaddr_in *)info->rti_info[RTAX_BRD]; if (sin == NULL)
if (!sin)
sin = &null_sin; sin = &null_sin;
printf("--> %s ", inet_ntoa(sin->sin_addr)); printf("--> %s ", inet_ntoa(sin->sin_addr));
} }
sin = (struct sockaddr_in *)info->rti_info[RTAX_NETMASK]; sin = (struct sockaddr_in *)ifa->ifa_netmask;
if (!sin) if (sin == NULL)
sin = &null_sin; sin = &null_sin;
printf("netmask 0x%lx ", (unsigned long)ntohl(sin->sin_addr.s_addr)); printf("netmask 0x%lx ", (unsigned long)ntohl(sin->sin_addr.s_addr));
if (flags & IFF_BROADCAST) { if (ifa->ifa_flags & IFF_BROADCAST) {
/* note RTAX_BRD overlap with IFF_POINTOPOINT */ sin = (struct sockaddr_in *)ifa->ifa_broadaddr;
sin = (struct sockaddr_in *)info->rti_info[RTAX_BRD]; if (sin != NULL && sin->sin_addr.s_addr != 0)
if (sin && sin->sin_addr.s_addr != 0)
printf("broadcast %s", inet_ntoa(sin->sin_addr)); printf("broadcast %s", inet_ntoa(sin->sin_addr));
} }
putchar('\n'); putchar('\n');

View File

@ -36,7 +36,6 @@ static const char rcsid[] =
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <net/if.h> #include <net/if.h>
#include <net/route.h> /* for RTX_IFA */
#include <err.h> #include <err.h>
#include <stdio.h> #include <stdio.h>
@ -179,7 +178,7 @@ in6_fillscopeid(struct sockaddr_in6 *sin6)
} }
static void static void
in6_status(int s __unused, const struct rt_addrinfo * info) in6_status(int s __unused, const struct ifaddrs *ifa)
{ {
struct sockaddr_in6 *sin, null_sin; struct sockaddr_in6 *sin, null_sin;
struct in6_ifreq ifr6; struct in6_ifreq ifr6;
@ -192,7 +191,7 @@ in6_status(int s __unused, const struct rt_addrinfo * info)
memset(&null_sin, 0, sizeof(null_sin)); memset(&null_sin, 0, sizeof(null_sin));
sin = (struct sockaddr_in6 *)info->rti_info[RTAX_IFA]; sin = (struct sockaddr_in6 *)ifa->ifa_addr;
if (sin == NULL) if (sin == NULL)
return; return;
@ -237,14 +236,13 @@ in6_status(int s __unused, const struct rt_addrinfo * info)
sizeof(addr_buf)); sizeof(addr_buf));
printf("\tinet6 %s ", addr_buf); printf("\tinet6 %s ", addr_buf);
if (flags & IFF_POINTOPOINT) { if (ifa->ifa_flags & IFF_POINTOPOINT) {
/* note RTAX_BRD overlap with IFF_BROADCAST */ sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
sin = (struct sockaddr_in6 *)info->rti_info[RTAX_BRD];
/* /*
* some of the interfaces do not have valid destination * some of the interfaces do not have valid destination
* address. * address.
*/ */
if (sin && sin->sin6_family == AF_INET6) { if (sin != NULL && sin->sin6_family == AF_INET6) {
int error; int error;
/* XXX: embedded link local addr check */ /* XXX: embedded link local addr check */
@ -269,8 +267,8 @@ in6_status(int s __unused, const struct rt_addrinfo * info)
} }
} }
sin = (struct sockaddr_in6 *)info->rti_info[RTAX_NETMASK]; sin = (struct sockaddr_in6 *)ifa->ifa_netmask;
if (!sin) if (sin == NULL)
sin = &null_sin; sin = &null_sin;
printf("prefixlen %d ", prefix(&sin->sin6_addr, printf("prefixlen %d ", prefix(&sin->sin6_addr,
sizeof(struct in6_addr))); sizeof(struct in6_addr)));

View File

@ -36,12 +36,12 @@ static const char rcsid[] =
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <net/if.h> #include <net/if.h>
#include <net/route.h>
#include <err.h> #include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ifaddrs.h>
#include <net/if_var.h> #include <net/if_var.h>
#define IPXIP #define IPXIP
@ -55,19 +55,19 @@ static struct ifaliasreq ipx_addreq;
static struct ifreq ipx_ridreq; static struct ifreq ipx_ridreq;
static void static void
ipx_status(int s __unused, const struct rt_addrinfo * info) ipx_status(int s __unused, const struct ifaddrs *ifa)
{ {
struct sockaddr_ipx *sipx, null_sipx; struct sockaddr_ipx *sipx, null_sipx;
sipx = (struct sockaddr_ipx *)info->rti_info[RTAX_IFA]; sipx = (struct sockaddr_ipx *)ifa->ifa_addr;
if (sipx == NULL) if (sipx == NULL)
return; return;
printf("\tipx %s ", ipx_ntoa(sipx->sipx_addr)); printf("\tipx %s ", ipx_ntoa(sipx->sipx_addr));
if (flags & IFF_POINTOPOINT) { if (ifa->ifa_flags & IFF_POINTOPOINT) {
sipx = (struct sockaddr_ipx *)info->rti_info[RTAX_BRD]; sipx = (struct sockaddr_ipx *)ifa->ifa_broadaddr;
if (!sipx) { if (sipx == NULL) {
memset(&null_sipx, 0, sizeof(null_sipx)); memset(&null_sipx, 0, sizeof(null_sipx));
sipx = &null_sipx; sipx = &null_sipx;
} }

View File

@ -36,12 +36,12 @@ static const char rcsid[] =
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <net/if.h> #include <net/if.h>
#include <net/route.h> /* for RTX_IFA */
#include <err.h> #include <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ifaddrs.h>
#include <net/if_dl.h> #include <net/if_dl.h>
#include <net/if_types.h> #include <net/if_types.h>
@ -52,16 +52,16 @@ static const char rcsid[] =
static struct ifreq link_ridreq; static struct ifreq link_ridreq;
static void static void
link_status(int s __unused, const struct rt_addrinfo *info) link_status(int s __unused, const struct ifaddrs *ifa)
{ {
const struct sockaddr_dl *sdl = /* XXX no const 'cuz LLADDR is defined wrong */
(const struct sockaddr_dl *) info->rti_info[RTAX_IFA]; struct sockaddr_dl *sdl = (struct sockaddr_dl *) ifa->ifa_addr;
if (sdl != NULL && sdl->sdl_alen > 0) { if (sdl != NULL && sdl->sdl_alen > 0) {
if (sdl->sdl_type == IFT_ETHER && if (sdl->sdl_type == IFT_ETHER &&
sdl->sdl_alen == ETHER_ADDR_LEN) sdl->sdl_alen == ETHER_ADDR_LEN)
printf("\tether %s\n", printf("\tether %s\n",
ether_ntoa((const struct ether_addr *)LLADDR(sdl))); ether_ntoa((struct ether_addr *)LLADDR(sdl)));
else { else {
int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0; int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;

View File

@ -62,6 +62,7 @@ static const char rcsid[] =
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
#include <ifaddrs.h>
#include <ctype.h> #include <ctype.h>
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
@ -81,7 +82,6 @@ static const char rcsid[] =
struct ifreq ifr; struct ifreq ifr;
char name[IFNAMSIZ]; char name[IFNAMSIZ];
int flags;
int setaddr; int setaddr;
int setipdst; int setipdst;
int setmask; int setmask;
@ -94,9 +94,8 @@ int supmedia = 0;
int printkeys = 0; /* Print keying material for interfaces. */ int printkeys = 0; /* Print keying material for interfaces. */
static int ifconfig(int argc, char *const *argv, const struct afswtch *afp); static int ifconfig(int argc, char *const *argv, const struct afswtch *afp);
static void status(const struct afswtch *afp, int addrcount, static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
struct sockaddr_dl *sdl, struct if_msghdr *ifm, struct ifaddrs *ifa);
struct ifa_msghdr *ifam);
static void tunnel_status(int s); static void tunnel_status(int s);
static void usage(void); static void usage(void);
@ -141,16 +140,13 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int c, all, namesonly, downonly, uponly; int c, all, namesonly, downonly, uponly;
int need_nl = 0, count = 0;
const struct afswtch *afp = NULL; const struct afswtch *afp = NULL;
int addrcount, ifindex; int ifindex;
struct if_msghdr *ifm, *nextifm; struct ifaddrs *ifap, *ifa;
struct ifa_msghdr *ifam; struct ifreq paifr;
struct sockaddr_dl *sdl; const struct sockaddr_dl *sdl;
char *buf, *lim, *next; char options[1024], *cp;
size_t needed; const char *ifname;
int mib[6];
char options[1024];
struct option *p; struct option *p;
all = downonly = uponly = namesonly = verbose = 0; all = downonly = uponly = namesonly = verbose = 0;
@ -213,6 +209,7 @@ main(int argc, char *argv[])
if (argc > 1) if (argc > 1)
usage(); usage();
ifname = NULL;
ifindex = 0; ifindex = 0;
if (argc == 1) { if (argc == 1) {
afp = af_getbyname(*argv); afp = af_getbyname(*argv);
@ -227,13 +224,13 @@ main(int argc, char *argv[])
if (argc < 1) if (argc < 1)
usage(); usage();
strncpy(name, *argv, sizeof(name)); ifname = *argv;
argc--, argv++; argc--, argv++;
/* check and maybe load support for this interface */ /* check and maybe load support for this interface */
ifmaybeload(name); ifmaybeload(ifname);
ifindex = if_nametoindex(name); ifindex = if_nametoindex(ifname);
if (ifindex == 0) { if (ifindex == 0) {
/* /*
* NOTE: We must special-case the `create' command * NOTE: We must special-case the `create' command
@ -245,7 +242,7 @@ main(int argc, char *argv[])
ifconfig(argc, argv, NULL); ifconfig(argc, argv, NULL);
exit(0); exit(0);
} }
errx(1, "interface %s does not exist", name); errx(1, "interface %s does not exist", ifname);
} }
} }
@ -256,106 +253,55 @@ main(int argc, char *argv[])
argc--, argv++; argc--, argv++;
} }
retry: if (getifaddrs(&ifap) != 0)
mib[0] = CTL_NET; err(EXIT_FAILURE, "getifaddrs");
mib[1] = PF_ROUTE; cp = NULL;
mib[2] = 0; ifindex = 0;
mib[3] = 0; /* address family */ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
mib[4] = NET_RT_IFLIST; memset(&paifr, 0, sizeof(paifr));
mib[5] = ifindex; /* interface index */ strncpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name));
if (sizeof(paifr.ifr_addr) >= ifa->ifa_addr->sa_len) {
/* if particular family specified, only ask about it */ memcpy(&paifr.ifr_addr, ifa->ifa_addr,
if (afp != NULL) ifa->ifa_addr->sa_len);
mib[3] = afp->af_af;
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
errx(1, "iflist-sysctl-estimate");
if ((buf = malloc(needed)) == NULL)
errx(1, "malloc");
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
if (errno == ENOMEM && count++ < 10) {
warnx("Routing table grew, retrying");
free(buf);
sleep(1);
goto retry;
}
errx(1, "actual retrieval of interface table");
}
lim = buf + needed;
next = buf;
while (next < lim) {
ifm = (struct if_msghdr *)next;
if (ifm->ifm_type == RTM_IFINFO) {
if (ifm->ifm_data.ifi_datalen == 0)
ifm->ifm_data.ifi_datalen = sizeof(struct if_data);
sdl = (struct sockaddr_dl *)((char *)ifm + sizeof(struct if_msghdr) -
sizeof(struct if_data) + ifm->ifm_data.ifi_datalen);
flags = ifm->ifm_flags;
} else {
fprintf(stderr, "out of sync parsing NET_RT_IFLIST\n");
fprintf(stderr, "expected %d, got %d\n", RTM_IFINFO,
ifm->ifm_type);
fprintf(stderr, "msglen = %d\n", ifm->ifm_msglen);
fprintf(stderr, "buf:%p, next:%p, lim:%p\n", buf, next,
lim);
exit (1);
} }
next += ifm->ifm_msglen; if (ifname != NULL && strcmp(ifname, ifa->ifa_name) != 0)
ifam = NULL; continue;
addrcount = 0; if (ifa->ifa_addr->sa_family == AF_LINK)
while (next < lim) { sdl = (const struct sockaddr_dl *) ifa->ifa_addr;
else
sdl = NULL;
if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0)
continue;
if (strlcpy(name, ifa->ifa_name, sizeof(name)) >= sizeof(name))
continue;
cp = ifa->ifa_name;
nextifm = (struct if_msghdr *)next; if (downonly && (ifa->ifa_flags & IFF_UP) != 0)
continue;
if (nextifm->ifm_type != RTM_NEWADDR) if (uponly && (ifa->ifa_flags & IFF_UP) == 0)
break; continue;
ifindex++;
if (ifam == NULL) /*
ifam = (struct ifa_msghdr *)nextifm; * Are we just listing the interfaces?
*/
addrcount++; if (namesonly) {
next += nextifm->ifm_msglen; if (ifindex > 1)
} printf(" ");
memcpy(name, sdl->sdl_data, fputs(name, stdout);
sizeof(name) <= sdl->sdl_nlen ? continue;
sizeof(name)-1 : sdl->sdl_nlen);
name[sizeof(name) <= sdl->sdl_nlen ?
sizeof(name)-1 : sdl->sdl_nlen] = '\0';
if (all || namesonly) {
if (uponly)
if ((flags & IFF_UP) == 0)
continue; /* not up */
if (downonly)
if (flags & IFF_UP)
continue; /* not down */
if (namesonly) {
if (afp == NULL || afp->af_af != AF_LINK ||
sdl->sdl_type == IFT_ETHER) {
if (need_nl)
putchar(' ');
fputs(name, stdout);
need_nl++;
}
continue;
}
} }
if (argc > 0) if (argc > 0)
ifconfig(argc, argv, afp); ifconfig(argc, argv, afp);
else else
status(afp, addrcount, sdl, ifm, ifam); status(afp, sdl, ifa);
} }
free(buf); if (namesonly)
printf("\n");
freeifaddrs(ifap);
if (namesonly && need_nl > 0) exit(0);
putchar('\n');
exit (0);
} }
static struct afswtch *afs = NULL; static struct afswtch *afs = NULL;
@ -698,6 +644,7 @@ static void
setifflags(const char *vname, int value, int s, const struct afswtch *afp) setifflags(const char *vname, int value, int s, const struct afswtch *afp)
{ {
struct ifreq my_ifr; struct ifreq my_ifr;
int flags;
bcopy((char *)&ifr, (char *)&my_ifr, sizeof(struct ifreq)); bcopy((char *)&ifr, (char *)&my_ifr, sizeof(struct ifreq));
@ -722,6 +669,7 @@ setifflags(const char *vname, int value, int s, const struct afswtch *afp)
void void
setifcap(const char *vname, int value, int s, const struct afswtch *afp) setifcap(const char *vname, int value, int s, const struct afswtch *afp)
{ {
int flags;
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) { if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) {
Perror("ioctl (SIOCGIFCAP)"); Perror("ioctl (SIOCGIFCAP)");
@ -780,25 +728,6 @@ setifname(const char *val, int dummy __unused, int s,
free(newname); free(newname);
} }
/*
* Expand the compacted form of addresses as returned via the
* configuration read via sysctl().
*/
static void
rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo)
{
struct sockaddr *sa;
int i;
memset(rtinfo->rti_info, 0, sizeof(rtinfo->rti_info));
for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
if ((rtinfo->rti_addrs & (1 << i)) == 0)
continue;
rtinfo->rti_info[i] = sa = (struct sockaddr *)cp;
cp += SA_SIZE(sa);
}
}
#define IFFBITS \ #define IFFBITS \
"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \ "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \
"\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \ "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
@ -813,10 +742,10 @@ rt_xaddrs(caddr_t cp, caddr_t cplim, struct rt_addrinfo *rtinfo)
* specified, show only it; otherwise, show them all. * specified, show only it; otherwise, show them all.
*/ */
static void static void
status(const struct afswtch *afp, int addrcount, struct sockaddr_dl *sdl, status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
struct if_msghdr *ifm, struct ifa_msghdr *ifam) struct ifaddrs *ifa)
{ {
struct rt_addrinfo info; struct ifaddrs *ift;
int allfamilies, s; int allfamilies, s;
struct ifstat ifs; struct ifstat ifs;
@ -834,11 +763,11 @@ status(const struct afswtch *afp, int addrcount, struct sockaddr_dl *sdl,
err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family); err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
printf("%s: ", name); printf("%s: ", name);
printb("flags", flags, IFFBITS); printb("flags", ifa->ifa_flags, IFFBITS);
if (ifm->ifm_data.ifi_metric) if (ioctl(s, SIOCGIFMETRIC, &ifr) != -1)
printf(" metric %ld", ifm->ifm_data.ifi_metric); printf(" metric %d", ifr.ifr_metric);
if (ifm->ifm_data.ifi_mtu) if (ioctl(s, SIOCGIFMTU, &ifr) != -1)
printf(" mtu %ld", ifm->ifm_data.ifi_mtu); printf(" mtu %d", ifr.ifr_mtu);
putchar('\n'); putchar('\n');
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) { if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) {
@ -854,22 +783,20 @@ status(const struct afswtch *afp, int addrcount, struct sockaddr_dl *sdl,
tunnel_status(s); tunnel_status(s);
while (addrcount > 0) { for (ift = ifa; ift != NULL; ift = ift->ifa_next) {
info.rti_addrs = ifam->ifam_addrs; if (ift->ifa_addr == NULL)
/* Expand the compacted addresses */ continue;
rt_xaddrs((char *)(ifam + 1), ifam->ifam_msglen + (char *)ifam, if (strcmp(ifa->ifa_name, ift->ifa_name) != 0)
&info); continue;
if (allfamilies) { if (allfamilies) {
const struct afswtch *p; const struct afswtch *p;
p = af_getbyfamily(info.rti_info[RTAX_IFA]->sa_family); p = af_getbyfamily(ift->ifa_addr->sa_family);
if (p != NULL && p->af_status != NULL) if (p != NULL && p->af_status != NULL)
p->af_status(s, &info); p->af_status(s, ift);
} else if (afp->af_af == info.rti_info[RTAX_IFA]->sa_family) } else if (afp->af_af == ift->ifa_addr->sa_family)
afp->af_status(s, &info); afp->af_status(s, ift);
addrcount--;
ifam = (struct ifa_msghdr *)((char *)ifam + ifam->ifam_msglen);
} }
#if 0
if (allfamilies || afp->af_af == AF_LINK) { if (allfamilies || afp->af_af == AF_LINK) {
const struct afswtch *lafp; const struct afswtch *lafp;
@ -885,6 +812,7 @@ status(const struct afswtch *afp, int addrcount, struct sockaddr_dl *sdl,
lafp->af_status(s, &info); lafp->af_status(s, &info);
} }
} }
#endif
if (allfamilies) if (allfamilies)
af_other_status(s); af_other_status(s);
else if (afp->af_other_status != NULL) else if (afp->af_other_status != NULL)
@ -954,7 +882,7 @@ printb(const char *s, unsigned v, const char *bits)
} }
void void
ifmaybeload(char *name) ifmaybeload(const char *name)
{ {
struct module_stat mstat; struct module_stat mstat;
int fileid, modid; int fileid, modid;

View File

@ -72,7 +72,7 @@ void callback_register(callback_func *, void *);
#define DEF_CMD_OPTARG(name, func) { name, OPTARG, { .c_func = func } } #define DEF_CMD_OPTARG(name, func) { name, OPTARG, { .c_func = func } }
#define DEF_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func } } #define DEF_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func } }
struct rt_addrinfo; struct ifaddrs;
struct addrinfo; struct addrinfo;
enum { enum {
@ -94,7 +94,7 @@ struct afswtch {
* is defined then it is invoked after all address status * is defined then it is invoked after all address status
* is presented. * is presented.
*/ */
void (*af_status)(int, const struct rt_addrinfo *); void (*af_status)(int, const struct ifaddrs *);
void (*af_other_status)(int); void (*af_other_status)(int);
/* parse address method */ /* parse address method */
void (*af_getaddr)(const char *, int); void (*af_getaddr)(const char *, int);
@ -127,7 +127,6 @@ extern char name[IFNAMSIZ]; /* name of interface */
extern int allmedia; extern int allmedia;
extern int supmedia; extern int supmedia;
extern int printkeys; extern int printkeys;
extern int flags;
extern int newaddr; extern int newaddr;
extern int verbose; extern int verbose;
extern int setipdst; extern int setipdst;
@ -137,7 +136,7 @@ void setifcap(const char *, int value, int s, const struct afswtch *);
void Perror(const char *cmd); void Perror(const char *cmd);
void printb(const char *s, unsigned value, const char *bits); void printb(const char *s, unsigned value, const char *bits);
void ifmaybeload(char *name); void ifmaybeload(const char *name);
typedef void clone_callback_func(int, struct ifreq *); typedef void clone_callback_func(int, struct ifreq *);
void clone_setcallback(clone_callback_func *); void clone_setcallback(clone_callback_func *);