home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-User.iso / usr / lib / perl5 / Socket.pm < prev    next >
Text File  |  1997-03-29  |  2KB  |  150 lines

  1. package Socket;
  2.  
  3. =head1 NAME
  4.  
  5. Socket - load the C socket.h defines
  6.  
  7. =head1 SYNOPSIS
  8.  
  9.     use Socket;
  10.  
  11.     $proto = (getprotobyname('udp'))[2];         
  12.     socket(Socket_Handle, PF_INET, SOCK_DGRAM, $proto); 
  13.  
  14. =head1 DESCRIPTION
  15.  
  16. This module is just a translation of the C F<socket.h> file.
  17. Unlike the old mechanism of requiring a translated F<socket.ph>
  18. file, this uses the B<h2xs> program (see the Perl source distribution)
  19. and your native C compiler.  This means that it has a 
  20. far more likely chance of getting the numbers right.
  21.  
  22. =head1 NOTE
  23.  
  24. Only C<#define> symbols get translated; you must still correctly
  25. pack up your own arguments to pass to bind(), etc.
  26.  
  27. =cut
  28.  
  29. use Carp;
  30.  
  31. require Exporter;
  32. use AutoLoader;
  33. require DynaLoader;
  34. @ISA = qw(Exporter DynaLoader);
  35. @EXPORT = qw(
  36.     AF_802
  37.     AF_APPLETALK
  38.     AF_CCITT
  39.     AF_CHAOS
  40.     AF_DATAKIT
  41.     AF_DECnet
  42.     AF_DLI
  43.     AF_ECMA
  44.     AF_GOSIP
  45.     AF_HYLINK
  46.     AF_IMPLINK
  47.     AF_INET
  48.     AF_LAT
  49.     AF_MAX
  50.     AF_NBS
  51.     AF_NIT
  52.     AF_NS
  53.     AF_OSI
  54.     AF_OSINET
  55.     AF_PUP
  56.     AF_SNA
  57.     AF_UNIX
  58.     AF_UNSPEC
  59.     AF_X25
  60.     MSG_DONTROUTE
  61.     MSG_MAXIOVLEN
  62.     MSG_OOB
  63.     MSG_PEEK
  64.     PF_802
  65.     PF_APPLETALK
  66.     PF_CCITT
  67.     PF_CHAOS
  68.     PF_DATAKIT
  69.     PF_DECnet
  70.     PF_DLI
  71.     PF_ECMA
  72.     PF_GOSIP
  73.     PF_HYLINK
  74.     PF_IMPLINK
  75.     PF_INET
  76.     PF_LAT
  77.     PF_MAX
  78.     PF_NBS
  79.     PF_NIT
  80.     PF_NS
  81.     PF_OSI
  82.     PF_OSINET
  83.     PF_PUP
  84.     PF_SNA
  85.     PF_UNIX
  86.     PF_UNSPEC
  87.     PF_X25
  88.     SOCK_DGRAM
  89.     SOCK_RAW
  90.     SOCK_RDM
  91.     SOCK_SEQPACKET
  92.     SOCK_STREAM
  93.     SOL_SOCKET
  94.     SOMAXCONN
  95.     SO_ACCEPTCONN
  96.     SO_BROADCAST
  97.     SO_DEBUG
  98.     SO_DONTLINGER
  99.     SO_DONTROUTE
  100.     SO_ERROR
  101.     SO_KEEPALIVE
  102.     SO_LINGER
  103.     SO_OOBINLINE
  104.     SO_RCVBUF
  105.     SO_RCVLOWAT
  106.     SO_RCVTIMEO
  107.     SO_REUSEADDR
  108.     SO_SNDBUF
  109.     SO_SNDLOWAT
  110.     SO_SNDTIMEO
  111.     SO_TYPE
  112.     SO_USELOOPBACK
  113. );
  114.  
  115. sub AUTOLOAD {
  116.     local($constname);
  117.     ($constname = $AUTOLOAD) =~ s/.*:://;
  118.     $val = constant($constname, @_ ? $_[0] : 0);
  119.     if ($! != 0) {
  120.     if ($! =~ /Invalid/) {
  121.         $AutoLoader::AUTOLOAD = $AUTOLOAD;
  122.         goto &AutoLoader::AUTOLOAD;
  123.     }
  124.     else {
  125.         ($pack,$file,$line) = caller;
  126.         croak "Your vendor has not defined Socket macro $constname, used";
  127.     }
  128.     }
  129.     eval "sub $AUTOLOAD { $val }";
  130.     goto &$AUTOLOAD;
  131. }
  132.  
  133.  
  134. # pack a sockaddr_in structure for use in bind() calls.
  135. # (here to hide the 'S n C4 x8' magic from applications)
  136. sub sockaddr_in{
  137.     my($af, $port, @quad) = @_;
  138.     my $pack = 'S n C4 x8'; # lookup $pack from hash using $af?
  139.     pack($pack, $af, $port, @quad);
  140. }
  141.  
  142.  
  143. bootstrap Socket;
  144.  
  145. # Preloaded methods go here.  Autoload methods go after __END__, and are
  146. # processed by the autosplit program.
  147.  
  148. 1;
  149. __END__
  150.