[PATCH] initiflist(): sort interfaces by ifindex
by Vitezslav Samel
Since Linux 3.2 entries in /proc/net/dev are hashed and not sorted
by ifindex. Take care of that and sort them by ifindex in loading time.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/ifstats.c | 40 +++++++++++++++++++++-------------------
1 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/src/ifstats.c b/src/ifstats.c
index 0cfaacd..dbc5ab5 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -146,15 +146,11 @@ static int ifinlist(struct iflist *list, char *ifname)
static void initiflist(struct iflist **list)
{
- FILE *fd;
char ifname[IFNAMSIZ];
- struct iflist *itmp = NULL;
- struct iflist *tail = NULL;
- unsigned int index = 0;
*list = NULL;
- fd = open_procnetdev();
+ FILE *fd = open_procnetdev();
if (fd == NULL) {
tui_error(ANYKEY_MSG, "Unable to obtain interface list");
return;
@@ -183,26 +179,32 @@ static void initiflist(struct iflist **list)
* At this point, the interface is now sure to be up and running.
*/
- itmp = xmalloc(sizeof(struct iflist));
- memset(itmp, 0, sizeof(struct iflist));
+ struct iflist *itmp = xmallocz(sizeof(struct iflist));
strcpy(itmp->ifname, ifname);
itmp->ifindex = ifindex;
- index++;
- itmp->index = index;
- if (*list == NULL) {
- *list = itmp;
- itmp->prev_entry = NULL;
- } else {
- tail->next_entry = itmp;
- itmp->prev_entry = tail;
+ /* make the linked list sorted by ifindex */
+ struct iflist *cur = *list, *last = NULL;
+ while (cur != NULL && cur->ifindex < ifindex) {
+ last = cur;
+ cur = cur->next_entry;
}
-
- tail = itmp;
- itmp->next_entry = NULL;
+ itmp->prev_entry = last;
+ itmp->next_entry = cur;
+ if (cur)
+ cur->prev_entry = itmp;
+ if (last)
+ last->next_entry = itmp;
+ else
+ *list = itmp;
}
-
fclose(fd);
+
+ /* let the index follow the sorted linked list */
+ unsigned int index = 1;
+ struct iflist *cur;
+ for (cur = *list; cur != NULL; cur = cur->next_entry)
+ cur->index = index++;
}
static struct iflist *positionptr(struct iflist *iflist, const int ifindex)
--
1.7.8.4
11 years, 11 months
[PATCH] struct othptabent: make more room for MAC addrs
by Vitezslav Samel
Make more room for textual representation of MAC addresses.
For the future: make this dynamicly allocated and destroyed.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/othptab.h | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/othptab.h b/src/othptab.h
index 0f4d30d..71fd959 100644
--- a/src/othptab.h
+++ b/src/othptab.h
@@ -24,8 +24,8 @@ struct othptabent {
unsigned long int daddr;
struct in6_addr s6addr;
struct in6_addr d6addr;
- char smacaddr[15];
- char dmacaddr[15];
+ char smacaddr[18]; /* FIXME: use dynamicly allocated space */
+ char dmacaddr[18];
unsigned short linkproto;
char s_fqdn[100];
char d_fqdn[100];
--
1.7.8.4
11 years, 11 months
[PATCH 0/2] iptraf-ng: fixes
by Vitezslav Samel
The first commit fixes brown-paper-bag-over-my-head bug, the other
adds support to see packets on SIT interfaces.
The first one is so severe bug that you should consider releasing
new version of iptraf-ng.
Vitezslav Samel (2):
packet.c: packet_get() fix
packet.c: packet_adjust(): support SIT tunnels
src/packet.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
--
1.7.8.4
11 years, 12 months
[PATCH] CHANGES: set date of 1.1.2 release
by Vitezslav Samel
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
CHANGES | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/CHANGES b/CHANGES
index e5b8815..eb58676 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,6 @@
CHANGES file for iptraf-ng
-* aaa bbb 00 0000 Nikola Pajkovsky <npajkovs(a)redhat.com> - 1.1.2
+* Fri May 04 2012 Nikola Pajkovsky <npajkovs(a)redhat.com> - 1.1.2
- massive code cleanup
- fix PPP handling
- move the splash screen to the main menu
--
1.7.8.4
12 years
[PATCH 0/9] iptraf-ng-next: externs.h cleanup
by Vitezslav Samel
The externs.h file is included in iptraf.c only and doesn't
reflect the right types of the functions declared in int. Move
the function declarations into the proper headers, fix their types
and make all this mess compile. This way compiler would give us
warnings/errors when the function declaration and definition differ.
Vitezslav Samel (9):
externs.h cleanup: detstats()
externs.h cleanup: *options()
externs.h cleanup: kill unused ip_host_breakdown() declaration
externs.h cleanup: ifstats(), selectiface()
externs.h cleanup: ipmon()
externs.h cleanup: packet_size_breakdown()
externs.h cleanup: servmon()
externs.h cleanup: hostmon()
externs.h: remove this file
src/Makefile.am | 4 +++-
src/detstats.c | 1 +
src/detstats.h | 10 ++++++++++
src/externs.h | 29 -----------------------------
src/hostmon.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
src/hostmon.h | 54 ++++--------------------------------------------------
src/ifstats.c | 1 +
src/ifstats.h | 11 +++++++++++
src/iptraf.c | 6 +++++-
src/itrafmon.c | 1 +
src/itrafmon.h | 10 ++++++++++
src/options.h | 6 ++++++
src/pktsize.c | 6 ++++++
src/pktsize.h | 10 +++++-----
src/serv.c | 40 ++++++++++++++++++++++++++++++++++++++++
src/serv.h | 46 ++++++----------------------------------------
16 files changed, 156 insertions(+), 129 deletions(-)
create mode 100644 src/detstats.h
delete mode 100644 src/externs.h
create mode 100644 src/ifstats.h
create mode 100644 src/itrafmon.h
--
1.7.8.4
12 years
[PATCH 0/4] iptraf-ng: cleanups
by Vitezslav Samel
The first three patches clean up ifstats.h file: move structs
to appropriate files and the rest makes the new counters.[ch].
This cleanup allows to use structs now defined in counters.h in other
files/modules (e.g. in coming up RATE patches).
The last patch removes two unused functions from serv.c (this also
kills one warning).
Vitezslav Samel (4):
move struct ifcounts
move struct iflist and iftab
create counters.c
serv.c: remove unused functions
src/Makefile.am | 3 +-
src/counters.c | 23 +++++++++++++++++++
src/counters.h | 19 ++++++++++++++++
src/detstats.c | 40 ++++++++++++++-------------------
src/ifstats.c | 30 +++++++++++++++++++++++++-
src/ifstats.h | 64 -------------------------------------------------------
src/promisc.c | 1 -
src/serv.c | 24 --------------------
8 files changed, 90 insertions(+), 114 deletions(-)
create mode 100644 src/counters.c
create mode 100644 src/counters.h
delete mode 100644 src/ifstats.h
--
1.7.8.4
12 years