summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1997-11-22 13:46:02 +0000
committerbrian <brian@FreeBSD.org>1997-11-22 13:46:02 +0000
commite46337437dc8b33d62f1939c9a109c6316c57fbb (patch)
treea7e0178d0e9fe3a036aee4fe37f0c437e25c3103 /usr.sbin/ppp
parent975c3797b1c2e5d9e9c4439ac6f45c4890b6f5e6 (diff)
downloadFreeBSD-src-e46337437dc8b33d62f1939c9a109c6316c57fbb.zip
FreeBSD-src-e46337437dc8b33d62f1939c9a109c6316c57fbb.tar.gz
Understand how to derive the names of interfaces
when they aren't ordered. This is probably vital for laptop support ;-I
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r--usr.sbin/ppp/route.c62
1 files changed, 28 insertions, 34 deletions
diff --git a/usr.sbin/ppp/route.c b/usr.sbin/ppp/route.c
index 41f62db..694d713 100644
--- a/usr.sbin/ppp/route.c
+++ b/usr.sbin/ppp/route.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: route.c,v 1.26 1997/11/15 02:15:56 brian Exp $
+ * $Id: route.c,v 1.27 1997/11/22 03:37:44 brian Exp $
*
*/
@@ -264,12 +264,11 @@ static const char *
Index2Nam(int idx)
{
static char ifs[50][6];
- static int nifs;
+ static int nifs, debug_done;
if (!nifs) {
int mib[6], needed, len;
char *buf, *ptr, *end;
- struct if_msghdr *n;
struct sockaddr_dl *dl;
struct if_msghdr *ifm;
@@ -292,38 +291,38 @@ Index2Nam(int idx)
}
end = buf + needed;
- ptr = buf;
- while (ptr < end) {
+ for (ptr = buf; ptr < end; ptr += ifm->ifm_msglen) {
ifm = (struct if_msghdr *)ptr;
-
- if (ifm->ifm_type != RTM_IFINFO) {
- free(buf);
- return "???";
- }
dl = (struct sockaddr_dl *)(ifm + 1);
- ptr += ifm->ifm_msglen;
- while (ptr < end) {
- n = (struct if_msghdr *)ptr;
- if (n->ifm_type != RTM_NEWADDR)
- break;
- ptr += n->ifm_msglen;
- }
- if ((len = dl->sdl_nlen) > sizeof(ifs[0])-1)
- len = sizeof(ifs[0])-1;
- strncpy(ifs[nifs], dl->sdl_data, len);
- ifs[nifs++][len] = '\0';
- if (nifs == sizeof(ifs)/sizeof(ifs[0]))
- break;
+ if (ifm->ifm_index > 0 && ifm->ifm_index <= sizeof(ifs)/sizeof(ifs[0])
+ && ifs[ifm->ifm_index-1][0] == '\0') {
+ if ((len = dl->sdl_nlen) > sizeof(ifs[0])-1)
+ len = sizeof(ifs[0])-1;
+ strncpy(ifs[ifm->ifm_index-1], dl->sdl_data, len);
+ ifs[ifm->ifm_index-1][len] = '\0';
+ if (len && nifs < ifm->ifm_index)
+ nifs = ifm->ifm_index;
+ } else if (LogIsKept(LogDEBUG))
+ LogPrintf(LogDEBUG, "Skipping out-of-range interface %d!\n",
+ ifm->ifm_index);
}
free(buf);
}
-#ifdef __FreeBSD__
- idx--; /* We start at 1, not 0 */
-#endif
- if (idx < 0 || idx >= nifs)
+ if (LogIsKept(LogDEBUG) && !debug_done) {
+ int f;
+
+ LogPrintf(LogDEBUG, "Found the following interfaces:\n");
+ for (f = 0; f < nifs; f++)
+ if (*ifs[f] != '\0')
+ LogPrintf(LogDEBUG, " Index %d, name \"%s\"\n", f+1, ifs[f]);
+ debug_done = 1;
+ }
+
+ if (idx < 1 || idx > nifs || ifs[idx-1][0] == '\0')
return "???";
- return ifs[idx];
+
+ return ifs[idx-1];
}
int
@@ -475,12 +474,7 @@ GetIfIndex(char *name)
int idx;
const char *got;
-#ifdef __FreeBSD__
- idx = 1; /* We start at 1, not 0 */
-#else
- idx = 0;
-#endif
-
+ idx = 1;
while (strcmp(got = Index2Nam(idx), "???"))
if (!strcmp(got, name))
return IfIndex = idx;
OpenPOWER on IntegriCloud