Net-Interface
view release on metacpan or search on metacpan
inst/netsymbols.pl view on Meta::CPAN
|;
### populate IFF flags
#
print NFt q|
/* BEGIN ni_IFF_inc.c include
****************************************************************
* DO NOT ALTER THIS FILE *
* IT IS WRITTEN BY Makefile.PL & inst/netsymbols.pl *
* EDIT THOSE INSTEAD *
****************************************************************
*/
const ni_iff_t ni_iff_tab[] = {
|;
### populate C portion
#
my @tmp = grep {/^AF/} keys %fam; # tmp store AFs
my @afs = sort { $fam{$a} <=> $fam{$b} } @tmp;
@tmp = grep {/^PF/} keys %fam;
my @pfs = sort { $fam{$a} <=> $fam{$b} } @tmp;
my @ifs = keys %ifs;
# iffs are not unique so we can safely purge unwanted symbols here
my @iffs = sort grep {/^IFF_/ && $_ !~ /IFF_DRV/} keys %ifs;
my @iffIN6 = sort grep {/^IN6_IFF/} keys %ifs;
#foreach (@iffs) {
# print STDERR "$_\t=> $ifs{$_}\n";
#}
print NFe q|my @afs = qw(
|;
foreach(@afs) {
$_ =~ /AF_([^\s]+)/;
print NFx "\t$_ = _NI_$_\n";
print NFe "\t$_\n";
print NFc qq|#ifdef $_\n\# define _NI_$_ $fam{$_}\n#else\n# define _NI_$_ $endv\n#endif\n|;
print NFz qq|\t{$_,\t"|, (lc $1), qq|"},\n|;
}
print NFe q|);
my @pfs = qw(
|;
foreach(@pfs) {
$_ =~ /PF_([^\s]+)/;
print NFx "\t$_ = _NI_$_\n";
print NFe "\t$_\n";
print NFc qq|#ifdef $_\n\# define _NI_$_ $fam{$_}\n#else\n# define _NI_$_ $endv\n#endif\n|;
print NFz qq|\t{$_,\t"|, (lc $1), qq|"},\n|;
}
print NFz qq|\t{__NI_AF_TEST,\t"placeholder"}
};
|;
print NFx qq|\t_NI_AF_TEST = __NI_AF_TEST
PREINIT:
SV * rv;
int n, i;
PPCODE:
if (ix >= $endv) {
croak("%s is not implemented on this architecture", GvNAME(CvGV(cv)));
}
rv = sv_2mortal(newSViv(ix));
n = sizeof(ni_af_sym_tab) / sizeof(ni_iff_t);
for (i=0; i<n; i++) {
if (ni_af_sym_tab[i].iff_val == ix) {
sv_setpv(rv,ni_af_sym_tab[i].iff_nam);
break;
}
}
SvIOK_on(rv);
XPUSHs(rv);
XSRETURN(1);
int
_net_if_syms()
ALIAS:
|;
print NFe q|);
my @ifs = qw(
|;
my $ifidx = 0;
my $idxary = q|
const u_int64_t bigsymvals[] = {|;
my $icoma = '';
foreach (@ifs) {
print NFe "\t$_\n";
next if $_ =~ /IFF_/;
print NFc qq|#ifdef $_\n\# define _NI_$_ $_\n#else\n# define _NI_$_ $endv\n#endif\n|;
# print NFx "\t$_ = _NI_$_\n";
print NFx "\t$_ = $ifidx\n";
$idxary .= "$icoma\n\t$ifs{$_}";
$icoma = ',';
$ifidx++;
}
print NFz qq|
const ni_iff_t ni_sym_iff_tab[] = {
|;
print NFe q|);
my @iffs = qw(
|;
print NFx qq| CODE:
if (ix >= $endv) {
croak("%s is not implemented on this architecture", GvNAME(CvGV(cv)));
}
RETVAL = bigsymvals[ix];
OUTPUT:
RETVAL
void
_net_i2f_syms()
inst/netsymbols.pl view on Meta::CPAN
=item * :afs Import all AF_XXX symbols
=item * :pfs Import all PF_XXX symbols
=item * :ifs Import all IFxxxx symbols
=item * :iffs Import all IFF symbols
|;
if (@iffIN6) {
print NFe q|
=item * :iffIN6 Import all IN6_IFF symbols (BSD flavors only)
|;
}
if (exists $fam{AF_INET6}) {
print NFe q|
=item * :iftype Import all IPV6 type symbols
=item * :scope Import all IPV6 scope symbols
|;
}
print NFe q|
=back
=head1 non EXPORT functions
=over 4
=item * Net::Interface::NetSymbols::NI_ENDVAL();
Reports the highest symbol value +1 of :all symbols above. Used for testing.
=item * Net::Interface::NetSymbols::NI_UNIQUE();
Returns a hash pointer to the AF_ or PF_ symbol values mapped to their
character strings as defined for this architecture.
i.e.
|, $utxt, q|
=head1 AUTHOR Michael Robinton <michael@bizsystems.com>
=head1 COPYRIGHT |. ((localtime())[5] +1900) .q|
Michael Robinton, all rights reserved.
This library is free software. You can distribute it and/or modify it under
the same terms as Perl itself.
=cut
1;
|;
# add test element and complete
print NFx qq| PREINIT:
SV * rv;
int n, i;
PPCODE:
if (ix >= $endv) {
croak("%s is not implemented on this architecture", GvNAME(CvGV(cv)));
}
rv = sv_2mortal(newSVnv(bigsymvals[ix]));
n = sizeof(ni_sym_iff_tab) / sizeof(ni_iff_t);
for (i=0; i<n; i++) {
if (ni_sym_iff_tab[i].iff_val == bigsymvals[ix]) {
sv_setpv(rv,ni_sym_iff_tab[i].iff_nam);
break;
}
}
SvNOK_on(rv);
XPUSHs(rv);
XSRETURN(1);
|;
# usually _LOCAL is defined on modern systems
#
close NFe;
close NFx;
close NFc;
close NFt;
# exit;
}
gensyms();
1;
( run in 0.816 second using v1.01-cache-2.11-cpan-5511b514fd6 )