Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/mtrace SIOCGIFCONF->getifaddrs conversion
details: https://anonhg.NetBSD.org/src/rev/4b926b961223
branches: trunk
changeset: 550691:4b926b961223
user: itojun <itojun%NetBSD.org@localhost>
date: Sun Aug 17 22:12:43 2003 +0000
description:
SIOCGIFCONF->getifaddrs conversion
diffstat:
usr.sbin/mtrace/mtrace.c | 37 ++++++++++++++++---------------------
1 files changed, 16 insertions(+), 21 deletions(-)
diffs (77 lines):
diff -r 85a182a72228 -r 4b926b961223 usr.sbin/mtrace/mtrace.c
--- a/usr.sbin/mtrace/mtrace.c Sun Aug 17 21:43:29 2003 +0000
+++ b/usr.sbin/mtrace/mtrace.c Sun Aug 17 22:12:43 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mtrace.c,v 1.31 2003/05/16 23:24:38 dsl Exp $ */
+/* $NetBSD: mtrace.c,v 1.32 2003/08/17 22:12:43 itojun Exp $ */
/*
* mtrace.c
@@ -52,7 +52,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: mtrace.c,v 1.31 2003/05/16 23:24:38 dsl Exp $");
+__RCSID("$NetBSD: mtrace.c,v 1.32 2003/08/17 22:12:43 itojun Exp $");
#endif
#include <sys/types.h>
@@ -65,6 +65,7 @@
#include <memory.h>
#include <netdb.h>
#include <string.h>
+#include <ifaddrs.h>
#include "defs.h"
#include <stdarg.h>
@@ -296,37 +297,31 @@
u_int32_t
get_netmask(int s, u_int32_t dst)
{
- unsigned int i;
- char ifbuf[5000];
- struct ifconf ifc;
- struct ifreq *ifr;
u_int32_t if_addr, if_mask;
u_int32_t retval = 0xFFFFFFFF;
int found = FALSE;
+ struct ifaddrs *ifap, *ifa;
- ifc.ifc_buf = ifbuf;
- ifc.ifc_len = sizeof(ifbuf);
- if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
- perror("ioctl (SIOCGIFCONF)");
+ if (getifaddrs(&ifap) != 0) {
+ perror("getifaddrs");
return (retval);
}
- for (i = 0; i < ifc.ifc_len; ) {
- ifr = (struct ifreq *)((char *)ifc.ifc_req + i);
- i += sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len;
- if_addr = ((struct sockaddr_in *)&(ifr->ifr_addr))->sin_addr.s_addr;
- if (ioctl(s, SIOCGIFNETMASK, (char *)ifr) >= 0) {
- if_mask = ((struct sockaddr_in *)&(ifr->ifr_addr))->sin_addr.s_addr;
- if ((dst & if_mask) == (if_addr & if_mask)) {
- retval = if_mask;
- if (lcl_addr == 0) lcl_addr = if_addr;
- }
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+ if_addr = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
+ if_mask = ((struct sockaddr_in *)ifa->ifa_netmask)->sin_addr.s_addr;
+ if ((dst & if_mask) == (if_addr & if_mask)) {
+ retval = if_mask;
+ if (lcl_addr == 0)
+ lcl_addr = if_addr;
}
- if (lcl_addr == if_addr) found = TRUE;
+ if (lcl_addr == if_addr)
+ found = TRUE;
}
if (!found && lcl_addr != 0) {
printf("Interface address is not valid\n");
exit(1);
}
+ freeifaddrs(ifap);
return (retval);
}
Home |
Main Index |
Thread Index |
Old Index