-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdiscover.pl
executable file
·80 lines (67 loc) · 1.71 KB
/
discover.pl
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl
use strict;
use warnings;
use File::Temp qw(tempdir);
my $srcdir = "src/org/jnasockopt";
my $inputoption = "$srcdir/JNASockOption.java";
my $inputlevel = "$srcdir/JNASockOptionLevel.java";
my $tmpdir = tempdir(CLEANUP => 1);
my $tmpc = $tmpdir."/test.c";
my $tmpx = $tmpdir."/test";
sub checkSymbol
{
my @includes = qw(stdio.h stdlib.h net/if_utun.h netinet/in.h sys/mbuf.h sys/un.h netinet/sctp.h netinet/tcp.h netinet/udp.h netpacket/packet.h);
my $sym = shift @_;
my $level = shift @_;
my $func = $level?"putLevel":"putOption";
my $enum = $level?"JNASockOptionLevel":"JNASockOption";
open (OUTPUT, ">$tmpc") || die ("Cannot open C file $tmpc: $!");
for my $i (@includes)
{
print OUTPUT "#include <$i>\n" if ( -r "/usr/include/$i" );
}
print OUTPUT <<"END1";
/* testing $sym */
int
main (int argc, char **argv)
{
printf ("\\t\\t$func ($enum.$sym, 0x%x);\\n", $sym);
exit (0);
}
END1
close (OUTPUT);
unlink ($tmpx);
# printf STDERR "Testing $sym\n";
my $out = "";
my $redir = ">/dev/null 2>&1";
open (PIPE, "gcc $tmpc -o $tmpx $redir && chmod 755 $tmpx && $tmpx|") || die "Cannot run gcc: $!";
while (<PIPE>)
{
$out .= $_;
}
return $out;
}
sub checkFiles
{
print << "END2";
package sockettest;
public class JNASockOptionDetailsSubclass extends JNASockOptionDetails {
\tpublic JNASockOptionDetailsSubclass() {
\t\tsuper ();
END2
my $level;
for ($level = 0; $level<2; $level++)
{
open (INPUT, $level?$inputlevel:$inputoption) || die ("Cannot open input file: $!");
while (<INPUT>)
{
print checkSymbol($1, $level) if (/^\s+([A-Z_]+)\b/);
}
close (INPUT);
}
print << "END3";
\t}
}
END3
}
checkFiles;