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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
|
#!/usr/bin/perl
#
# ##################################################################### #
# netsymbols.pl version 0.10 9-21-16, michael@bizsystems.com #
# #
# #
# COPYRIGHT 2008-2016 Michael Robinton <michael@bizsystems.com> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of either: #
# #
# a) the GNU General Public License as published by the Free #
# Software Foundation; either version 2, or (at your option) any #
# later version, or #
# #
# b) the "Artistic License" which comes with this distribution. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either #
# the GNU General Public License or the Artistic License for more #
# details. #
# #
# You should have received a copy of the Artistic License with this #
# distribution, in the file named "Artistic". If not, I'll be glad #
# to provide one. #
# #
# You should also have received a copy of the GNU General Public #
# License along with this program in the file named "Copying". If not, #
# write to the #
# #
# Free Software Foundation, Inc. #
# 59 Temple Place, Suite 330 #
# Boston, MA 02111-1307, USA #
# #
# or visit their web page on the internet at: #
# #
# http://www.gnu.org/copyleft/gpl.html. #
# ##################################################################### #
package NetSymbols;
use diagnostics;
use Config;
my $doprint = 0;
my $conf = \%Config;
my $include = $conf->{usrinc};
sub new {
return bless {}, __PACKAGE__;
}
my $grep = qx/which grep/;
chop $grep while $grep =~ /\n$/;
my $gfp = sub {
my($mtch,$include) = @_;
my $cmd = $grep . $mtch . $include .'/*'."\n";
my @lines = qx/$cmd/;
print STDERR '# ', $cmd if $doprint;
foreach (@lines) {
chop $_ while $_ =~ /\s$/;
print STDERR $_, "\n" if $doprint;
}
return @lines;
};
my (@fileAFs,@fileIFs,@fileIN6s);
sub mksymblArrays {
@fileAFs = $gfp->(' -rEl "define[[:space:]]+[AP]F_" ',$include);
@fileIFs = $gfp->(' -rEl "define[[:space:]]+IF" ',$include);
@fileIN6s = $gfp->(' -rEl "define[[:space:]]+IN6_IF" ',$include);
}
### generate AF/PF families
# list of troublesome symbols to ignore
my @donotuse = qw(
AF_NETGRAPH
PF_NETGRAPH
);
# list of wanted AF/PF symbols, ignore the rest
# this list should reflect the SOCKADDR's present
# in the header file "ni_fixups.h" plus a few symbols
#
my @wantafsyms = qw(
AF_UNSPEC
AF_INET
AF_INET6
AF_LOCAL
AF_FILE
AF_UNIX
AF_MAX
AF_PACKET
AF_ROUTE
AF_APPLETALK
AF_ASH
AF_X25
AF_ECONET
AF_IPX
AF_ROSE
AF_LINK
AF_ISO
AF_NUTSS
AF_AX25
AF_DECnet
PF_UNSPEC
PF_INET
PF_INET6
PF_LOCAL
PF_FILE
PF_UNIX
PF_MAX
PF_PACKET
PF_ROUTE
PF_APPLETALK
PF_ASH
PF_X25
PF_ECONET
PF_IPX
PF_ROSE
PF_LINK
PF_ISO
PF_NUTSS
PF_AX25
PF_DECnet
);
my(@slurp,%slurped,%fam,%unique);
my $endv = 0; # maximum value found in defines
sub cleanslurp {
undef @slurp;
%slurped = ();
}
# file string, slurp switch full filename = 1
sub slurp {
my($in,$sw) = @_;;
$sw = 0 unless defined $sw;
#print STDERR "slurping $in\n";
return if $slurped{$in};
$slurped{$in} = 1;
local *F;
my $file;
if ($sw) {
$file = $in;
} else {
my $incpth = $Config{incpth};
while ($incpth =~ /(\S+)/g) {
my $path=$1 .'/'. $in;
if (-e $path) {
$file=$path;
last;
}
}
return unless ($file);
}
open (F,$file) or return;
my @new = <F>;
close F;
#foreach (@new) {
# print STDERR "$file => $_\n";
#}
push @slurp, @new;
}
sub fslurp {
foreach (@_) {
#print STDERR $_,"\n";
slurp($_,1); # tell slurp to use absolute file name
}
}
# input: hash pointer,
# unique hash pointer or false
# regular expression,
# secondary regexp if enum (else undef)
#
sub fill {
my($hp,$unique,$rgx1,$rgx2) = @_;
my %enum; # enumeration cache
foreach(@slurp) {
if ($_ =~ /^#\s*include\s+\<\s*([^\s>]+)/) {
#print STDERR "\tincfile $1\n";
slurp($1);
next;
}
if ($rgx2 && $_ =~ /$rgx2/) {
my $pri = $1;
my $sec = $2;
#print STDERR "IFF pri=$pri, sec=$sec\n";
next if $2 =~ /[^0-9x]/; # must be numeric or hex
$sec = eval "$sec";
$enum{$pri} = $sec;
$endv = $sec if $endv < $sec; # track maximum value
next;
}
next unless $_ =~ /$rgx1/;
my $pri = $1;
my $sec = $2;
#print STDERR "pri=$pri, sec=$sec\n";
if ($rgx2 && exists $enum{$pri} && $pri eq $sec) {
$hp->{$pri} = $enum{$pri};
next;
} elsif ($sec =~ /[^0-9x]/) { # if this is not a number
next unless exists $hp->{$sec}; # should not happen
$hp->{$pri} = $hp->{$sec};
} else {
$sec = eval "$sec";
$hp->{$pri} = $sec;
$endv = $sec if $endv < $sec; # track maximum value
next unless $unique;
next if exists $unique->{$sec};
#print STDERR "unique $sec\t=> $pri\n";
$unique->{$sec} = $pri; # track 1st definition
}
}
}
# input: filehandle,
# symbol hash
# array of symbols synonyms
#
sub extradef {
my($F,$sym,@syn) = @_;
#print STDERR "extra defs @syn\n";
my $x;
foreach(0..$#syn) { # check each synonym
if (exists $sym->{$syn[$_]}) {
$x = $_;
last;
}
}
#print STDERR qq|\n\tadvisory warning\n"@syn"\n\tnot defined\n| unless defined $x;
return unless defined $x;
# define all undefined synonyms
#
foreach(0..$#syn) {
next if $_ == $x;
my $newsym = $syn[$_];
print $F "#ifndef $newsym\n# define $syn[$_] $syn[$x]\n#endif\n";
$sym->{$newsym} = $sym->{$syn[$x]};
}
}
my $XX = 1; # 1 = original, 0 = new
sub gensyms {
mksymblArrays();
cleanslurp();
if ($XX) {
slurp('sys/socket.h'); # parse sys/socket.h and its #includes
} else {
fslurp(@fileAFs);
}
fill(\%fam,\%unique,'^#\s*define\s+((?:A|P)F_[^\s]+)\s+([^\s]+)');
# fill(\%fam,\%unique,'^#\s*define\s+((?:A|P)F_[^\s]{2,})\s+([^\s]+)');
# repeat in case symbol dependencies are out of order
cleanslurp();
if ($XX) {
slurp('sys/socket.h');
#slurp('sys/types.h');
} else {
fslurp(@fileAFs);
}
fill(\%fam,'','^#\s*define\s+((?:A|P)F_[^\s]+)\s+([^\s]+)');
# fill(\%fam,'','^#\s*define\s+((?:A|P)F_[^\s]{2,})\s+([^\s]+)');
my %ifs;
cleanslurp();
if ($XX) {
slurp('net/if.h');
slurp('netinet/in.h') if -e '/usr/include/netinet/in.h';
slurp('netinet/in_var.h') if -e '/usr/include/netinet/in_var.h';
} else {
fslurp(@fileIFs);
fslurp(@fileIN6s);
}
fill(\%ifs,\%unique,'^#\s*define\s+(IF[^\s]+)\s+([^\s]+)','(IF[^\s]+)\s*\=\s*([^\s,]+)');
fill(\%ifs,\%unique,'^#\s*define\s+(IN6_IF[^\s]+)\s+([^\s]+)','(IN6_IF[^\s]+)\s*\=\s*([^\s,]+)');
#foreach (keys %unique) {
#print STDERR "$_\t=> $unique{$_}\n";
#}
cleanslurp();
if ($XX) {
slurp('net/if.h');
slurp('netinet/in.h') if -e '/usr/include/netinet/in.h';
slurp('netinet/in_var.h') if -e '/usr/include/netinet/in_var.h';
} else {
fslurp(@fileIFs);
fslurp(@fileIN6s);
}
fill(\%ifs,'','^#\s*define\s+(IF[^\s]+)\s+([^\s]+)','(IF[^\s]+)\s*\=\s*([^\s,]+)');
fill(\%ifs,'','^#\s*define\s+(IN6_IF[^\s]+)\s+([^\s]+)','(IN6_IF[^\s]+)\s*\=\s*([^\s,]+)');
# dispose of troublesome symbols
my %ru = reverse %unique;
foreach my $symhsh (\%ifs,\%fam,\%ru) {
foreach(@donotuse) { # remove the ones that cause trouble
delete $symhsh->{$_} if exists $symhsh->{$_};
}
}
foreach my $symhsh(\%fam) {
my @allsyms = keys %$symhsh;
foreach my $havsym (@allsyms) {
unless (grep {/$havsym/} @wantafsyms) {
delete $symhsh->{$havsym}; # delete unneeded symbol here
delete $ru{$havsym}; # and in unique hash
}
}
}
%unique = reverse %ru;
# fill done, bump max value
++$endv;
# we're going to ignore all that end value tracking because IFF's exceed I32
# I32 size. Use the max number that fits in an I32 and do IFF's another way
$endv = (2**31) -1;
mkdir 'lib' unless -e 'lib' && -d 'lib';
mkdir 'lib/Net' unless -e 'lib/Net' && -d 'lib/Net';
mkdir 'lib/Net/Interface' unless -e 'lib/Net/Interface' && -d 'lib/Net/Interface';
open(NFe,'>lib/Net/Interface/NetSymbols.pm') or die "could not open NetSymbols.pm for write";
open(NFx,'>netsymbolXS.inc') or die "could not open netsymbolXS.inc for write";
open(NFc,'>netsymbolC.inc') or die "could not open netsymbolC.inc for write";
open(NFt,'>ni_IFF_inc.c') or die "could not open ni_IFF_inc.c for write";
open(NFz,'>ni_XStabs_inc.c') or die "could not open ni_XStabs_inc.c for write";
print NFz q|/* BEGIN ni_XStabs_inc.c
* ************************************************************ *
* DO NOT ALTER THIS FILE *
* IT IS WRITTEN BY Makefile.PL & inst/netsymbols.pl *
* EDIT THOSE INSTEAD *
* ************************************************************ *
* some of these symbols may be redundant *
* ************************************************************ */
|;
# make defines for synonyms
extradef(*NFc,\%fam,qw( PF_LOCAL PF_UNIX PF_FILE AF_LOCAL AF_FILE AF_UNIX )); # are all synonyms
extradef(*NFc,\%fam,qw( PF_MAX AF_MAX ));
extradef(*NFc,\%fam,qw( AF_PACKET PF_PACKET AF_ROUTE PF_ROUTE ));
extradef(*NFc,\%fam,qw( AF_ISO PF_ISO AF_BRIDGE PF_BRIDGE ));
# this one is not correct... extradef(*NFc,\%fam,qw( AF_NS PF_NS AF_NUTSS PF_NUTSS AF_ATM PF_ATM ));
extradef(*NFc,\%ifs,qw( IFNAMSIZ IF_NAMESIZE ));
# Fix missing definition
print NFc "#ifndef IFHWADDRLEN\n#define IFHWADDRLEN 6\n#endif\n";
$ifs{IFHWADDRLEN} = 6;
# Add opening definition
print NFc qq|
#define __NI_AF_TEST $endv
|;
print NFz q|
const ni_iff_t ni_af_sym_tab[] = {
|;
### populate exports
print NFe q|#!|. $conf->{perlpath} .q|
#
# DO NOT ALTER THIS FILE
# IT IS WRITTEN BY Makefile.PL and inst/netsymbols.pl
# EDIT THOSE INSTEAD
#
package Net::Interface::NetSymbols;
use vars qw($VERSION @EXPORT_OK %EXPORT_TAGS);
$VERSION = 1.01;
|;
print NFx q|void
_net_af_syms()
ALIAS:
|;
### 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/} sort keys %fam; # tmp store AFs
my @afs = sort { $fam{$a} <=> $fam{$b} } @tmp;
@tmp = grep {/^PF/} sort keys %fam;
my @pfs = sort { $fam{$a} <=> $fam{$b} } @tmp;
my @ifs = sort 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()
ALIAS:
|;
$comma = '';
foreach(sort @iffs) {
$_ =~ /IFF_([^\s]+)/;
print NFc qq|#ifdef $_\n\# define _NI_$_ $_\n#else\n# define _NI_$_ $endv\n#endif\n|;
print NFz qq|\t{$_,\t"|, (lc $1), qq|"},\n|;
print NFe "\t$_\n";
# print NFx "\t$_ = _NI_$_\n";
print NFx "\t$_ = $ifidx\n";
$idxary .= "$icoma\n\t$ifs{$_}";
$ifidx++;
next if $_ eq 'IFF_UP'; # special case handled separately
print NFt qq|$comma\n\t\{$_,\t"$1"\}|;
$comma = ',';
}
print NFt q|
};
#ifdef HAVE_STRUCT_IN6_IFREQ
const ni_iff_t ni_iff_tabIN6[] = {
|;
print NFe q|);
my @iffIN6 = qw(
|;
$comma = '';
foreach(sort @iffIN6) {
$_ =~ /IFF_([^\s]+)/;
print NFc qq|#ifdef $_\n\# define _NI_$_ $_\n#else\n# define _NI_$_ $endv\n#endif\n|;
print NFz qq|\t{$_,\t"|. (lc $1). qq|"},\n|;
next if $_ eq 'IFF_UP'; # special case handled separately
print NFe "\t$_\n";
# print NFx "\t$_ = _NI_$_\n";
print NFx "\t$_ = $ifidx\n";
$idxary .= "$icoma\n\t$ifs{$_}";
$ifidx++;
print NFt qq|$comma\n\t\{$_,\t"$1"\}|;
$comma = ',';
}
print NFz qq|\t{__NI_AF_TEST,\t"placeholder"}
};
$idxary
};
|;
print NFt q|
};
#endif
/* END ni_IFF_inc.c include */
|;
print NFe q|);
my %unique = (
|;
my $utxt = '';
foreach(sort {$a <=> $b} keys %unique) {
$utxt .= "\t$_\t=> '". $unique{$_} ."',\n";
}
print NFe $utxt, q|);
my @iftype = qw(
IPV6_ADDR_ANY
IPV6_ADDR_UNICAST
IPV6_ADDR_MULTICAST
IPV6_ADDR_ANYCAST
IPV6_ADDR_LOOPBACK
IPV6_ADDR_LINKLOCAL
IPV6_ADDR_SITELOCAL
IPV6_ADDR_COMPATv4
IPV6_ADDR_SCOPE_MASK
IPV6_ADDR_MAPPED
IPV6_ADDR_RESERVED
IPV6_ADDR_ULUA
IPV6_ADDR_6TO4
IPV6_ADDR_6BONE
IPV6_ADDR_AGU
IPV6_ADDR_UNSPECIFIED
IPV6_ADDR_SOLICITED_NODE
IPV6_ADDR_ISATAP
IPV6_ADDR_PRODUCTIVE
IPV6_ADDR_6TO4_MICROSOFT
IPV6_ADDR_TEREDO
IPV6_ADDR_ORCHID
IPV6_ADDR_NON_ROUTE_DOC
);
my @scope = qw(
RFC2373_GLOBAL
RFC2373_ORGLOCAL
RFC2373_SITELOCAL
RFC2373_LINKLOCAL
RFC2373_NODELOCAL
LINUX_COMPATv4
);
@EXPORT_OK = (@afs,@pfs,@ifs,@iftype,@scope);
%EXPORT_TAGS = (
all => [@afs,@pfs,@ifs,@iftype,@scope],
afs => [@afs],
pfs => [@pfs],
ifs => [@ifs],
iffs => [@iffs],
iffIN6 => [@iffIN6],
iftype => [@iftype],
scope => [@scope],
);
sub NI_ENDVAL {return |. $endv .q|};
sub NI_UNIQUE {return \%unique};
sub DESTROY {};
1;
__END__
=head1 NAME
Net::Interface::NetSymbols - AF_ PF_ IFxxx type symbols
=head1 SYNOPSIS
This module is built for this specific architecture during the F<make>
process using F<inst/netsymbols.pl>. Do not edit this module, edit
F<inst/netsymbols.pl> instead.
This module contains symbols arrays only for use by Net::Interface, in all other
respects it is NOT functional. It contains documentation and data arrays
for this specific architecture.
B<NOTE:> WARNING !!
usage is Net::Interface
B<NOT> Net::Interface::NetSymbols
use Net::Interface qw(
Net::Interface::NetSymbols::NI_ENDVAL();
Net::Interface::NetSymbols::NI_UNIQUE();
|;
print NFe qq|@afs
@pfs
@ifs
@iffs
|;
if (@iffIN6) {
print NFe qq|
@iffIN6 populated for BSD flavored systems
:all :afs :pfs :ifs :iffs :iffIN6 :iftype :scope
);
|;
} else {
print NFe qq|
:all :afs :pfs :ifs :iffs :iftype :scope
);
|;
}
print NFe q|
=head1 DESCRIPTION
All of the AF_XXX and PF_XXX symbols available in local C<sys/socket.h> plus
usual aliases for AF_LOCAL i.e. (AF_FILE AF_UNIX PF_LOCAL PF_FILE PF_UNIX)
All of the IFxxxx and IN6_IF symbols in C<net/if.h, netinet/in.h, netinet/in_var.h> and
their includes.
Symbols may be accessed for their numeric value or their string name.
i.e. if ($family == AF_INET)
do something...
or print AF_INET
will product the string "inet"
The same holds true for:
printf("family is %s",AF_INET);
or sprint("family is %s",AF_INET);
To print the numeric value of the SYMBOL do:
print (0 + SYMBOL), "\n";
|;
if (exists $fam{AF_INET6}) {
print NFe q|On systems supporting IPV6, these additional symbols are available which
may be applied to the address I<type> to determine the address attributes.
IPV6_ADDR_ANY unknown
IPV6_ADDR_UNICAST unicast
IPV6_ADDR_MULTICAST multicast
IPV6_ADDR_ANYCAST anycast
IPV6_ADDR_LOOPBACK loopback
IPV6_ADDR_LINKLOCAL link-local
IPV6_ADDR_SITELOCAL site-local
IPV6_ADDR_COMPATv4 compat-v4
IPV6_ADDR_SCOPE_MASK scope-mask
IPV6_ADDR_MAPPED mapped
IPV6_ADDR_RESERVED reserved
IPV6_ADDR_ULUA uniq-lcl-unicast
IPV6_ADDR_6TO4 6to4
IPV6_ADDR_6BONE 6bone
IPV6_ADDR_AGU global-unicast
IPV6_ADDR_UNSPECIFIED unspecified
IPV6_ADDR_SOLICITED_NODE solicited-node
IPV6_ADDR_ISATAP ISATAP
IPV6_ADDR_PRODUCTIVE productive
IPV6_ADDR_6TO4_MICROSOFT 6to4-ms
IPV6_ADDR_TEREDO teredo
IPV6_ADDR_ORCHID orchid
IPV6_ADDR_NON_ROUTE_DOC non-routeable-doc
if ($type & IPV6_ADDR_xxxx) {
print IPV6_ADDR_xxxx,"\n";
}
These symbols may be equated to the I<scope> of the address.
RFC2373_GLOBAL global-scope
RFC2373_ORGLOCAL org-local
RFC2373_SITELOCAL site-local
RFC2373_LINKLOCAL link-local
RFC2373_NODELOCAL loopback
LINUX_COMPATv4 lx-compat-v4
if ($scope eq RFC2373_xxxx) {
print RFC2373_xxxx,"\n";
}
|;
}
print NFe q|
=over 4
=item * :all Import all symbols
=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|
=back
=head1 AUTHOR Michael Robinton <michael@bizsystems.com>
=head1 COPYRIGHT 2008-2009
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;
|