Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
net-tools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
net-tools
Commits
e719ffd1
Commit
e719ffd1
authored
May 12, 1998
by
Klaas Freitag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First try at extension tolerant /proc parser. Only used by route so far.
parent
87661e43
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
3 deletions
+67
-3
lib/Makefile
lib/Makefile
+2
-2
lib/inet_gr.c
lib/inet_gr.c
+22
-1
lib/proc.c
lib/proc.c
+39
-0
lib/proc.h
lib/proc.h
+4
-0
No files found.
lib/Makefile
View file @
e719ffd1
...
...
@@ -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
...
...
lib/inet_gr.c
View file @
e719ffd1
...
...
@@ -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
);
...
...
lib/proc.c
0 → 100644
View file @
e719ffd1
/* 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
);
}
lib/proc.h
0 → 100644
View file @
e719ffd1
/* Generate a suitable scanf format for a column title line */
char
*
proc_gen_fmt
(
char
*
name
,
FILE
*
fh
,
...);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment