Commit e719ffd1 authored by Klaas Freitag's avatar Klaas Freitag

First try at extension tolerant /proc parser. Only used by route so far.

parent 87661e43
......@@ -34,7 +34,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
AFSROBJS = inet_sr.o inet6_sr.o netrom_sr.o ipx_sr.o setroute.o
ACTOBJS = slip_ac.o ppp_ac.o activate.o
VARIA = getargs.o masq_info.o
VARIA = getargs.o masq_info.o proc.o
NLSMISC = net-string.o
OBJS = $(NLSMISC) $(VARIA) $(AFOBJS) $(HWOBJS) \
......@@ -43,7 +43,7 @@ OBJS = $(NLSMISC) $(VARIA) $(AFOBJS) $(HWOBJS) \
# This can be overwritten by the TOPLEVEL Makefile
TOPDIR=..
COPTS = -O2 -Wall -fomit-frame-pointer #-DDEBUG
COPTS = -O2 -Wall #-DDEBUG
LOPTS = -s
CFLAGS = $(COPTS) -I. -I$(TOPDIR) -I$(TOPDIR)/include
......
......@@ -22,6 +22,7 @@
#include "net-locale.h"
#include "net-features.h"
#include "proc.h"
extern struct aftype inet_aftype;
......@@ -34,6 +35,7 @@ int rprint_fib(int ext, int numeric)
struct sockaddr snet, sgate, smask;
int num, iflags, metric, refcnt, use, mss, window, irtt;
FILE *fp=fopen(_PATH_PROCNET_ROUTE, "r");
char *fmt;
if (!fp) {
ESYSNOT("getroute","INET FIB");
......@@ -59,9 +61,28 @@ int rprint_fib(int ext, int numeric)
irtt=0;
window=0;
mss=0;
fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, fp,
"Iface", "%16s",
"Destination", "%128s",
"Gateway", "%128s",
"Flags", "%X",
"RefCnt", "%d",
"Use", "%d",
"Metric", "%d",
"Mask", "%128s",
"MTU", "%d",
"Window", "%d",
"IRTT", "%d",
NULL);
/* "%16s %128s %128s %X %d %d %d %128s %d %d %d\n" */
if (!fmt)
return 1;
while (fgets(buff, 1023, fp))
{
num = sscanf(buff, "%16s %128s %128s %X %d %d %d %128s %d %d %d\n",
num = sscanf(buff, fmt,
iface, net_addr, gate_addr,
&iflags, &refcnt, &use, &metric, mask_addr,
&mss,&window,&irtt);
......
/* Tolerant /proc file parser. Copyright 1998 Andi Kleen */
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
/* Caller must free return string. */
char *
proc_gen_fmt(char *name, FILE *fh, ...)
{
char buf[512], format[512] = "";
char *title, *head;
va_list ap;
if (!fgets(buf, sizeof buf, fh))
return NULL;
va_start(ap,fh);
head = strtok(buf, " \t");
title = va_arg(ap, char *);
while (title && head) {
if (!strcmp(title, head)) {
strcat(format, va_arg(ap, char *));
title = va_arg(ap, char *);
} else {
strcat(format, "%*[^ \t]");
}
strcat(format, " ");
head = strtok(NULL, " \t");
}
va_end(ap);
if (title) {
fprintf(stderr, "warning: %s does not contain required field %s\n",
name, title);
return NULL;
}
return strdup(format);
}
/* Generate a suitable scanf format for a column title line */
char *proc_gen_fmt(char *name, FILE *fh, ...);
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