blob: a7528a1b4b92c406519d6145034826cb2f9a244d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#!/usr/bin/php
<?php
$mynode = array_key_exists('LOCALNODE',$_SERVER)?$_SERVER['LOCALNODE']:0;
$file = STDIN;
$paths = array();
while (!feof($file)) {
if (seekto($file, '<as-path>') === FALSE) break;
seekto($file, '<segment');
seekto($file, '>');
$endofsection = FALSE;
$path = $mynode;
while (!feof($file)) {
if (seekto($file, '<') === FALSE) break;
switch (fread($file, 4)) {
case 'asn>': break;
case '/seg': $endofsection = TRUE; break;
default: die('unknown tag at '.(ftell($file)-4));
}
if ($endofsection) break;
$asn = seekto($file, '</asn>');
$path .= ' '.$asn;
}
if (in_array($path, $paths)) continue;
$paths[] = $path;
print($path."\n");
}
function seekto($f, $str) {
$part = '';
$i = 0;
$len = strlen($str);
while ($i < $len && !feof($f)) {
$c = fgetc($f);
if ($c === FALSE) return FALSE;
if ($c == $str[$i]) {
$i++;
} else {
if ($i) {
$i = 0;
$part = '';
}
$part .= $c;
}
}
return $part;
}
|