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) \
# 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
#include "net-locale.h"
#include "net-features.h"
+#include "proc.h"
extern struct aftype inet_aftype;
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");
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);
--- /dev/null
+/* 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);
+}
--- /dev/null
+
+
+/* Generate a suitable scanf format for a column title line */
+char *proc_gen_fmt(char *name, FILE *fh, ...);