Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/ndbootd Rewrite method used to determine the ethern...
details: https://anonhg.NetBSD.org/src/rev/97de8cd8fa72
branches: trunk
changeset: 581534:97de8cd8fa72
user: lukem <lukem%NetBSD.org@localhost>
date: Thu Jun 02 11:27:44 2005 +0000
description:
Rewrite method used to determine the ethernet address of the desired
interface to not use uninitalized variables.
Bug crept in in conversion to getifaddrs().
Detected with gcc -Wuninitalized.
diffstat:
usr.sbin/ndbootd/ndbootd.c | 38 +++++++++++---------------------------
1 files changed, 11 insertions(+), 27 deletions(-)
diffs (91 lines):
diff -r 2f79f8da6b44 -r 97de8cd8fa72 usr.sbin/ndbootd/ndbootd.c
--- a/usr.sbin/ndbootd/ndbootd.c Thu Jun 02 11:10:00 2005 +0000
+++ b/usr.sbin/ndbootd/ndbootd.c Thu Jun 02 11:27:44 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ndbootd.c,v 1.8 2003/08/17 22:34:17 itojun Exp $ */
+/* $NetBSD: ndbootd.c,v 1.9 2005/06/02 11:27:44 lukem Exp $ */
/* ndbootd.c - the Sun Network Disk (nd) daemon: */
@@ -81,7 +81,7 @@
#if 0
static const char _ndbootd_c_rcsid[] = "<<Id: ndbootd.c,v 1.9 2001/06/13 21:19:11 fredette Exp >>";
#else
-__RCSID("$NetBSD: ndbootd.c,v 1.8 2003/08/17 22:34:17 itojun Exp $");
+__RCSID("$NetBSD: ndbootd.c,v 1.9 2005/06/02 11:27:44 lukem Exp $");
#endif
/* includes: */
@@ -206,9 +206,6 @@
{
struct ifreq ifr;
#ifdef HAVE_AF_LINK
- struct ifaddrs *link_ifas[20]; /* FIXME - magic constant. */
- size_t link_ifas_count;
- size_t link_ifas_i;
struct sockaddr_dl *sadl;
#endif /* HAVE_AF_LINK */
struct ndbootd_interface *interface;
@@ -218,24 +215,10 @@
if (getifaddrs(&ifap) != 0) {
return (NULL);
}
-#ifdef HAVE_AF_LINK
- /* start our list of link address ifas: */
- link_ifas_count = 0;
-#endif /* HAVE_AF_LINK */
/* walk the interface list: */
ifa_user = NULL;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
-#ifdef HAVE_AF_LINK
- /* if this is a hardware address, save it: */
- if (ifa->ifa_addr->sa_family == AF_LINK) {
- if (link_ifas_count < (sizeof(link_ifas) / sizeof(link_ifas[0]))) {
- link_ifas[link_ifas_count++] = ifa;
- }
- continue;
- }
-#endif /* HAVE_AF_LINK */
-
/* ignore this interface if it doesn't do IP: */
if (ifa->ifa_addr->sa_family != AF_INET) {
continue;
@@ -258,12 +241,10 @@
}
}
- if (ifa == NULL)
+ /* if we don't have an interface to return: */
+ if (ifa == NULL || ifa_user == NULL) {
+ freeifaddrs(ifap);
errno = ENOENT;
-
- /* if we don't have an interface to return: */
- if (ifa_user == NULL) {
- freeifaddrs(ifap);
return (NULL);
}
/* start the interface description: */
@@ -274,15 +255,18 @@
/* we must be able to find an AF_LINK ifreq that gives us the
* interface's Ethernet address. */
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
- if (!strcmp(link_ifas[link_ifas_i]->ifa_name,
- ifa_user->ifa_name)) {
- ifa = link_ifas[link_ifas_i];
+ if (ifa->ifa_addr->sa_family != AF_LINK) {
+ continue;
+ }
+ /* if this is the hardware address we want */
+ if (!strcmp(ifa->ifa_name, ifa_user->ifa_name)) {
break;
}
}
if (ifa == NULL) {
freeifaddrs(ifap);
free(interface);
+ errno = ENOENT;
return (NULL);
}
/* copy out the Ethernet address: */
Home |
Main Index |
Thread Index |
Old Index