Commit 72c29c95 authored by Klaas Freitag's avatar Klaas Freitag

- Use numerical sort for interface sorting.

- Use an AF_INET socket for SIOCGIFCONF
parent 6053a5c2
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
10/1998 partly rewriten by Andi Kleen to support interface list. 10/1998 partly rewriten by Andi Kleen to support interface list.
I don't claim that the list operations are efficient @). I don't claim that the list operations are efficient @).
$Id: interface.c,v 1.8 1998/11/14 10:37:06 philip Exp $ $Id: interface.c,v 1.9 1998/11/15 18:58:40 freitag Exp $
*/ */
#include "config.h" #include "config.h"
...@@ -58,8 +58,7 @@ void add_interface(struct interface *n) ...@@ -58,8 +58,7 @@ void add_interface(struct interface *n)
pp = &int_list; pp = &int_list;
for (ife = int_list; ife; pp = &ife->next, ife = ife->next) { for (ife = int_list; ife; pp = &ife->next, ife = ife->next) {
/* XXX: should use numerical sort */ if (nstrcmp(ife->name, n->name) > 0)
if (strcmp(ife->name, n->name) > 0)
break; break;
} }
n->next = (*pp); n->next = (*pp);
...@@ -99,6 +98,16 @@ static int if_readconf(void) ...@@ -99,6 +98,16 @@ static int if_readconf(void)
struct ifconf ifc; struct ifconf ifc;
struct ifreq *ifr; struct ifreq *ifr;
int n, err = -1; int n, err = -1;
int skfd;
/* SIOCGIFCONF seems to only work properly on AF_INET sockets
currently */
skfd = get_socket_for_af(AF_INET);
if (skfd < 0) {
fprintf(stderr, _("warning: no inet socket available: %s\n"),
strerror(errno));
return -1;
}
ifc.ifc_buf = NULL; ifc.ifc_buf = NULL;
for (;;) { for (;;) {
......
...@@ -21,7 +21,7 @@ AFOBJS = unix.o inet.o inet6.o ax25.o ipx.o ddp.o ipx.o netrom.o af.o rose.o ec ...@@ -21,7 +21,7 @@ AFOBJS = unix.o inet.o inet6.o ax25.o ipx.o ddp.o ipx.o netrom.o af.o rose.o ec
AFGROBJS = inet_gr.o inet6_gr.o ipx_gr.o ddp_gr.o netrom_gr.o ax25_gr.o rose_gr.o getroute.o AFGROBJS = inet_gr.o inet6_gr.o ipx_gr.o ddp_gr.o netrom_gr.o ax25_gr.o rose_gr.o getroute.o
AFSROBJS = inet_sr.o inet6_sr.o netrom_sr.o ipx_sr.o setroute.o AFSROBJS = inet_sr.o inet6_sr.o netrom_sr.o ipx_sr.o setroute.o
ACTOBJS = slip_ac.o ppp_ac.o activate.o ACTOBJS = slip_ac.o ppp_ac.o activate.o
VARIA = getargs.o masq_info.o proc.o util.o VARIA = getargs.o masq_info.o proc.o util.o nstrcmp.o
NLSMISC = net-string.o NLSMISC = net-string.o
OBJS = $(NLSMISC) $(VARIA) $(AFOBJS) $(HWOBJS) \ OBJS = $(NLSMISC) $(VARIA) $(AFOBJS) $(HWOBJS) \
......
/* Copyright 1998 by Andi Kleen. Subject to the GPL. */
#include <ctype.h>
#include <stdlib.h>
#include "util.h"
/* like strcmp(), but knows about numbers */
int nstrcmp(const char *astr, const char *b)
{
const char *a = astr;
while (*a == *b) {
if (*a == '\0') return 0;
a++;
b++;
}
if (isdigit(*a)) {
if (!isdigit(*b)) return -1;
while (a > astr) {
a--;
if (!isdigit(*a)) {
a++;
break;
}
if (!isdigit(*b)) return -1;
b--;
}
return atoi(a) > atoi(b) ? 1 : -1;
}
return *a - *b;
}
...@@ -8,3 +8,6 @@ void *xrealloc(void *p, size_t sz); ...@@ -8,3 +8,6 @@ void *xrealloc(void *p, size_t sz);
int kernel_version(void); int kernel_version(void);
#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch)) #define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch))
int nstrcmp(const char *, const char *);
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
/* 19980630 - i18n - Arnaldo Carvalho de Melo <acme@conectiva.com.br> */ /* 19980630 - i18n - Arnaldo Carvalho de Melo <acme@conectiva.com.br> */
/* 19981113 - i18n fixes - Arnaldo Carvalho de Melo <acme@conectiva.com.br> */ /* 19981113 - i18n fixes - Arnaldo Carvalho de Melo <acme@conectiva.com.br> */
/*
XXX: rewrite to 2 pass to support /proc/net/netstat too
support -t -u
*/
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment