Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.1 KiB

  1. package Net::protoent;
  2. use strict;
  3. use 5.005_64;
  4. our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
  5. BEGIN {
  6. use Exporter ();
  7. @EXPORT = qw(getprotobyname getprotobynumber getprotoent);
  8. @EXPORT_OK = qw( $p_name @p_aliases $p_proto getproto );
  9. %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
  10. }
  11. use vars @EXPORT_OK;
  12. # Class::Struct forbids use of @ISA
  13. sub import { goto &Exporter::import }
  14. use Class::Struct qw(struct);
  15. struct 'Net::protoent' => [
  16. name => '$',
  17. aliases => '@',
  18. proto => '$',
  19. ];
  20. sub populate (@) {
  21. return unless @_;
  22. my $pob = new();
  23. $p_name = $pob->[0] = $_[0];
  24. @p_aliases = @{ $pob->[1] } = split ' ', $_[1];
  25. $p_proto = $pob->[2] = $_[2];
  26. return $pob;
  27. }
  28. sub getprotoent ( ) { populate(CORE::getprotoent()) }
  29. sub getprotobyname ($) { populate(CORE::getprotobyname(shift)) }
  30. sub getprotobynumber ($) { populate(CORE::getprotobynumber(shift)) }
  31. sub getproto ($;$) {
  32. no strict 'refs';
  33. return &{'getprotoby' . ($_[0]=~/^\d+$/ ? 'number' : 'name')}(@_);
  34. }
  35. 1;
  36. __END__
  37. =head1 NAME
  38. Net::protoent - by-name interface to Perl's built-in getproto*() functions
  39. =head1 SYNOPSIS
  40. use Net::protoent;
  41. $p = getprotobyname(shift || 'tcp') || die "no proto";
  42. printf "proto for %s is %d, aliases are %s\n",
  43. $p->name, $p->proto, "@{$p->aliases}";
  44. use Net::protoent qw(:FIELDS);
  45. getprotobyname(shift || 'tcp') || die "no proto";
  46. print "proto for $p_name is $p_proto, aliases are @p_aliases\n";
  47. =head1 DESCRIPTION
  48. This module's default exports override the core getprotoent(),
  49. getprotobyname(), and getnetbyport() functions, replacing them with
  50. versions that return "Net::protoent" objects. They take default
  51. second arguments of "tcp". This object has methods that return the
  52. similarly named structure field name from the C's protoent structure
  53. from F<netdb.h>; namely name, aliases, and proto. The aliases method
  54. returns an array reference, the rest scalars.
  55. You may also import all the structure fields directly into your namespace
  56. as regular variables using the :FIELDS import tag. (Note that this still
  57. overrides your core functions.) Access these fields as variables named
  58. with a preceding C<p_>. Thus, C<$proto_obj-E<gt>name()> corresponds to
  59. $p_name if you import the fields. Array references are available as
  60. regular array variables, so for example C<@{ $proto_obj-E<gt>aliases()
  61. }> would be simply @p_aliases.
  62. The getproto() function is a simple front-end that forwards a numeric
  63. argument to getprotobyport(), and the rest to getprotobyname().
  64. This function is not exported by default.
  65. To access this functionality without the core overrides,
  66. pass the C<use> an empty import list, and then access
  67. function functions with their full qualified names.
  68. On the other hand, the built-ins are still available
  69. via the C<CORE::> pseudo-package.
  70. =head1 NOTE
  71. While this class is currently implemented using the Class::Struct
  72. module to build a struct-like class, you shouldn't rely upon this.
  73. =head1 AUTHOR
  74. Tom Christiansen